📄 webcontext.java
字号:
/**
* Determines if the specified {@link GISResource} should be treated
* as an overlay. The {@link GISResource} is an Overlay if
* it contains an {@link OverlayFunctionality}.
*
* @param resource GIS Resource to determine whether an Overlay.
* @return Flag indicating if {@link GISResource} is an Overlay.
*/
public boolean isOverlay(GISResource resource) {
return resource.getFunctionality(OverlayFunctionality.FUNCTIONALITY_NAME) != null;
}
/**
* Returns the collection of GIS Resources that are
* Overlays. A GIS Resource is an Overlay if it contains
* an {@link OverlayFunctionality}.
*
* @return Collection of GIS Resources, indexed by Resource ID.
* <code>null</code> will never be returned.
*/
public Map<String, GISResource> getOverlayResources() {
Map<String, GISResource> overlays = new LinkedHashMap<String, GISResource>();
for (Entry<String, GISResource> entry : this.resources.entrySet()) {
GISResource resource = entry.getValue();
if (resource == null) {
continue;
}
if (isOverlay(resource)) {
overlays.put(entry.getKey(), entry.getValue());
}
}
return overlays;
}
/**
* Returns the collection of GIS Resources that are not
* Overlays. A GIS Resource is not an Overlay if it does
* not contain a {@link OverlayFunctionality}.
*
* @return Collection of GIS Resources, indexed by Resource ID.
* <code>null</code> will never be returned.
*/
public Map<String, GISResource> getNonOverlayResources() {
Map<String, GISResource> nonOverlays = new LinkedHashMap<String, GISResource>();
for (Entry<String, GISResource> entry : this.resources.entrySet()) {
GISResource resource = entry.getValue();
if (resource == null) {
continue;
}
if (!isOverlay(resource)) {
nonOverlays.put(entry.getKey(), entry.getValue());
}
}
return nonOverlays;
}
/**
* Determines if the specified GIS Resource can be moved
* up in the order. If the GIS Resource is an Overlay
* then it can't be moved up. Also, if the GIS Resource
* is the first GIS Resource under the Overlays then it
* can't be moved up.
*
* @param resource GIS Resource to determine if it can be
* moved up.
* @return Flag indicating if the GIS Resource can be
* moved up.
*/
public boolean canMoveUp(GISResource resource) {
if (isOverlay(resource)) {
return false;
}
Map<String, GISResource> nonOverlays = getNonOverlayResources();
List<GISResource> list = new ArrayList<GISResource>(nonOverlays.values());
return list.indexOf(resource) > 0;
}
/**
* Determines if the specified GIS Resource can be moved
* down in the order. If the GIS Resource is an Overlay
* then it can't be moved down. Also, if the GIS Resource
* is at the bottom then it can't be moved down.
*
* @param resource GIS Resource to determine if it can be
* moved down.
* @return Flag indicating if the GIS Resource can be
* moved down.
*/
public boolean canMoveDown(GISResource resource) {
if (isOverlay(resource)) {
return false;
}
Map<String, GISResource> nonOverlays = getNonOverlayResources();
List<GISResource> list = new ArrayList<GISResource>(nonOverlays.values());
return list.indexOf(resource) < list.size();
}
/**
* Determines if the specified GIS Resource can be removed.
* A GIS Resource can be removed as long as its not an Overlay.
*
* @param resource GIS Resource to determine if it can be
* removed.
* @return Flag indicating if the GIS Resource can be removed.
*/
public boolean canRemove(GISResource resource) {
return !isOverlay(resource);
}
/**
* Sets the reference to the Error Producer in order to
* send error messages to the UI.
*
* @param producer Reference to Error Producer.
*/
public void setErrorProducer(IErrorProducer producer) {
m_errorProducer = producer;
}
/**
* Called before this {@link WebContext} is initialized
* via {@link #setInit(boolean)}. In this implementation,
* the GIS Resources will be ordered. Overlays will be
* placed on top, and non-overlays will be placed on the
* bottom.
*
* @see #orderGISResources()
*/
protected void preInit() {
orderGISResources();
}
/**
* Orders the GIS Resources within this {@link WebContext}.
* Overlays are on top, Non Overlays are on the bottom.
*
* @see #getOverlayResources()
* @see #getNonOverlayResources()
*/
protected void orderGISResources() {
Map<String, GISResource> overlays = getOverlayResources();
Map<String, GISResource> nonOverlays = getNonOverlayResources();
this.resources.clear();
this.resources.putAll(overlays);
this.resources.putAll(nonOverlays);
}
/**
* Sets the reference to the Horizon Lookup.
*
* @param horizonLookup Reference to object implementing IHorizonLookup interface.
*/
public void setHorizonLookup(IHorizonLookup horizonLookup) {
if (horizonLookup != null) {
this.horizonLookup = horizonLookup;
}
}
/**
* Sets Map full extent.
*
* @param fullExtent {@link WebExtent} to set as a new map full extent.
*/
public void setMapFullExtent(WebExtent fullExtent) {
if (fullExtent != null) {
WebMap map = getWebMap();
map.init(this);
map.setFullExtent(fullExtent);
_logger.debug("Full Exent set to " + fullExtent);
//Calculate new current extent given map aspect ratio so that
//full extent is not exceeded by ADF when adjusting current extent
//to map.
com.esri.solutions.jitk.web.data.geometry.WebExtent newExt = new com.esri.solutions.jitk.web.data.geometry.WebExtent(fullExtent).getAdjustedExtent(map.getWidth(), map.getHeight());
_logger.debug("Current Extent set to " + newExt);
map.setCurrentExtent(newExt);
map.setInitExtent(newExt);
WebOverview overview = getWebOverview();
overview.exportImage();
overview.reloadImageRectangle();
}
}
/**
* Discovers full extent of the resource.
*
* @param resource Input {@link GISResource}.
* @return {@link WebExtent} object representing full extent of the resource provided.
*
*/
private WebExtent lookupFullExtent(GISResource resource) {
MapFunctionality mFunc = (resource != null) ? (MapFunctionality) resource.getFunctionality(MapFunctionality.FUNCTIONALITY_NAME) : null;
return (mFunc != null) ? mFunc.getFullExtent() : null;
}
/**
* Discovers horizon of the spatial reference.
*
* @param spatialReference Input {@link WebSpatialReference}.
* @return {@link WebExtent} object representing horizon of the {@link WebSpatialReference} provided.
*
*/
private WebExtent lookupFullExtent(WebSpatialReference spatialReference) {
return ((spatialReference != null) && (horizonLookup != null)) ? horizonLookup.lookup(spatialReference.getId()) : null;
}
/**
* Sets the spatial reference associated with this context.
*
* @param spatialReference {@link WebSpatialReference} associated with this context.
*
*/
@Override
public void setSpatialReference(WebSpatialReference spatialReference) {
if((spatialReference != null) && !spatialReference.equals(this.spatialReference)) {
super.setSpatialReference(spatialReference);
setMapFullExtent(lookupFullExtent(spatialReference));
setInit(true);
}
}
/**
* Sets the spatial reference associated with this context by its definition string.
*
* @param definitionString Definition string of the {@link WebSpatialReference} associated with this context.
*
*/
@Override
public void setSpatialReferenceDefinitionString(String definitionString) {
this.setSpatialReference(WebSpatialReference.getWebSpatialReference(definitionString));
}
/**
* Sets the spatial reference associated with this context by its ID.
*
* @param id ID of the {@link WebSpatialReference} associated with this context.
*
*/
@Override
public void setSpatialReferenceId(int id) {
this.setSpatialReference(WebSpatialReference.getWebSpatialReference(id));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -