⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 daynightlayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        interString = i18n.get(DayNightLayer.class,                TermFadeProperty,                I18n.TOOLTIP,                "Percentage of the distance from the horizon to the brightest point to start fading to darkness, 0.0 to 0.5.");        props.put(TermFadeProperty, interString);        interString = i18n.get(DayNightLayer.class,                TermFadeProperty,                TermFadeProperty);        props.put(TermFadeProperty + LabelEditorProperty, interString);        interString = i18n.get(DayNightLayer.class,                DaytimeColorProperty,                I18n.TOOLTIP,                "Color for the daytime area, if polygon terminator isn't used.");        props.put(DaytimeColorProperty, interString);        interString = i18n.get(DayNightLayer.class,                DaytimeColorProperty,                DaytimeColorProperty);        props.put(DaytimeColorProperty + LabelEditorProperty, interString);        props.put(DaytimeColorProperty + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.ColorPropertyEditor");        interString = i18n.get(DayNightLayer.class,                NighttimeColorProperty,                I18n.TOOLTIP,                "Color for the nighttime area.");        props.put(NighttimeColorProperty, interString);        interString = i18n.get(DayNightLayer.class,                NighttimeColorProperty,                NighttimeColorProperty);        props.put(NighttimeColorProperty + LabelEditorProperty, interString);        props.put(NighttimeColorProperty + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.ColorPropertyEditor");        interString = i18n.get(DayNightLayer.class,                DoPolyTerminatorProperty,                I18n.TOOLTIP,                "Render with polygon instead of image (it's faster).");        props.put(DoPolyTerminatorProperty, interString);        interString = i18n.get(DayNightLayer.class,                DoPolyTerminatorProperty,                DoPolyTerminatorProperty);        props.put(DoPolyTerminatorProperty + LabelEditorProperty, interString);        props.put(DoPolyTerminatorProperty + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor");        interString = i18n.get(DayNightLayer.class,                TerminatorVertsProperty,                I18n.TOOLTIP,                "Number of vertices of the polygon terminator (more is smoother).");        props.put(TerminatorVertsProperty, interString);        interString = i18n.get(DayNightLayer.class,                TerminatorVertsProperty,                TerminatorVertsProperty);        props.put(TerminatorVertsProperty + LabelEditorProperty, interString);        props.put(initPropertiesProperty, CurrentTimeProperty + " "                + OverlayTimeProperty + " " + UpdateIntervalProperty + " "                + NighttimeColorProperty + " " + DoPolyTerminatorProperty + " "                + TerminatorVertsProperty + " " + DaytimeColorProperty + " "                + TermFadeProperty + " " + RemovableProperty + " "                + AddAsBackgroundProperty);        return props;    }    /**     * Handle an ActionEvent from the Timer.     *      * @param ae action event from the timer.     */    public void actionPerformed(java.awt.event.ActionEvent ae) {        super.actionPerformed(ae);        if (Debug.debugging("daynight")) {            Debug.output(getName() + "| updating image via timer...");        }        doPrepare();    }    /**     * Create the OMGraphic that acts as an overlay showing the     * day/night terminator. The brightest spot on the earth is     * calculated, and then each pixel is inverse projected to find     * out its coordinates. Then the great circle distance is     * calculated. The terminator is assumed to be the great circle     * where all the points are PI/2 away from the bright point. If     * the termFade variable is set, then the difference in color over     * the terminator is feathered, on equal amount of the terminator.     *      * @param projection the projection of the screen,     * @return OMGraphic containing image to use for the layer. The     *         image has been projected.     */    protected OMGraphic createImage(Projection projection) {        if (currentTime)            overlayTime = System.currentTimeMillis();        if (Debug.debugging("daynight")) {            Debug.output("DayNightLayer: Calculating sun position at time "                    + Long.toString(overlayTime));        }        LatLonPoint brightPoint = SunPosition.sunPosition(overlayTime);        Debug.message("daynight", "DayNightLayer: Calculated sun position");        // Do a fast and relatively inexpensive calculation of the        // terminator. NOTE: for non-cylindrical projections we don't        // create a full-hemisphere circle so that we don't get        // flip-rendering problem...        if (doPolyTerminator) {            Debug.message("daynight",                    "DayNightLayer:  Creating polygon terminator");            LatLonPoint darkPoint = GreatCircle.spherical_between(brightPoint.radlat_,                    brightPoint.radlon_,                    (float) Math.PI,                    (float) Math.PI / 4f);            OMCircle circle = new OMCircle(darkPoint, (projection instanceof Cylindrical) ? 90f                    : 89.0f,//HACK                    Length.DECIMAL_DEGREE, terminatorVerts);            circle.setPolarCorrection(true);            circle.setFillPaint(nighttimeColor);            circle.setLinePaint(nighttimeColor);            circle.generate(projection);            Debug.message("daynight",                    "DayNightLayer: Done creating polygon terminator");            return circle;        }        int width = projection.getWidth();        int height = projection.getHeight();        int[] pixels = new int[width * height];        OMRaster ret = new OMRaster((int) 0, (int) 0, width, height, pixels);        Debug.message("daynight", getName()                + "|createImage: Center of bright spot lat= "                + brightPoint.getLatitude() + ", lon= "                + brightPoint.getLongitude());        // Light is clear and/or white        int light = daytimeColor.getRGB();        // Allocate the memory here for the testPoint        LatLonPoint testPoint = new LatLonPoint(0f, 0f);        // great circle distance between the bright point and each        // pixel.        float distance;        //  Set the darkeness value        int dark = nighttimeColor.getRGB();// ARGB        int darkness = dark >>> 24;// darkness alpha        int value;        // Calculate the fae limits around the terminator        float upperFadeLimit = (float) (MoreMath.HALF_PI * (1.0 + termFade));        float lowerFadeLimit = (float) (MoreMath.HALF_PI * (1.0 - termFade));        int fadeColorValue = 0x00FFFFFF & (dark); // RGB        for (int i = 0; i < width; i++) {            for (int j = 0; j < height; j++) {                testPoint = projection.inverse(i, j, testPoint);                distance = GreatCircle.spherical_distance(brightPoint.radlat_,                        brightPoint.radlon_,                        testPoint.radlat_,                        testPoint.radlon_);                if (distance > upperFadeLimit) {                    pixels[j * width + i] = dark;                } else if (distance > lowerFadeLimit) {                    value = (int) (darkness * (1 - ((upperFadeLimit - distance) / (upperFadeLimit - lowerFadeLimit))));                    value <<= 24;                    pixels[j * width + i] = fadeColorValue | value;                } else {                    pixels[j * width + i] = light;                }            }        }        ret.generate(projection);        return ret;    }    /**     * Prepares the graphics for the layer. This is where the     * getRectangle() method call is made on the location.     * <p>     * Occasionally it is necessary to abort a prepare call. When this     * happens, the map will set the cancel bit in the LayerThread,     * (the thread that is running the prepare). If this Layer needs     * to do any cleanups during the abort, it should do so, but     * return out of the prepare asap.     *       */    public synchronized OMGraphicList prepare() {        OMGraphicList list = getList();        if (list == null) {            list = new OMGraphicList();        } else {            list.clear();        }        if (isCancelled()) {            Debug.message("daynight", getName()                    + "|DayNightLayer.prepare(): aborted.");            return null;        }        Debug.message("basic", getName() + "|DayNightLayer.prepare(): doing it");        OMGraphic ras = createImage(getProjection());        if (timer != null)            timer.restart();        list.add(ras);        return list;    }    /**     * Get the time of the overlay.     */    public long getOverlayTime() {        return overlayTime;    }    /**     * Set the time for the overlay.     */    public void setOverlayTime(long ot) {        overlayTime = ot;        currentTime = false;        doPrepare();    }    /**     * Returns whether the layer will set the overlayTime to the time     * the image is created.     */    public boolean getCurrentTime() {        return currentTime;    }    /**     * Set whether the layer should set the overlayTime to the time     * the image is created. If the time is being set to reflect a     * time other than the current time, this needs to be set to     * false. It actually is, if you manually set the overlay time.     */    public void setCurrentTime(boolean ct) {        currentTime = ct;    }    /**     * Get the timer being used for automatic updates. May be null if     * a timer is not set.     */    public Timer getTimer() {        return timer;    }    /**     * If you want the layer to update itself at certain intervals,     * you can set the timer to do that. Set it to null to disable it.     */    public void setTimer(Timer t) {        timer = t;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -