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

📄 imageserver.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * This method returns a integer representing a mask created from     * the visibility settings of the layers.     */    public int calculateVisibleLayerMask() {        int ret = 0; // Initialize all the layer bits to zero.        for (int i = layers.length - 1; i >= 0; i--) {            if (layers[i].isVisible()) {                ret = ret | (0x00000001 << i);            }        }        return ret;    }    /**     * Use the ProjectionPainter interface of the layers to create an     * image. This approach avoids some of the timing issues that the     * thread model of the MapBean and Layers that seem to pop up from     * time to time. They are Swing components, you know. They were     * designed to be part of a GUI. So, this is a serialized, safe     * way to do things.     *      * @param proj projection of map.     * @param scaledWidth scaled pixel width of final image. If you     *        don't want it scaled, use -1.     * @param scaledHeight scaled pixel height of final image. If you     *        don't want it scaled, use -1.     * @param includedLayerMask a mask signifying which of the     *        ImageServer layers to use in the image. It's assumed     *        that the called knows which layers are desired. Bit 1 of     *        the mask refers to layer[0], etc. A bit turned on means     *        the layer will be included.     * @return a byte[] representing the formatted image.     */    public byte[] createImage(Projection proj, int scaledWidth,                              int scaledHeight, int includedLayerMask) {        Debug.message("imageserver",                "ImageServer: using the new ProjectionPainter interface!  createImage with layer mask.");        if (formatter == null) {            Debug.error("ImageServer.createImage: no formatter set! Can't create image.");            return new byte[0];        }        ImageFormatter imageFormatter = formatter.makeClone();        Graphics graphics = createGraphics(imageFormatter,                proj.getWidth(),                proj.getHeight());        if (graphics == null) {            return new byte[0];        }        ((Proj) proj).drawBackground((Graphics2D) graphics, background);        if (Debug.debugging("imageserver")) {            Debug.output("ImageServer: considering " + layers.length                    + " for image...");        }        if (layers != null) {            for (int i = layers.length - 1; i >= 0; i--) {                if ((includedLayerMask & (0x00000001 << i)) != 0) {                    if (Debug.debugging("imageserver")) {                        Debug.output("ImageServer: image request adding layer graphics from : "                                + layers[i].getName());                    }                    layers[i].renderDataForProjection(proj, graphics);                } else {                    if (Debug.debugging("imageserver")) {                        Debug.output("ImageServer: skipping layer graphics from : "                                + layers[i].getName());                    }                }            }        } else {            if (Debug.debugging("imageserver")) {                Debug.output("ImageServer: no layers available");            }        }        byte[] formattedImage = getFormattedImage(imageFormatter,                scaledWidth,                scaledHeight);        graphics.dispose();        return formattedImage;    }    /**     * Create a java.awt.Graphics to use for an image. The Graphics     * will affect the image contained within the ImageFormatter.     *      * @param formatter the ImageFormatter containing the image.     * @param width the pixel width of the image.     * @param height the pixel height of the image.     */    protected Graphics createGraphics(ImageFormatter formatter, int width,                                      int height) {        java.awt.Graphics graphics = null;        if (formatter != null) {            graphics = formatter.getGraphics(width, height);        } else {            Debug.error("ImageServer.createGraphics: Formatter is null, returning null graphics.");            return null;        }        if (graphics == null) {            Debug.error("ImageServer.createGraphics: NOT able to create Graphics!");            return null;        }        if (Debug.debugging("imageserver")) {            Debug.output("ImageServer.createGraphics: graphics is cool");        }        if (doAntiAliasing && graphics instanceof java.awt.Graphics2D) {            java.awt.Graphics2D g2d = (java.awt.Graphics2D) graphics;            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                    RenderingHints.VALUE_ANTIALIAS_ON);        }        return graphics;    }    /**     * Format the image that is contained in the ImageFormatter,     * scaling to a particular size if the scaledWidth and     * scaledHeight are greater than 0.     */    protected byte[] getFormattedImage(ImageFormatter formatter,                                       int scaledWidth, int scaledHeight) {        if (Debug.debugging("imageserver")) {            Debug.output("ImageServer: ready to create formatted image.");        }        byte[] formattedImage = null;        // Now, scale the image, if needed...        if (scaledWidth > 0 && scaledHeight > 0) {            formattedImage = formatter.getScaledImageBytes(scaledWidth,                    scaledHeight);        } else {            Debug.message("imageserver",                    "ImageServer: using full scale image (unscaled).");            formattedImage = formatter.getImageBytes();        }        return formattedImage;    }    /**     * Set the layers and image type in the properties.     */    public void setProperties(Properties props) {        setProperties((String) null, props);    }    /**     * Set the layers and image type in the properties. The properties     * might have a prefix in the file.     */    public void setProperties(String prefix, Properties props) {        setProperties(prefix, props, (Hashtable) null);    }    /**     * Set the layers and image type in the properties. The properties     * might have a prefix in the file.     */    public void setProperties(String prefix, Properties props,                              Hashtable instantiatedLayers) {        setPropertyPrefix(prefix);        prefix = PropUtils.getScopedPropertyPrefix(prefix);        layers = getLayers(props, instantiatedLayers);        formatter = getFormatters(props);        doAntiAliasing = PropUtils.booleanFromProperties(props, prefix                + AntiAliasingProperty, false);    }    /**     * Part of the PropertyConsumer interface. Doesn't do anything     * yet.     */    public Properties getProperties(Properties props) {        if (props == null) {            props = new Properties();        }        return props;    }    /**     * Part of the PropertyConsumer interface.     */    public Properties getPropertyInfo(Properties list) {        if (list == null) {            list = new Properties();        }        list.put(ImageServerLayersProperty,                "A list of marker names (space-separated) for layer definitions");        list.put(ImageFormattersProperty,                "A list of marker names (space-separated) for ImageFormatter definitions");        list.put(AntiAliasingProperty,                "Whether to use anti-aliasing for the image");        return list;    }    /**     * Part of the PropertyConsumer interface. Set the Properties     * prefix to use to scope the relevant properties passed into the     * setProperties method.     */    public void setPropertyPrefix(String prefix) {        propertiesPrefix = prefix;    }    /**     * Part of the PropertyConsumer interface. Get the Properties     * prefix used to scope the relevant properties passed into the     * setProperties method.     */    public String getPropertyPrefix() {        return propertiesPrefix;    }    /**     * Given a integer that represents, bitwise, the layers that you     * want out of the current list held by the ImageServer layer     * array, return an array of those layers.     *      * @param layerMask bit mask for desired layers, bit 0 is layer 0.     * @return layer[]     */    protected synchronized Layer[] getMaskedLayers(int layerMask) {        if (layerMask == 0xFFFFFFFF || layers == null) {            // They all want to be there            Debug.message("imageserver",                    (layers != null ? "ImageServer: image request adding all layers."                            : "ImageServer.getMaskedLayers() null layers"));            return layers;        } else {            // Use the vector as a growable array, and add the layers            // to it that the mask says should be there.            Vector layerVector = new Vector(layers.length);            for (int i = 0; i < layers.length; i++) {                if ((layerMask & (0x00000001 << i)) != 0) {                    layerVector.add(layers[i]);                    if (Debug.debugging("imageserver")) {                        Debug.output("ImageServer: image request adding layer: "                                + layers[i].getName());                    }                }            }            Layer[] imageLayers = new Layer[layerVector.size()];            return (Layer[]) layerVector.toArray(imageLayers);        }    }    /**     * Get the ImageFormatter currently used for the image creation.     *      * @return ImageFormatter.     */    public synchronized ImageFormatter getFormatter() {        return formatter;    }    /**     * Set the ImageFormatter to be used for ImageCreation.     */    public synchronized void setFormatter(ImageFormatter f) {        formatter = f;    }    /**     * Set the default formatter to the one with the given label. The     * label can be retrieved from the ImageFormatter.     *      * @param formatterLabel String for a particular formatter.     * @return true if label matches up with a known formatter, false     *         if no formatter found.     */    public synchronized boolean setFormatter(String formatterLabel) {        ImageFormatter tmpFormatter = (ImageFormatter) imageFormatters.get(formatterLabel.intern());        if (tmpFormatter != null) {            setFormatter(tmpFormatter);            return true;        } else {            return false;        }    }    /**     * Get the Hashtable used to hold the ImageFormatters. The label     * for each one is the lookup for it in the Hashtable.     *      * @return Hashtable of ImageFormatters.     */    public synchronized Hashtable getFormatters() {        return imageFormatters;    }    /**     * Set the ImageFormatter Hashtable to set up the possible choices     * for image formats.     *      * @param iFormatters Hashtable of ImageFormatters     * @param defaultFormatterKey the key label of the formatter to     *        use for a default.     */    public synchronized void setFormatters(Hashtable iFormatters,                                           String defaultFormatterKey) {        imageFormatters = iFormatters;        formatter = (ImageFormatter) imageFormatters.get(defaultFormatterKey.intern());    }    /**     * Create an ImageFormatter from the contents of a properties     * object.     *      * @param p Properties used to initialize the Properties.     * @return default formatter.     */    protected ImageFormatter getFormatters(Properties p) {        String formattersString;        ImageFormatter iFormatter = null;        String prefix = PropUtils.getScopedPropertyPrefix(this);        formattersString = p.getProperty(prefix + ImageFormattersProperty);        // First, look at the formatters string to get a marker list        // of available formatters.        if (formattersString != null) {            Vector markerNames = PropUtils.parseSpacedMarkers(formattersString);

⌨️ 快捷键说明

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