com\esri\adf\sample\resource\MyCustomOverviewFunctionality.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package com.esri.adf.sample.resource; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.Serializable; import java.util.logging.Level; import java.util.logging.Logger; import com.esri.adf.sample.resource.util.MyCustomUtil; import com.esri.adf.web.data.GISResource; import com.esri.adf.web.data.OverviewFunctionality; import com.esri.adf.web.data.WebContext; import com.esri.adf.web.data.WebElementConverter; import com.esri.adf.web.data.WebOverview; import com.esri.adf.web.data.geometry.WebExtent; import com.esri.adf.web.data.geometry.WebSpatialReference; import com.esri.adf.web.util.ImageUtil; import com.esri.adf.web.util.WebUtil; /** * <b>GraphicsOverviewFunctionality</b> provides overview capability for <b>GraphicsResource</b>. */ public class MyCustomOverviewFunctionality implements OverviewFunctionality, Serializable { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(MyCustomOverviewFunctionality.class.getName()); private MyCustomResource resource = null; private boolean disabled = false; public void initFunctionality(GISResource resource) { logger.log(Level.FINE, "GraphicsOverviewFunctionality.initFunctionality(" + resource + ")"); if (resource == null) { throw new ADFMyCustomException("Resource is null"); } if (!(resource instanceof MyCustomResource)) { throw new ADFMyCustomException("Resource is not a instance of GraphicsResource"); } this.resource = (MyCustomResource) resource; } public void destroyFunctionality() { } public InputStream exportImage() { WebContext mwContext = this.resource.getWebContext(); WebOverview mwOverview = mwContext.getWebOverview(); WebExtent overviewExtent = mwOverview.getDrawExtent(); WebSpatialReference mapsr = this.resource.getDefaultSpatialReference(); int width = mwOverview.getWidth(); int height = mwOverview.getHeight(); WebExtent currentExtent = null; if (mapsr != null && !(mwContext.getSpatialReference().equals(mapsr))) { logger.fine("Projecting the current extent"); currentExtent = mwContext.projectExtent(currentExtent); logger.fine("Projected Extent : " + currentExtent); } logger.fine("Reaspecting the current extent"); currentExtent = WebUtil.reaspect(overviewExtent, width, height); logger.fine("Reaspected Extent : " + currentExtent); mwOverview.setDrawExtent(new WebExtent(currentExtent.getMinX(), currentExtent.getMinY(), currentExtent.getMaxX(), currentExtent.getMaxY(), mwContext.getSpatialReference())); try { WebElementConverter converter = new WebElementConverter(width, height); converter.draw(MyCustomUtil.drawGrid(width, height, 50)); if (mwOverview.isLastEnabledOverviewFunctionality(this) && mwContext.getResources().size() > 1) { InputStream opaqueImage = new ByteArrayInputStream(ImageUtil.createBlankImage(width, height, 1D, "PNG")); InputStream transparentImage = new ByteArrayInputStream(converter.getPNGImage()); return new ByteArrayInputStream(ImageUtil.mergeImages(new InputStream[] { transparentImage, opaqueImage }, "PNG")); } return new ByteArrayInputStream(converter.getPNGImage()); } catch (Exception e) { throw new ADFMyCustomException("Unable to export overview image.", e); } } public MyCustomResource getResource() { return this.resource; } public boolean isDisabled() { return this.disabled; } public void setDisabled(boolean disabled) { this.disabled = disabled; } }