Select to view content in your preferred language

Snapping

2991
3
06-06-2011 11:58 PM
MatthewPilgrim
Regular Contributor
Hi,

I have several [simple] questions about snapping (v2.1 onwards):

1) I see that the editor class has setting to control the snapping hotkey and tolerances.  But its not clear what graphics it can snap to whilst adding new geometry.  To enable the add command we are limited to one layerid (see add command api docs), does this mean snapping is limited to that layer or all visible graphics?  [Note: I tried the editor widget sdk example and it doesn't snap to the red graphics.  It does have multiple layerids set in the C#.  Adding seems to fail after the pop up box asks for a number\text]

2) Almost by accident we found that snapping is available via the draw class (i.e. NOT the editor or editor widget) using the Control (CTRL) key.  How do we change this key and the associated tolerances for the draw class?

3) When adding graphics using the draw or editor class the snapping doesn't allow me to snap to the graphic currently been drawn.  Can this be added in future?

4) Finally before discovering the draw class snapping I tried to add my own snap code.  This went well until trying to replace the point the user clicked with my own nearest snap point.  The only api hook I could find was the draw.vertexadded event.  In here I tried to undo the last vertex and then add my own but this gave strange behaviour.  As anyone got something similar to work and how? [a berforevertex added event with e.handled would be useful here]

Thanks in anticipation,

Matt
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
You can try out the following sample that use both Add (Draw) and EditVertices. Both of these commands, allow snapping.

By default, snap key is Ctrl-key and snap distance is 15. If you are using Draw or Editor, you overwrite the default in the same way
esri:Editor.SnapDistance="20" esri:Editor.SnapKey="S"

In this snippet, there are three different layers. You should be able to snap against features from another layer. This is also true for FeatureLayer (that inherits from GraphicsLayer). I included a checkbox that will turn off visibility of line layer, you will see that layers with visible=false are ignored in snapping.

    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid x:Name="LayoutRoot" Background="White">
  <Grid.Resources>
   <esri:Editor x:Key="MyRedEditor" Map="{Binding ElementName=MyMap}" LayerIDs="Red"/>
   <esri:Editor x:Key="MyEditor" Map="{Binding ElementName=MyMap}" />
   <esri:Editor x:Key="MyBlueEditor" Map="{Binding ElementName=MyMap}" LayerIDs="Blue"/>
   <esri:SimpleFillSymbol  x:Key="RedSymbol" Fill="Red"/>
   <esri:SimpleFillSymbol  x:Key="BlueSymbol" Fill="Blue"/>
   <esri:SimpleLineSymbol  x:Key="RedLineSymbol" Color="Red" Width="5"/>
  </Grid.Resources>
  <esri:Map x:Name="MyMap">
   <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer"/>
   <esri:GraphicsLayer ID="Red"/>
   <esri:GraphicsLayer ID="Blue"/>
   <esri:GraphicsLayer ID="Line" Visible="True">
   <esri:Graphic Symbol="{StaticResource RedLineSymbol}"  >
     <esri:Polyline >
      <esri:Polyline.Paths>
       <esri:PointCollection>
        <esri:MapPoint X="-118.169" Y="34.016" />
        <esri:MapPoint X="-104.941" Y="39.7072" />
        <esri:MapPoint X="-96.724" Y="32.732" />
        <esri:MapPoint X="-87.671" Y="41.804" />
        <esri:MapPoint X="-74" Y="40.68" />
       </esri:PointCollection>
      </esri:Polyline.Paths>
     </esri:Polyline>
    </esri:Graphic>
   </esri:GraphicsLayer>
  </esri:Map>
  <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
   <Button Content="AddBlue" DataContext="{StaticResource MyBlueEditor}" 
     Command="{Binding Add}" CommandParameter="{StaticResource BlueSymbol}"/>
   <Button Content="AddRed" DataContext="{StaticResource MyRedEditor}" 
     Command="{Binding Add}" CommandParameter="{StaticResource RedSymbol}"/>
   <Button Content="EditVertices" DataContext="{StaticResource MyEditor}" 
     Command="{Binding EditVertices}" />
   <CheckBox x:Name="LineVisible" DataContext="{Binding ElementName=MyMap, Path=Layers[Line]}" 
       Content="Line layer visiblity"  IsChecked="{Binding Visible, Mode=TwoWay}" />
  </StackPanel>
 </Grid>
0 Kudos
dotMorten_esri
Esri Notable Contributor
Snapping is enabled for any client side graphics you have. If you want to disable graphics for specific layers, you can temporarily disable hittesting on those layers. Ie. layer.IsHitTestVisible=false;

Regarding (3): You cannot snap to the feature you are drawing, since it would cause a self-intersection on the path/ring. This is by design. However if you are editing a multi-part geometry (ie holes etc), you can snap to the other parts of that geometry instance, but the "active" path/ring will still be ignored.
0 Kudos
JustinCornell
Occasional Contributor

By default, snap key is Ctrl-key and snap distance is 15. If you are using Draw or Editor, you overwrite the default in the same way
esri:Editor.SnapDistance="20" esri:Editor.SnapKey="S"


So how do I get to the Draw objects Editor?  I don't see a Editor property on that object.  In debug mode there are all the editor properties, however, they are not public.  Any help with this would be great!  If the Editor is not currently available can you put in a request to expose that object in the next release of the SL API?

Thanks!
0 Kudos