📄 webcontext.java
字号:
package com.esri.solutions.jitk.web.data;
import com.esri.adf.web.ADFException;
import com.esri.adf.web.data.GISFunctionality;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.MapFunctionality;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.WebOverview;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebSpatialReference;
import com.esri.solutions.jitk.web.error.DefaultError;
import com.esri.solutions.jitk.web.error.IErrorProducer;
import com.esri.solutions.jitk.web.projection.horizon.IHorizonLookup;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* Extension of {@link com.esri.adf.web.data.WebContext} in order
* to provide custom functionality. This custom functionality
* includes the concept of Overlays and constraining the Map to
* the horizon of the current map Spatial Reference.
*
* <p>
* Overlays are GIS Resources that must remain on top of the Map
* and Table Of Contents. A GIS Resource is an Overlay if
* it contains an {@link OverlayFunctionality} in its set
* of {@link GISFunctionality} objects. An Overlay is static,
* it cannot be moved or removed. Overlays are added to the
* configuration of a WebContext within the bean framework.
* The current implementation does not support overlays
* being added at runtime.
* </p>
*
* <p>
* When a GIS Resource is added to this {@link WebContext} it
* is added at the top of the Map, but under any Overlays. The Current
* Extent of the Map is set to the Current Extent of
* the GIS Resource. The Full Extent of the Map is set to
* the Full Extent of the GIS Resource. The Spatial Reference
* of the Map is also changed to the Spatial Reference of
* the GIS Resource. This allows the Map to be zoomed to the
* Map Service being added to the Map. It also prevents the
* Map from going outside of the Full Extent of the GIS Resource
* in order to prevent projection issues. This implementation
* considers the horizon of the Spatial Reference to be the
* Full Extent of the GIS Resource.
* </p>
*
* <p>
* When multiple GIS Resources are being replaced within this {@link WebContext},
* via the {@link #setResources(Map)} method, the Full Extent, Current
* Extent, and Spatial Reference of the Map are left intact. It is
* up to the caller of {@link #setResources(Map)} to manipulate
* those field values. After {@link #setResources(Map)} has been
* invoked and the other field values have been set appropriately
* (Current Extent, Full Extent, Spatial Reference), then the
* caller must invoke {@link #setInit(boolean) setInit(true)} to
* reinitialize this {@link WebContext}.
* </p>
*
* <p>
* Also, when multiple GIS Resources are being replaced within this
* {@link WebContext} this implementation is fault tolerant. If
* the initialization of one GIS Resource fails, it will send
* a warning message, and continue with the other GIS Resources.
* </p>
*/
public class WebContext extends com.esri.adf.web.data.WebContext {
private static final Logger _logger = LogManager.getLogger(WebContext.class);
private static final long serialVersionUID = 3420058782421187233L;
/**
* Reference to Horizon Lookup
*/
private IHorizonLookup horizonLookup = null;
/**
* Flag indicating if the {@link #init(com.esri.adf.web.data.WebContext)}
* method has already been successfully invoked.
*/
private boolean m_initMethodFlag = false;
/**
* Reference to Error Producer to send messages to the
* UI for display.
*/
private IErrorProducer m_errorProducer;
/*
* (non-Javadoc)
* @see com.esri.adf.web.data.WebContext#setInit(boolean)
*/
@Override
public void setInit(boolean init) {
if (init && super.init) {
super.init = false;
}
preInit();
super.setInit(init);
}
/*
* (non-Javadoc)
* @see com.esri.adf.web.data.WebContext#addResource(java.lang.String, com.esri.adf.web.data.GISResource, int)
*/
@Override
public void addResource(String id, GISResource newResource, int index) {
Map<String, GISResource> overlays = getOverlayResources();
Map<String, GISResource> nonOverlays = getNonOverlayResources();
this.resources.clear();
this.resources.putAll(overlays);
if (nonOverlays.isEmpty()) {
this.resources.put(id, newResource);
}
int i = 0;
for (Entry<String, GISResource> entry : nonOverlays.entrySet()) {
if (index == i) {
this.resources.put(id, newResource);
}
i++;
this.resources.put(entry.getKey(), entry.getValue());
}
try {
if (m_initMethodFlag) {
newResource.init(this);
}
setInit(true);
super.setSpatialReference(newResource.getDefaultSpatialReference());
setMapFullExtent(lookupFullExtent(newResource));
} catch (ADFException ex) {
_logger.warn("An error has occurred adding resource to the map - removing invalid resource",
ex);
this.removeResource(newResource);
}
}
/*
* (non-Javadoc)
* @see com.esri.adf.web.data.WebContext#addResource(java.lang.String, com.esri.adf.web.data.GISResource)
*/
@Override
public void addResource(String id, GISResource resource) {
addResource(id, resource, 0);
}
/*
* (non-Javadoc)
* @see com.esri.adf.web.data.WebContext#moveResource(int, com.esri.adf.web.data.GISResource)
*/
@Override
public void moveResource(int toIndex, GISResource resource) {
if (isOverlay(resource)) {
return;
}
Map<String, GISResource> overlays = getOverlayResources();
if (toIndex < overlays.size()) {
toIndex = overlays.size();
}
super.moveResource(toIndex, resource);
}
/*
* (non-Javadoc)
* @see com.esri.adf.web.data.WebContext#removeResource(com.esri.adf.web.data.GISResource)
*/
@Override
public boolean removeResource(GISResource resource) {
if (isOverlay(resource)) {
return false;
}
this.resources.values().remove(resource);
resource.destroy();
for (Entry<String, GISResource> entry : getNonOverlayResources()
.entrySet()) {
GISResource first = entry.getValue();
super.setSpatialReference(first.getDefaultSpatialReference());
setMapFullExtent(lookupFullExtent(first));
break;
}
this.setInit(true);
return true;
}
/*
* (non-Javadoc)
* @see com.esri.adf.web.data.WebContext#setResources(java.util.Map)
*/
@Override
public void setResources(Map<String, GISResource> newResources) {
Map<String, GISResource> overlays = getOverlayResources();
Map<String, GISResource> copyOfNewResources = new LinkedHashMap<String, GISResource>();
copyOfNewResources.putAll(newResources);
if (m_initMethodFlag) {
for (Entry<String, GISResource> entry : copyOfNewResources.entrySet()) {
GISResource resource = entry.getValue();
try {
resource.init(this);
} catch (ADFException e) {
resource.destroy();
copyOfNewResources.values().remove(resource);
if (m_errorProducer != null) {
DefaultError error = new DefaultError();
error.setCode("warn");
error.setMessage("Unable to initialize resource " +
resource.getAlias() + ".");
m_errorProducer.push(error);
}
}
}
}
this.resources.clear();
this.resources.putAll(overlays);
this.resources.putAll(copyOfNewResources);
orderGISResources();
}
/*
* (non-Javadoc)
* @see com.esri.adf.web.data.WebContext#init(com.esri.adf.web.data.WebContext)
*/
@Override
public void init(com.esri.adf.web.data.WebContext ctx) {
super.init(ctx);
m_initMethodFlag = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -