📄 defaultopenmapcomposition.java
字号:
package com.esri.solutions.jitk.web.tasks.mapcomp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.esri.adf.web.ags.data.AGSLocalMapResource;
import com.esri.adf.web.ags.data.AGSMapFunctionality;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.MapFunctionality;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebSpatialReference;
import com.esri.arcgisws.LayerDescription;
import com.esri.arcgisws.MapLayerInfo;
import com.esri.solutions.jitk.common.personalization.ADFPersonalizationContext;
import com.esri.solutions.jitk.common.personalization.IPersonalizable;
import com.esri.solutions.jitk.common.personalization.IPersonalizationContext;
import com.esri.solutions.jitk.personalization.PersonalizationException;
import com.esri.solutions.jitk.personalization.data.IMapComposition;
import com.esri.solutions.jitk.personalization.data.beans.v1.AgsInternetServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.AgsLocalServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.ArcImsInternetServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.ArcImsTcpServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.AttributeCollectionType;
import com.esri.solutions.jitk.personalization.data.beans.v1.AttributeType;
import com.esri.solutions.jitk.personalization.data.beans.v1.EnvelopeNType;
import com.esri.solutions.jitk.personalization.data.beans.v1.LayerListType;
import com.esri.solutions.jitk.personalization.data.beans.v1.LayerType;
import com.esri.solutions.jitk.personalization.data.beans.v1.MapCompositionType;
import com.esri.solutions.jitk.personalization.data.beans.v1.ServiceListType;
import com.esri.solutions.jitk.personalization.data.beans.v1.WcsServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.WfsServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.WmsServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.LayerListType.LayerItemType;
import com.esri.solutions.jitk.personalization.data.beans.v1.ServiceListType.ServiceItemType;
import com.esri.solutions.jitk.web.data.WebContext;
import com.esri.solutions.jitk.web.tasks.resources.ResourceAdder;
/**
* Default implementation of {@link IOpenMapComposition} in order to
* provide a default implementation of opening a Map Composition within
* the viewer.
*/
public class DefaultOpenMapComposition implements IPersonalizable,
IOpenMapComposition {
private static final String WARN_UNABLE_TO_FIND_LAYER_AGS = "Unable to find AGS Layer {0}, {1} in AGS Service {2}.";
/**
* Logger to use to log messages from this class.
*/
private static final Logger LOG = LogManager.getLogger(DefaultOpenMapComposition.class);
/**
* List of messages that are generated by an operation.
*/
private final List<String> m_messages;
/**
* Reference to Personalization Context for Personalization data and functions.
*/
private IPersonalizationContext m_persCtx;
/**
* Reference to object to convert between Map Composition Beans
* and ADF objects.
*/
private IBeanToADFConverter m_converter;
/**
* Constructs a new <code>DefaultOpenMapComposition</code>
* object.
*/
public DefaultOpenMapComposition() {
m_messages = new ArrayList<String>();
m_converter = new DefaultBeanToADFConverter();
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.web.tasks.mapcomp.IOpenMapComposition#open(com.esri.solutions.jitk.personalization.data.IMapComposition)
*/
public void open(IMapComposition mc) throws PersonalizationException {
if (mc == null) {
throw new NullPointerException();
}
MapCompositionType mcData = mc.getMapComposition();
applyBackgroundColor(mcData);
applyServices(mcData);
m_persCtx.getWebContext().setInit(true);
applySpatialReference(mcData);
applyFullExtent(mcData);
applyExtent(mcData);
//m_persCtx.getWebContext().refresh();
m_persCtx.setAttribute(ADFPersonalizationContext.CURRENT_MAP_COMPOSITION_KEY,
mc);
}
/**
* Applies the extent information contained within the Map Composition
* to the WebContext.
*
* @param mcData Map Composition data.
*/
protected void applyExtent(MapCompositionType mcData) {
WebExtent extent = null;
EnvelopeNType initial = mcData.getInitialEnvelope();
if (initial != null) {
extent = new WebExtent();
extent.setMinX(initial.getXMin());
extent.setMinY(initial.getYMin());
extent.setMaxX(initial.getXMax());
extent.setMaxY(initial.getYMax());
if (initial.getSpatialReference() != null) {
WebSpatialReference wsr = WebSpatialReference.getWebSpatialReference(initial.getSpatialReference()
.getWKT());
extent.setSpatialReference(wsr);
}
m_persCtx.getWebContext().getWebMap().setCurrentExtent(extent);
}
}
/**
* Applies the Full Extent that was saved within the Map Composition
* and sets it within the {@link WebContext}. This keeps the Map
* constrained to a Full Extent that is within the Spatial
* Reference's horizon.
*
* @param mcData Map Composition data.
*/
protected void applyFullExtent (MapCompositionType mcData) {
if (!(m_persCtx.getWebContext() instanceof WebContext)) {
LOG.warn("Cannot apply Full Extent correctly, because WebContext is not instance of " + WebContext.class.getName());
return;
}
AttributeCollectionType attrs = mcData.getAttributes();
if (attrs == null) {
return;
}
AttributeType fullExtentAttr = null;
for (Object o : attrs.getAttribute()) {
if (!(o instanceof AttributeType)) {
continue;
}
AttributeType attr = (AttributeType) o;
if (attr.getName() == null) {
continue;
}
if (attr.getName().equals("FullExtent")) {
fullExtentAttr = attr;
break;
}
}
if (fullExtentAttr == null) {
return;
}
String fullExtentStr = fullExtentAttr.getValue();
if (fullExtentStr == null) {
return;
}
String[] fullExtentArr = fullExtentStr.split(",", 5);
WebExtent fullExtent = new WebExtent();
fullExtent.setMinX(Double.valueOf(fullExtentArr[0]));
fullExtent.setMinY(Double.valueOf(fullExtentArr[1]));
fullExtent.setMaxX(Double.valueOf(fullExtentArr[2]));
fullExtent.setMaxY(Double.valueOf(fullExtentArr[3]));
WebSpatialReference sr = WebSpatialReference.getWebSpatialReference(fullExtentArr[4]);
fullExtent.setSpatialReference(sr);
((WebContext)m_persCtx.getWebContext()).setMapFullExtent(fullExtent);
}
/**
* Applies the Spatial Reference information contained within
* the Map Composition to the WebContext.
*
* @param mcData Map Composition Data.
*/
protected void applySpatialReference(MapCompositionType mcData) {
WebSpatialReference wsr = null;
if (mcData.getSpatialReference() != null) {
wsr = WebSpatialReference.getWebSpatialReference(mcData.getSpatialReference()
.getWKT());
m_persCtx.getWebContext().setSpatialReference(wsr);
}
}
/**
* Uses the Map Composition Data to apply the Map Services within the
* Map Composition to the Map Viewer.
*
* @param mcData Map Composition Data, cannot be <code>null</code>.
*
* @throws NullPointerException Thrown if the <code>mcData</code>
* argument is <code>null</code>.
*/
@SuppressWarnings("unchecked")
protected void applyServices(MapCompositionType mcData) {
ResourceAdder resourceAdder = null;
GISResource resource = null;
if (mcData == null) {
throw new NullPointerException();
}
resourceAdder = new ResourceAdder();
resourceAdder.setWebContext(m_persCtx.getWebContext());
Map<String, GISResource> newResources = new LinkedHashMap<String, GISResource>();
ServiceListType servicesList = mcData.getServices();
List services = new ArrayList(servicesList.getServiceItem());
for (Iterator i = services.iterator(); i.hasNext();) {
ServiceItemType service = (ServiceItemType) i.next();
String id = UUID.randomUUID().toString();
if (service.getAgsInternetService() != null) {
AgsInternetServiceType agsInet = service.getAgsInternetService();
resource = m_converter.createAGSMapResource(agsInet);
newResources.put(id, resource);
} else if (service.getAgsLocalService() != null) {
AgsLocalServiceType agsLocal = service.getAgsLocalService();
resource = m_converter.createAGSLocalMapResource(agsLocal);
newResources.put(id, resource);
} else if (service.getArcImsInternetService() != null) {
ArcImsInternetServiceType aimsInet = service.getArcImsInternetService();
resource = m_converter.createAIMSMapResource(aimsInet);
newResources.put(id, resource);
} else if (service.getArcImsTcpService() != null) {
ArcImsTcpServiceType aimsTcp = service.getArcImsTcpService();
resource = m_converter.createAIMSMapResource(aimsTcp);
newResources.put(id, resource);
} else if (service.getWmsService() != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -