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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 17, 2017 at 22:33
2
  • 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). Commented Aug 18, 2017 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. Commented Aug 18, 2017 at 14:08

1 Answer 1

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

answered Aug 18, 2017 at 22:47
5
  • 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? Commented Aug 21, 2017 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). Commented Aug 22, 2017 at 0:04
  • But if I'm using the API the autogeneralization is already turned off, isn't it? Commented Aug 22, 2017 at 6:01
  • No, auto-generalization is ON by default (unless you're editing). Commented Aug 22, 2017 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. Commented Aug 30, 2017 at 20:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.