📄 weboverview.java
字号:
package com.esri.solutions.jitk.web.data;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.esri.adf.web.data.OverviewFunctionality;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.util.ImageUtil;
import com.esri.adf.web.util.WebUtil;
/**
* Extension of the {@link com.esri.adf.web.data.WebOverview} class.
* This provides some new features of the Overview Map. In the base
* implementation, the background map would never zoom, but instead remained
* static at the full extent. As the user panned or zoomed on the main map,
* the rectangle would be updated.
*
* <p>
* This Overview Map will not remain static. It will zoom if necessary. If the
* ratio between the map's extent and the overview map's extent is not within
* a configurable range, then the overview map will be redrawn accordingly. If the
* user pans to an area outside of the current extent of the overview map, then
* the overview map will be redrawn.
* </p>
*
* <p>
* The MinExtentRatio property is the minimum ratio between the Map Extent and the Overview
* Map extent that is allowed before the Overview Map needs to be redrawn. Example, if the
* MinExtentRatio property has a value of 2.0, then once the width of the Overview Map divided by
* the width of the Map is less than 2.0, then the Overview Map will be redrawn. This prevents the
* highlighted region from becoming too big on the Overview Map. The MinExtentRatio cannot be equal to
* or less than 0.0.
* </p>
*
* <p>
* The MaxExtentRatio property is the maximum ratio between the Map Extent and the Overview Map
* extent that is allowed before the Overview Map needs to be redrawn. Example, if the
* MaxExtentRatio property has a value of 8.0, then once the width of the Overview Map divided by
* the width of the Map is greater than 8.0, then the Overview Map will be redrawn. This prevents
* the highlighted region from becoming too small on the Overview Map. The MaxExtentRatio cannot be
* equal to or less then 0.0.
* </p>
*/
public class WebOverview extends com.esri.adf.web.data.WebOverview {
/**
* Unique Version ID of this class. Used for serialization purposes.
*/
private static final long serialVersionUID = -3815139545421274948L;
/**
* Logger to use to log messages from this class.
*/
private static final Logger LOG = LogManager.getLogger(WebOverview.class);
/**
* Minimum ratio between the Map Extent and the Overview Map Extent. If the
* ratio is less than this value then the Overview Map is redrawn.
*/
private double minExtentRatio;
/**
* Maximum ratio between the Map Extent and the Overview Map Extent. If the
* ratio is greater than this value then the Overview Map is redrawn.
*/
private double maxExtentRatio;
/**
* Keeps track of the enabled/disabled state of the Overview Functionalities
* before any changes are made.
*/
private final Map<OverviewFunctionality, Boolean> m_ovFuncState;
/**
* Default value for the Minimum Extent Ratio property.
*
* @see #setMinExtentRatio(double)
*/
public static final double DEFAULT_MINIMUM_EXTENT_RATIO = 2.0D;
/**
* Default value for the Maximum Extent Ratio property.
*
* @see #setMaxExtentRatio(double)
*/
public static final double DEFAULT_MAXIMUM_EXTENT_RATIO = 8.0D;
/**
* Default value for the Image Format property
*
* @see #setImageFormat(String)
*/
public static final String DEFAULT_IMAGE_FORMAT = "png";
/**
* Constructs a new WebOverview object. The MinimumExtentRatio property
* is set to {@link #DEFAULT_MINIMUM_EXTENT_RATIO} and the MaximumExtentRatio
* property is set to {@link #DEFAULT_MAXIMUM_EXTENT_RATIO}.
*
*/
public WebOverview (){
LOG.info("Constructing a new " + this.getClass().getName() + " object.");
setMinExtentRatio(DEFAULT_MINIMUM_EXTENT_RATIO);
setMaxExtentRatio(DEFAULT_MAXIMUM_EXTENT_RATIO);
setImageFormat(DEFAULT_IMAGE_FORMAT);
setShowFullExtent(false);
m_ovFuncState = new HashMap<OverviewFunctionality, Boolean>();
}
/**
* Sets the ShowFullExtent property to the desired value. The method argument
* must be <code>false</code> in order for this Overview Map to function properly.
*
* @param showFullExtent Must be <code>false</code>.
*
* @throws IllegalArgumentException Thrown if the <code>showFullExtent</code> argument
* is <code>false</code>.
*/
public void setShowFullExtent (boolean showFullExtent) {
LOG.debug("Attempting to set ShowFullExtent to " + showFullExtent);
if (showFullExtent) {
throw new IllegalArgumentException ("ShowFullExtent property must be false for this Overview Map to work as desired");
}
super.setShowFullExtent(showFullExtent);
LOG.debug("Successfully set ShowFullExtent to " + showFullExtent);
}
/**
* Sets the ImageFormat property on this Overview Map. The ImageFormat property specifies what
* type of image encoding that the Overview Map image should be drawn, such as JPG, PNG, etc.
*
* @param format Encoding to use when exporting the image, cannot be
* <code>null</code>.
*
* @throws NullPointerException Thrown if the <code>format</code> argument is
* <code>null</code>.
*/
public void setImageFormat (String format) {
LOG.debug("Attempting to set ImageFormat to " + format);
if (format == null) {
throw new NullPointerException ();
}
super.setImageFormat(format);
LOG.debug("Successfully set ImageFormat to " + format);
}
/**
* Override of the {@link com.esri.adf.web.data.WebOverview#update(WebContext, Object)}
* method. This method will determine if the Overview Map image needs to be redrawn
* and exported and will calculate the new extent of the Overview Map.
*
* @param context Reference to the {@link WebContext}. This method does not
* use this argument.
* @param arg Argument passed to the {@link WebContext#refresh(Object)} method
* when invoked. This method ignores this argument.
*/
public void update(WebContext context, Object arg) {
LOG.info("Updating Overview Map");
if (shouldRedrawOvMap() || imageBytes == null) {
LOG.info("Overview Map needs to be redrawn");
calculateNewDrawExtent();
imageBytes = null;
}
reloadImageRectangle();
updateOvFuncState();
}
/**
* Override of the {@link com.esri.adf.web.data.WebOverview#init(WebContext)} method.
* This method will be invoked by the ADF framework.
* This method will call the super class's init method. Then it will calculate a new
* extent for the Overview Map based on the referenced {@link WebMap} object.
*
* @param context Reference to the {@link WebContext}.
*/
public void init(WebContext context) {
LOG.info("Initializing Overview Map");
super.init(context);
calculateNewDrawExtent();
reloadImageRectangle();
updateOvFuncState();
}
/**
* Returns value of the MinExtentRatio property. If the {@link #setMinExtentRatio(double)} method
* has not been invoked, then this method will return {@link #DEFAULT_MINIMUM_EXTENT_RATIO}.
* See the class documentation for more information on the MinExtentRatio property.
*
* @return Value of MinExtentRatio property.
*/
public double getMinExtentRatio() {
return minExtentRatio;
}
/**
* Sets the value of the MinExtentRatio property. See the class documentation for more information
* on the MinExtentRatio property.
*
* @param minExtentRatio Value of the MinExtentRatio property, must be greater than 0.0.
*
* @throws IllegalArgumentException Thrown if the <code>minExtentRatio</code> argument is less than
* or equal to 0.0.
*/
public void setMinExtentRatio(final double minExtentRatio) {
LOG.debug("Attempting to set MinExtentRatio to " + minExtentRatio);
if (minExtentRatio <= 0.0) {
throw new IllegalArgumentException("MinExtentRatio cannot be less than 0.0");
}
this.minExtentRatio = minExtentRatio;
LOG.debug("Successfully set MinExtentRatio to " + minExtentRatio);
}
/**
* Returns value of the MaxExtentRatio property. If the {@link #setMaxExtentRatio(double)} method
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -