SnappingManager without draw/edit toolbars

562
1
04-18-2014 02:10 PM
KyleEinspahr
New Contributor
I am using the ArcGIS JavaScript API v. 3.7.
I am trying snap to geometries in a certain layer as the mouse moves on the map.  I am trying to do so without activating the Edit Toolbar or the Draw Toolbar.  My call to map.snappingManager.getSnappingPoint() returns a point but it is the same screen point as the screen point passed in.

Any ideas to help me?

Here is my code for map ??? on-load event:

self.mapVm.map.snappingManager.destroy();
self.mapVm.map.snappingManager = new snappingManager({ map: self.mapVm.map, layerInfos: [{ layer: self.parentVm.fieldEditLayer, snapToEdge: false }], tolerance: 50 });

Here is my code for map ??? mouse-move event:
if (evt.ctrlKey) {
                            // SnapPoint
                            var currentScreenPoint = self.mapVm.map.toScreen(evt.mapPoint);
                            self.mapVm.map.snappingManager.getSnappingPoint(currentScreenPoint).then(function (value) {
                                    if (value !== undefined) {
                                        snapPoint = value;
                                        snapPoint.setSpatialReference(new spatialReference({ wkid: 102100 }));

                                        var snapScreenPoint = self.mapVm.map.toScreen(snapPoint);
                                        var xDiff = Math.abs(currentScreenPoint.x - snapScreenPoint.x);
                                        var yDiff = Math.abs(currentScreenPoint.y - snapScreenPoint.y);
                                        if (xDiff > 4 || yDiff > 4) {
                                            snapPointGraphic = new graphic(value, polygonSnapSymbol);
                                            self.mapVm.map.graphics.add(snapPointGraphic);
                                            self.mapVm.map.graphics.redraw();
                                        }
                                    } else {
                                        if (snapPointGraphic) {
                                            self.mapVm.map.graphics.remove(snapPointGraphic);
                                            snapPointGraphic = undefined;
                                        }
                                    }
                                },
                                function() {
                                    if (snapPointGraphic) {
                                        self.mapVm.map.graphics.remove(snapPointGraphic);
                                        snapPointGraphic = undefined;
                                    }
                                });
                        } else {
                            if (snapPointGraphic) {
                                self.mapVm.map.graphics.remove(snapPointGraphic);
                                snapPointGraphic = undefined;
                            }
                        }

Any hints would be appreciated.
1 Reply
AndyWhitaker1
New Contributor III

I also want to snap to a feature layer (of polylines) while the user is moving their mouse around.  I want to do this while the Directions widget (ArcGIS for JS 3.32) has the map click active for selecting stops for a route.  I'll snap to the route linework.  @keinspahr Did you ever find an answer for this?  I'm going to dive into this one; I've been avoiding it for a while.

0 Kudos