📄 graphicsmaker.java
字号:
package com.esri.webadf.sample;
import java.util.Arrays;
import org.apache.axis.types.UnsignedByte;
import com.esri.adf.web.ags.data.AGSMapFunctionality;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.faces.event.MapEvent;
import com.esri.arcgisws.EsriSimpleMarkerStyle;
import com.esri.arcgisws.GraphicElement;
import com.esri.arcgisws.MapDescription;
import com.esri.arcgisws.MarkerElement;
import com.esri.arcgisws.PointN;
import com.esri.arcgisws.RgbColor;
import com.esri.arcgisws.SimpleMarkerSymbol;
public class GraphicsMaker {
private WebContext webContext = null;
public WebContext getWebContext() {
return webContext;
}
public void setWebContext(WebContext webContext) {
this.webContext = webContext;
}
public String addText(){
return null;
}
public void addPoint(MapEvent event){
//get the point the user clicked and convert it from image coordinates to map coordinates
WebMap webMap = webContext.getWebMap();
WebPoint point = (WebPoint) event.getWebGeometry().toMapGeometry(webMap);
//get the mapResource so we can get to the MapDescription
AGSMapResource mapResource = (AGSMapResource) webContext.getResources().get("ags1");
AGSMapFunctionality mapFunctionality = (AGSMapFunctionality) mapResource.getFunctionality("map");
MapDescription mapDescription = mapFunctionality.getMapDescription();
//Get any existing graphic elements from the map description
GraphicElement[] existingElements = mapDescription.getCustomGraphics();
GraphicElement[] graphicElements = null;
if(existingElements == null){
graphicElements = new GraphicElement[1];
} else {
//there were already graphic elements so we need to copy them to our array
graphicElements = new GraphicElement[existingElements.length + 1];
System.arraycopy(existingElements, 0, graphicElements, 0, existingElements.length );
}
//make a marker element and set it's properties
MarkerElement markerElement = new MarkerElement();
PointN pointN = new PointN(point.getX(), point.getY(), null, null, null, null);
markerElement.setPoint(pointN);
//make a marker symbol for the element
SimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol();
markerSymbol.setSize(15.0);
markerSymbol.setStyle(EsriSimpleMarkerStyle.esriSMSCircle);
RgbColor color = new RgbColor();
color.setAlphaValue(new UnsignedByte(255));
color.setBlue(new UnsignedByte(0));
color.setRed(new UnsignedByte(255));
color.setGreen(new UnsignedByte(0));
markerSymbol.setColor(color);
markerSymbol.setOutlineColor(color);
markerElement.setSymbol(markerSymbol);
//add the markerElement to the array of graphicElements
graphicElements[graphicElements.length-1] = markerElement;
//set the custom graphics, this is a remote call
mapDescription.setCustomGraphics(graphicElements);
//refresh the context because the Mapdescription has changed and we want to see the changes
//in the map that is drawn
webContext.refresh();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -