📄 zoomtoscaletask.java
字号:
package com.esri.solutions.jitk.web.tasks.navigation.scale;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.GeometryUtil;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.tasks.TaskInfo;
import com.esri.adf.web.faces.event.TaskEvent;
import com.esri.solutions.jitk.web.tasks.RenderControlledTask;
import org.apache.log4j.Logger;
import java.util.Map;
public class ZoomToScaleTask extends RenderControlledTask {
private static final long serialVersionUID = 652269790014907948L;
private static Logger _logger = Logger.getLogger(ZoomToScaleTask.class.getName());
private static final String SCALE_MAP_TASK = "SCALE_MAP_TASK";
private String _taskName = null;
private String _mapScaleTxt = "";
private Map<String, String> _mapScales = null;
private String _mapScaleSel = "";
private String _errMessage = "";
private String footerNote = null;
private boolean _errOccurred;
private ZoomToScaleTaskInfo _taskInfo = null;
public ZoomToScaleTask() {
super();
setTaskInfo(new ZoomToScaleTaskInfo(this));
this._taskName = SCALE_MAP_TASK;
}
public TaskInfo getTaskInfo() {
if (this._context == null) {
_taskInfo.getTaskDescriptor().setDisabled(true);
}
return this._taskInfo;
}
public void setTaskInfo(TaskInfo taskInfo) {
this._taskInfo = (ZoomToScaleTaskInfo) taskInfo;
super.setTaskInfo(this._taskInfo);
}
public String getTaskName() {
return _taskName;
}
public void setTaskName(String taskName) {
this._taskName = taskName;
}
public String getMapScaleTxt() {
return _mapScaleTxt;
}
public void setMapScaleTxt(String mapScaleTxt) {
this._mapScaleTxt = mapScaleTxt;
}
public String getMapScaleSel() {
return this._mapScaleSel;
}
public void setMapScaleSel(String mapScaleSel) {
this._mapScaleSel = mapScaleSel;
}
public void scale(TaskEvent event) {
try {
_logger.debug("Scale task invoked");
requestTaskRender();
WebContext webContext = event.getWebContext();
if (getContext() == null) {
setContext(event.getWebContext());
}
//Get WebMap
WebMap webMap = webContext.getWebMap();
//Get, expand and set map's extent
WebExtent webExtent = webMap.getCurrentExtent();
WebExtent fullExtent = webMap.getFullExtent();
double currentMapScale = webMap.getMapScale();
double mapScale;
String mapScaleTextVal = getMapScaleTxt();
if ((mapScaleTextVal == null) || (mapScaleTextVal.length() <= 0)) {
this.renderResourceMessage(ResourceProps.MSG_MISSING_SCALE);
return;
}
mapScaleTextVal = mapScaleTextVal.replace(",", "");
mapScale = Double.parseDouble(mapScaleTextVal);
_logger.info("Scaling map to 1:" + mapScaleTextVal);
double scaleFactor = mapScale / currentMapScale;
com.esri.solutions.jitk.web.data.geometry.WebExtent newExtent = new com.esri.solutions.jitk.web.data.geometry.WebExtent(webExtent);
newExtent.expand(scaleFactor);
if (GeometryUtil.inside(newExtent, fullExtent)) {
_logger.debug("Next extent " + newExtent +
" within full extent " + fullExtent + ", scaling");
//Refresh context to update all controls
webExtent.expand(scaleFactor);
webContext.refresh();
webMap.setMapScale(mapScale);
} else {
_logger.debug("Next extent " + newExtent +
" NOT within full extent " + fullExtent + ", NOT scaling");
renderResourceMessage(ResourceProps.MSG_SCALEBEYONDFULLEXTENT);
}
} catch (Exception ex) {
renderExceptionMessage(ex);
}
}
public String getErrMessage() {
return _errMessage;
}
public void setErrMessage(String errMessage) {
this._errMessage = errMessage;
}
/**
* Get footer note
*/
public String getFooterNote() {
return this.footerNote;
}
/**
* Set footer note
*/
public void setFooterNote(String footerNote) {
this.footerNote = footerNote;
}
public boolean isErrOccurred() {
return _errOccurred;
}
public void setErrOccurred(boolean errOccurred) {
this._errOccurred = errOccurred;
}
public Map<String, String> getMapScales() {
return _mapScales;
}
public void setMapScales(Map<String, String> mapScales) {
this._mapScales = mapScales;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -