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

📄 webmapimageexporter.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }

            if ((resource != null) && !m_resources.isEmpty() && !m_resources.contains(resource)) {
            	continue;
            }

            if (!(func instanceof ExportFunctionality)) {
                continue;
            }

            ExportFunctionality exportFunc = (ExportFunctionality) func;
            try {
                
            	if(!currentExtent.getSpatialReference().equals(func.getResource().getDefaultSpatialReference())) {
                    setRef = true;
                    selectedMapFunc = func;
                
            	} else {
                    imageIn = exportFunc.export(props);

                    if(imageIn == null) {
                        continue;
                    }

                    images.add(imageIn);
                    transValues.add(func.getTransparency());
                }
            
            } catch (ADFException e) {
                LOG.warn("Unable to export Map for Resource [ID: " + resourceId + ", Alias: " + resource.getAlias() + "]", e);
                imageIn = null;
            }
        }

        // need to set the spatial reference to that of the selected 
        // mapfunctionality, then set it back after the image is exported.
        if (setRef) {
            
        	ExportFunctionality exportFunc = (ExportFunctionality) selectedMapFunc;
            // set the spatial reference before creating the image
            m_map.getWebContext().setSpatialReference(selectedMapFunc.getResource().getDefaultSpatialReference());
            imageIn = exportFunc.export(props);

            if (imageIn != null) {
                images.add(imageIn);
                transValues.add(selectedMapFunc.getTransparency());
            }

            // reset the spatial reference
            m_map.getWebContext().setSpatialReference(currentExtent.getSpatialReference());
            m_map.getWebContext().getWebMap().setCurrentExtent(currentExtent); 
            m_map.getWebContext().refresh();
        }

        images.add(new ByteArrayInputStream(ImageUtil.createBlankImage(props.getWidth(), props.getHeight(), 1.0D, props.getImageFormat())));
        transValues.add(1.0D);
    }

    /**
     * Merge a list of images into a single image.
     *
     * @param props                Contains export properties.  ImageFormat is used from Export Properties
     * @param images        List of <code>InputStream</code> objects.  These will be read
     *                                         to get the image.
     * @param trans                Transparency values for each image.
     * @return Merged image as a byte array.  The image will be in the format specified
     *                         in the Export Properties.
     */
    protected byte[] mergeImages(ExportProperties props, List<InputStream> images, List<Double> trans) {
        InputStream[] imagesArr = new InputStream[images.size()];
        imagesArr = images.toArray(imagesArr);

        double[] transArr = new double[trans.size()];
        int i = 0;

        for (Double value : trans) {
            transArr[i] = value;
            i++;
        }

        return ImageUtil.mergeImages(imagesArr, props.getImageFormat(), transArr);
    }

    /**
     * Can be implemented by subclasses in order to export other items with the map.
     * This method will be called after the map images have been exported and before
     * all the images are merged.
     *
     * @param props                Contains export properties.
     * @param images        Contains {@link InputStream} objects for each image of the map.
     * @param transValues  Contains transparency values for each image of the map.
     */
    protected void exportOther(ExportProperties props, List<InputStream> images, List<Double> transValues) {
        return;
    }

    /**
     * Sets the {@link WebMap} object that will be used to export
     * a Map Image.  The {@link WebMap} argument cannot be <code>null</code>.
     *
     * @param map        {@link WebMap} used to export Map Image, cannot be
     *                                 <code>null</code>.
     * @throws NullPointerException                Thrown if the <code>map</code>
     *                                                                         object is <code>null</code>.
     */
    public void setWebMap(WebMap map) {
        
    	if (map == null) {
            throw new NullPointerException(ERROR_NULL_WEB_MAP);
        }

        m_map = map;
    }

    /**
     * Sets the list of GIS Resource IDs that should be exported.  If specified,
     * only GIS Resource objects with the specified IDs will be exported.  If
     * not specified, all GIS Resources will be exported.
     *
     * @param resourceIDList                List of GIS Resource IDs that should be exported.
     */
    public void setResourceIDFilter(List<String> resourceIDList) {
        m_resourceIdList.clear();

        if (resourceIDList != null) {
            m_resourceIdList.addAll(resourceIDList);
            m_resources.clear();
        }
    }

    /**
     * Sets the list of GIS Resource objects that should be exported.  If specified
     * only these GIS Resources will be exported.  If not specified, all GIS Resources
     * will be exported.
     *
     * @param resources                List of GIS Resource objects to be exported.
     */
    public void setGISResourceFilter(List<GISResource> resources) {
        m_resources.clear();

        if(resources != null) {
            m_resources.addAll(resources);
            m_resourceIdList.clear();
        }
    }

    /**
     * Sets the Image Format that will be used to encode the image
     * during export.  The argument can be a String value in order
     * to allow configuration through a bean management framework.
     *
     * @param format        Format of image as a string (jpg, png, etc.),
     *                                         cannot be <code>null</code>.
     */
    public void setImageFormatAsString(String format) {
        
    	if(format == null) {
            throw new NullPointerException(ERROR_NULL_IMAGE_FORMAT);
        }

        setImageFormat(Format.valueOf(format.toUpperCase()));
    }

    /**
     * Sets the desired Dots Per Inch of the exported map image.  The
     * dpi must be greater than 0.
     *
     * @param dpi        Desired dots per inch of the exported map image, must be
     *                                 greater than 0.
     * @throws IllegalArgumentException                Thrown if the dpi is
     *                                                                                 not greater than 0.
     */
    public void setDpi(int dpi) {
        
    	if(dpi <= 0) {
            throw new IllegalArgumentException(ERROR_INVALID_DPI);
        }

        m_dpi = dpi;
    }

    /**
     * Sets the desired extent of the Map Image in Map coordinates.
     * The exported image will be at the specified extent.  If the
     * extent is <code>null</code> then the Current Extent of the Map
     * will be used.
     *
     * @param extent        Desired Extent to export.
     */
    public void setExtent(WebExtent extent) {
        if (extent == null) {
            LOG.info(INFO_NULL_EXTENT);
        }

        m_extent = extent;
    }

    /**
     * Sets a flag to indicate if Graphic Resources should be exported within the
     * image.  If this flag is set to true, but if a GraphicsResource is not included
     * in the GIS Resource Filter or Resource ID filter then the Graphics Resource will
     * not be drawn.  If this flag is false, and the Graphics Resource is included in the
     * GIS Resource Filter or Resource ID filter, then the Graphics Resource will not be
     * drawn.
     *
     * @param flag                Indicates if Graphics Resources should be exported.
     */
    public void setExportGraphicsResources(boolean flag) {
        m_exportGraphicResources = flag;
    }

    /**
     * Helper method to retrieve the full extent of the Map for the specified
     * GIS Resource.
     *
     * @param res                GIS Resource with Map Functionality.
     * @return Full Extent of Map for GIS Resource or <code>null</code> if GIS
     *                         Resource is <code>null</code> or Map Functionality for GIS Resource
     *                         cannot be found.
     */
    private WebExtent getMapFullExtent(GISResource res) {
    	GISFunctionality func = (res != null) ? res.getFunctionality(MapFunctionality.FUNCTIONALITY_NAME) : null;	
    	return (func != null) ? ((MapFunctionality) func).getFullExtent() : null;
    }
}

⌨️ 快捷键说明

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