📄 scalesliderrenderer.java
字号:
package com.esri.solutions.jitk.web.faces.renderkit.xml.ajax;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
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.faces.component.MapControl;
import com.esri.adf.web.faces.renderkit.xml.ajax.AJAXRenderer;
import com.esri.adf.web.util.WebUtil;
import com.esri.adf.web.util.XMLUtil;
import com.esri.solutions.jitk.web.event.IScaleSliderConfig;
public class ScaleSliderRenderer implements AJAXRenderer {
@SuppressWarnings("unchecked")
public Class getControlClass() {
return MapControl.class;
}
public Object getOriginalState(final UIComponent component) {
// We want to save the state of the control before the main serious GIS actions start!
Document xmlDoc = XMLUtil.newDocument();
renderSliderXML(XMLUtil.createElement(xmlDoc, "root", null, null), component);
return XMLUtil.transform(xmlDoc, null);
}
public void renderAjaxResponse(final FacesContext facesContext,
final UIComponent component,
final Object previousState,
final boolean b,
final Element parentElement) {
// Render the state of the control and compare if the previous state and new state are the same or not.
// If they are the same, the browser does not need to be updated.
// If they are different, then send the new state xml to the browser so that it can be updated.
Document xmlDoc = XMLUtil.newDocument();
renderSliderXML(XMLUtil.createElement(xmlDoc, "root", null, null), component);
XMLUtil.transform(xmlDoc, null);
parentElement.appendChild(parentElement.getOwnerDocument().importNode(xmlDoc.getElementsByTagName("root").item(0).getFirstChild(), true));
}
public void renderSliderXML(final Element parentElement, final UIComponent aComponent) {
MapControl mapControl = (MapControl) aComponent;
WebContext webContext = WebUtil.getWebContext(mapControl);
WebMap webMap = webContext.getWebMap();
double mapScale = webMap.getMapScale();
FacesContext facesContext = FacesContext.getCurrentInstance();
IScaleSliderConfig ssb = (IScaleSliderConfig) facesContext.getApplication().createValueBinding("#{scaleSliderBB}").getValue(facesContext);
Element anElement = XMLUtil.createElement("slider-update", null, parentElement);
if (isInside(mapControl)) { // if extent inside valid bounds set current map scale
anElement.setAttribute("mapUpdate", "true");
} else { // if extent outside get valid scale from mapScale_ <= getMaxAllowedScale()
anElement.setAttribute("mapUpdate", "false");
}
anElement.setAttribute("mapscale-value", Long.toString(Math.round(mapScale)));
anElement.setAttribute("minscale-value", Long.toString(Math.round(ssb.getMinScale())));
anElement.setAttribute("maxscale-value", Long.toString(Math.round(ssb.getMaxScale())));
}
private boolean isInside(MapControl mapControl) {
WebContext webContext = WebUtil.getWebContext(mapControl);
WebMap webMap = webContext.getWebMap();
WebExtent webExtent = webMap.getCurrentExtent();
WebExtent fullExtent = webMap.getFullExtent();
com.esri.solutions.jitk.web.data.geometry.WebExtent newExtent =
new com.esri.solutions.jitk.web.data.geometry.WebExtent(webExtent);
//Do not scale the map to an extent that is not supported by the horizon of the
//coordinate system, i.e. full extent
if (GeometryUtil.inside(newExtent, fullExtent)) {
return true;
} else { // if map scale not within bounds calculate maximum valid scale
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -