3

I'm using snapping in a web map for a move/rotate custom tool. According to the API documentation the default option is to set all feature and graphics layers in the map to be target snapping layers.

The snapping seems to work fine since the user is getting the X symbol over the vertices of the features when the pointer is close with the CTRL key pressed.

However when I capture the point coordinates on click, the value is not identical to the feature's vertex coordinate as I expected. There's a small difference and some variance in multiple clicks for the same vertex. For the tool I really need to have the same exact coordinate of the feature so the operation will no generate gaps in the layer.

I'm using ArcGIS API for JavaScript 3.7 and the drawEnd event (using esri.toolbars.Draw.POINT) to get the coordinate.

Is this the expected behaviour for the snapping (an approximation instead of the exact coordinate of the feature) ? Or is there a way to get what I want.

  • Makes me wonder if it's using the map coordinate of the pixel where it snapped to ... if you zoom out, is the error greater? 3.7 is pretty old. In the math of version numbers 3.20 > 3.7 (13 releases greater). – Kirk Kuykendall Aug 18 '17 at 2:19
  • The error doesn't seem to be related to the zoom level. Sometimes I get a better value in a greater level or sometimes in a lesser level of zoom. – ednincer Aug 18 '17 at 14:08
1

This is the expected behavior in this case. You're snapping to the features as drawn on the map. And in general the features are auto-generalized to be appropriate for whatever scale you're working on.

If you're editing with the API, this auto-generalization is turned off automatically.

In your case, you probably want to set setAutoGeneralize to false. It will impact your performance a little, but you'll get more accurate geometry coordinates.

See https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#setautogeneralize

  • Thanks for the information. In this case I'm not yet editing, just getting the coordinate of the snapping point (on click). So according to your answer if I'm using the API, the auto-generalization is already turned off and I'm getting the more accurate geometry coordinates. So it's not possible to get the real coordinate of the feature, that's right? – ednincer Aug 21 '17 at 20:08
  • Not sure I understand your third sentence there. Once you turn off the autogeneralization, you should get the original feature (and it's coordinates). – Bjorn Svensson Aug 22 '17 at 0:04
  • But if I'm using the API the autogeneralization is already turned off, isn't it? – ednincer Aug 22 '17 at 6:01
  • No, auto-generalization is ON by default (unless you're editing). – Bjorn Svensson Aug 22 '17 at 6:34
  • I set the autogeneralization to false for the layer but I'm still getting aproximate values for the coordinates in the drawEnd event. – ednincer Aug 30 '17 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.