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.