📄 cleargraphicsresourcesadapter.java
字号:
package com.esri.solutions.jitk.web.tasks.mapcomp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.graphics.GraphicsLayer;
import com.esri.adf.web.data.graphics.GraphicsResource;
import com.esri.solutions.jitk.web.tasks.IWebContextAware;
/**
* Clears the Graphics on the map when a Map Composition is
* opened or created. This object will observe the <code>created</code>
* and <code>opened</code> events that are fired by the Map
* Composition tasks.
*/
public class ClearGraphicsResourcesAdapter implements
IMapCompositionEventObserver {
/**
* ID of the Graphics Resource within the WebContext
*/
private String m_resourceId;
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver#created(com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent)
*/
public void created(MapCompositionEvent event) {
if (event.getSource() instanceof IWebContextAware) {
IWebContextAware ctxAware = (IWebContextAware) event.getSource();
WebContext ctx = ctxAware.getContext();
removeGraphics(ctx);
}
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver#deleted(com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent)
*/
public void deleted(MapCompositionEvent event) {
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver#opened(com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent)
*/
public void opened(MapCompositionEvent event) {
if (event.getSource() instanceof IWebContextAware) {
IWebContextAware ctxAware = (IWebContextAware) event.getSource();
WebContext ctx = ctxAware.getContext();
removeGraphics(ctx);
}
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver#saved(com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent)
*/
public void saved(MapCompositionEvent event) {
}
/**
* Sets the ID of the Graphics Resource within the Web Context.
* The Graphics Resource will be cleared of all graphics when this
* object is notified of a <code>created</code> or <code>opened</code>
* event.
*
* @param resourceId
*/
public void setGraphicsResourceId (String resourceId) {
m_resourceId = resourceId;
}
/**
* Removes the Graphics from the Web Context. The Graphics
* Resource ID will be used to find the Graphics Resource. The
* Graphics Resource will then be cleared of all Graphics.
*
* @param ctx WebContext object to have its Graphics cleared.
*/
protected void removeGraphics (WebContext ctx) {
List<GraphicsResource> graphics = new ArrayList<GraphicsResource>();
if (m_resourceId == null) {
for (Entry<String, GISResource> entry : ctx.getResources().entrySet()) {
if (entry.getValue() instanceof GraphicsResource) {
graphics.add((GraphicsResource) entry.getValue());
}
}
} else {
GISResource res = ctx.getResourceById(m_resourceId);
if (res instanceof GraphicsResource) {
graphics.add((GraphicsResource) res);
}
}
if (graphics.isEmpty()) {
return;
}
for (GraphicsResource graphicsRes : graphics) {
List<GraphicsLayer> layers = graphicsRes.getLayers(true);
for (GraphicsLayer layer : layers) {
layer.removeAllGraphicFeatures();
}
}
ctx.refresh();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -