📄 fixedzoomaction.java
字号:
package com.esri.solutions.jitk.commands;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebPoint;
/**
* The core fixed-zoom capability, with enforced business logic for min and max
* zoom factors. Business rule applied is:<p/>
* <code>ZOOM_FACTOR_MIN <= zoomFactor <= ZOOM_FACTOR_MAX</code>
*/
public class FixedZoomAction {
private static final Logger _logger = LogManager.getLogger(FixedZoomAction.class);
private WebContext webContext = null;
private double zoomFactor;
/**
* The minimum amount one is able to zoom in, expressed as a ratio. Its
* inverse is the minimum amount by which one may zoom out.
*/
protected static final double ZOOM_FACTOR_MAX = 0.99d;
/**
* The maximum amount one is able to zoom in, expressed as a ratio. Its
* inverse is the maximum amount by which one may zoom out.
*/
protected static final double ZOOM_FACTOR_MIN = 0.05d;
public FixedZoomAction() {
super();
}
/**
* Getter for the web context.
*
* @return the associated WebContext
* @todo who needs to be able to call this? can it be protected?
*/
public final WebContext getWebContext() {
return webContext;
}
/**
* Setter for the web context, called by the ADF during initialization.
*
* @param webContext
* presumably called by JSF
* @todo who needs to be able to call this? can it be protected?
*/
public final void setWebContext(WebContext webContext) {
_logger.debug("webContext being set");
this.webContext = webContext;
}
/**
* Computes a new scaled extent on the same center given an arbitrary
* (though validated!) scale factor
*
* @param currentExtent
* the extent reference with which all extent work is done: it
* gets modified
* @param scaleFactor
* the assumed-valid scale factor.
* @return the new extent resulting from applying the passed scalar zoom
* factor to the passed extent.
*/
protected final WebExtent getScaledExtent(WebExtent currentExtent,
double scaleFactor) {
currentExtent.expand(scaleFactor);
return currentExtent;
}
/**
* Computes a new scaled extent with the passed centerpoint given an
* arbitrary (though validated!) scale factor
*
* @param currentExtent
* the initial extent (before scaling)
* @param scaleFactor
* the assumed-valid scale factor.
* @param webExtentCenterPoint
* the new center point of the new extent
* @return the rescaled, recentered-at-webExtentCenterPoint new extent
*/
protected final WebExtent getScaledExtent(WebExtent currentExtent,
double scaleFactor, WebPoint webExtentCenterPoint) {
// compute the recentered, unscaled new extent
double deltaX = currentExtent.getWidth() / 2d;
double deltaY = currentExtent.getHeight() / 2d;
WebPoint upperLeft = new WebPoint(webExtentCenterPoint.getX() - deltaX,
webExtentCenterPoint.getY() - deltaY);
WebPoint lowerRight = new WebPoint(
webExtentCenterPoint.getX() + deltaX, webExtentCenterPoint
.getY()
+ deltaY);
// and now scale the recentered extent per the zoom factor
WebExtent newExtent = getScaledExtent(new WebExtent(upperLeft,
lowerRight), scaleFactor);
return newExtent;
}
/**
* Validates the zoom ratio such that the invariant is
* <code>ZOOM_FACTOR_MIN <= zoomFactor <= ZOOM_FACTOR_MAX</code>.
*
* @param zoomFactor
* an unvalidated scale factor
* @throws Exception
* if the passed scale factor violates the business rule.
*/
public final double validateZoomFactor(double zoomFactor) throws Exception {
if (zoomFactor > ZOOM_FACTOR_MAX) {
throw new Exception("Zoom factor is too big");
}
else if (zoomFactor < ZOOM_FACTOR_MIN) {
throw new Exception("Zoom factor is too small");
}
return zoomFactor;
}
/**
* The proportion that any zoomed-in extent will be of the prior extent. Its
* inverse corresponds to the proportion used for zooming out.
*
* @return the validated zoom factor
*/
public final double getZoomFactor() {
return zoomFactor;
}
/**
* Setter for the zoom ratio that ensures that only valid scale factors get
* set; probably called by the ADF.
*
* @param factor
* the new zoom factor
* @throws Exception
* if the scale factor value is invalid
*/
public final void setZoomFactor(double factor) throws Exception {
zoomFactor = validateZoomFactor(factor);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -