Upload Download
com\esri\arcgis\sample\upload\PointTool.java
/* Copyright 2010 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions.
* 
*/
package com.esri.arcgis.sample.upload;

import com.esri.adf.web.data.GraphicElement;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebGraphics;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.symbol.WebSimpleMarkerSymbol;
import com.esri.adf.web.faces.event.MapEvent;
import com.esri.adf.web.faces.event.MapToolAction;
import java.util.Random;

/**
 * A simple class that implements MapToolAction and add a point to the web graphics.
 */
public class PointTool implements MapToolAction {
  private static WebSimpleMarkerSymbol markerSymbol;

  static {
    //set symbology to be used for displaying the added point
    markerSymbol = new WebSimpleMarkerSymbol();
    markerSymbol.setAngle(0);
    Random rand = new Random();
    String colorStr = (rand.nextInt(255)+1) + "," + (rand.nextInt(255)+1) + "," + (rand.nextInt(255)+1);
    markerSymbol.setColor(colorStr);
    markerSymbol.setMarkerType(WebSimpleMarkerSymbol.CIRCLE);
    markerSymbol.setOutlineColor("0,0,0");
    markerSymbol.setTransparency(1.0);
    markerSymbol.setWidth(50);
  }

  /**
   * Implements function defined in interface to process user's mouse click and 
   * adds point to web graphics.
   */
  public void execute(MapEvent event){
    //get web context and point from map event
    WebContext context = event.getWebContext();
    WebPoint point = (WebPoint) event.getWebGeometry();

    //generate graphic element using point and symbology defined
    GraphicElement element = new GraphicElement();
    element.setSymbol(markerSymbol);
    element.setGeometry(point.toMapGeometry(context.getWebMap()));

    //add graphic element to web graphics
    WebGraphics graphics = context.getWebGraphics();
    graphics.addGraphics(element);
  }
}