com.esri.adf.web.ags.data.edit
Class SnapHandler

java.lang.Object
  extended by com.esri.adf.web.ags.data.edit.SnapHandler
All Implemented Interfaces:
ActionEventListener, Serializable, EventListener

public class SnapHandler
extends Object
implements Serializable, ActionEventListener

Handles Geometry snapping. It can also work as an event listener that listens to PreFeatureStoreEvent and snaps the feature geometry curried by the event. A sample of copy and snapping:

 //create a select action
 SelectByExtent select = new SelectByExtent(EditUtil.toEnvelope(-2309712.539, -887434.291, -1023725.086, 411499.344, map
     .getSpatialReference(), ctx));
 
 //one feature per select
 select.setMaxCount(1);
 
 //create a copy feature action
 CopyFeature copy = new CopyFeature(EditUtil.toILine(-2309712.539, -887434.291, -1023725.086, 411499.344, map
     .getSpatialReference(), ctx));
 
 SnapHandler snap = new SnapHandler();
 
 //create a snap rule
 snap.setSnapType(snaplayer, Integer.valueOf(esriGeometryHitPartType.esriGeometryPartBoundary
     | esriGeometryHitPartType.esriGeometryPartEndpoint | esriGeometryHitPartType.esriGeometryPartVertex));
 
 //all the feature to be copy will be snapped    
 copy.addEventListener(snap);
 
 // select and copy
 workspace.perform(context, select, copy);
 

See Also:
Serialized Form

Constructor Summary
SnapHandler()
           
 
Method Summary
 Map<com.esri.arcgis.carto.IFeatureLayer,Integer> getLayers()
          Gets the layer and snap type pairs.
 Integer getSnapType(com.esri.arcgis.carto.IFeatureLayer key)
          Gets the snap type.
static com.esri.arcgis.geometry.ISpatialReference getSpatialReference(com.esri.arcgis.carto.IFeatureLayer flayer)
          Gets spatial reference of the feature layer.
 int getTolerance()
          Gets the snapping tolerance in pixels.
 void onEvent(EditEvent event)
          Invokes the listener for the event.
 void setLayers(Map<com.esri.arcgis.carto.IFeatureLayer,Integer> layers)
          Sets the layer and snap type pairs.
 Integer setSnapType(com.esri.arcgis.carto.IFeatureLayer key, Integer value)
          Sets the snap type.
 void setTolerance(int tolerance)
          Sets the snapping tolerance in pixels.
 com.esri.arcgis.geometry.IGeometry snapGeometry(com.esri.arcgis.geometry.IGeometry geometry, com.esri.arcgis.geometry.IEnvelope bounds, int imageWidth, com.esri.arcgis.server.IServerContext ctx)
          Snaps a geometry
 Object[] snapPoint(com.esri.arcgis.geometry.IPoint point, boolean returnNull, com.esri.arcgis.server.IServerContext ctx, com.esri.arcgis.geometry.IEnvelope mapbounds, int imageWidth)
          Snaps a point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnapHandler

public SnapHandler()
Method Detail

getTolerance

public int getTolerance()
Gets the snapping tolerance in pixels.

Returns:
Returns the tolerance.

setTolerance

public void setTolerance(int tolerance)
Sets the snapping tolerance in pixels.

Parameters:
tolerance - The tolerance to set.

snapGeometry

public com.esri.arcgis.geometry.IGeometry snapGeometry(com.esri.arcgis.geometry.IGeometry geometry,
                                                       com.esri.arcgis.geometry.IEnvelope bounds,
                                                       int imageWidth,
                                                       com.esri.arcgis.server.IServerContext ctx)
                                                throws Exception
Snaps a geometry

Parameters:
geometry - the geometry to snap.
bounds - the map bounds.
imageWidth - the map width in pixels.
Returns:
the snap result.
Throws:
Exception

getSpatialReference

public static com.esri.arcgis.geometry.ISpatialReference getSpatialReference(com.esri.arcgis.carto.IFeatureLayer flayer)
                                                                      throws IOException,
                                                                             com.esri.arcgis.interop.AutomationException
Gets spatial reference of the feature layer.

Parameters:
flayer - the layer
Throws:
IOException
com.esri.arcgis.interop.AutomationException

snapPoint

public Object[] snapPoint(com.esri.arcgis.geometry.IPoint point,
                          boolean returnNull,
                          com.esri.arcgis.server.IServerContext ctx,
                          com.esri.arcgis.geometry.IEnvelope mapbounds,
                          int imageWidth)
                   throws Exception
Snaps a point.

Parameters:
point - the point to snap.
returnNull - set true to return null when no snap performed.
mapbounds - the map bounds.
imageWidth - the map width in pixels.
Returns:
the snap result as an Object[2]{Point,ILayer}
Throws:
Exception

onEvent

public void onEvent(EditEvent event)
Description copied from interface: ActionEventListener
Invokes the listener for the event.

Specified by:
onEvent in interface ActionEventListener
Parameters:
event - the event.

getSnapType

public Integer getSnapType(com.esri.arcgis.carto.IFeatureLayer key)
Gets the snap type. It is a combination of
  • esriGeometryHitPartType.esriGeometryPartBoundary
  • esriGeometryHitPartType.esriGeometryPartVertex
  • esriGeometryHitPartType.esriGeometryPartEndpoint
  • Parameters:
    key - the layer
    Returns:
    the type

    setSnapType

    public Integer setSnapType(com.esri.arcgis.carto.IFeatureLayer key,
                               Integer value)
    Sets the snap type. The key the layer, the value is a combination of
  • esriGeometryHitPartType.esriGeometryPartBoundary
  • esriGeometryHitPartType.esriGeometryPartVertex
  • esriGeometryHitPartType.esriGeometryPartEndpoint
  • Parameters:
    key -
    value -
    Returns:
    previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.

    getLayers

    public Map<com.esri.arcgis.carto.IFeatureLayer,Integer> getLayers()
    Gets the layer and snap type pairs.

    Returns:
    Returns the layers.

    setLayers

    public void setLayers(Map<com.esri.arcgis.carto.IFeatureLayer,Integer> layers)
    Sets the layer and snap type pairs.

    Parameters:
    layers - The layers to set.