SnapManager fails to complete snap in Javascript
I am having a problem similar to the one Tyler described but the previous post did not solve my problem. I have a custom widget with a click event that uses the snapping manager to guide the user to place a point along a road. The road is in a feature service and I am using the draw toolbar to create the point. Snapping at first seems to be working great to the point of creating the little blue X that is constrained to follow the road, however, when the user actually clicks the point will be created at the actual click point and not where the blue X is showing.
How can I make the snapped point graphic actually be created on the line where the blue X seems to indicate it will be?
Right now I am adding the featurelayer to the map every time the user clicks, which is not practical in the long run, but I am just trying to get it to work.
Thank you for any help in solving this problem.
myfunction: function (evt) {
var parcelsLayer = new FeatureLayer(
"http://myurl/MapServer/0",
{
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
this.map.addLayer(parcelsLayer);
var snapManager = this.map.enableSnapping({
tolerance: 20,
alwaysSnap: true
});
var layerInfos = [{
layer: parcelsLayer
}];
snapManager.setLayerInfos(layerInfos);
var tb;
tb = new Draw(this.map);
tb.activate(Draw["POINT"]);
var line = new SimpleLineSymbol();
line.setColor(new Color([168, 0, 0, 1]));
line.setWidth(2);
var marker = new SimpleMarkerSymbol();
marker.setOutline(line);
marker.setStyle(SimpleMarkerSymbol.STYLE_X);
var graphic = new Graphic(evt.mapPoint, marker);
this.map.graphics.add(graphic);
}
Finally solved the problem. It turned out the error function tagged on at the end disrupted everything else. I removed it and the point and value started working fine. Thank you for helping me work through this!
var deferred = this.map.snappingManager.getSnappingPoint(evt.screenPoint);
var sms = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 12,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([70, 0, 130, 1]), 1), new Color([70, 0, 130, 1]));
deferred.then(lang.hitch(this, function(value){
var point;
if (value !== undefined){
point = value;
} else {
point = evt.mapPoint;
}
var graphic = new Graphic(point, sms);
this.map.graphics.add(graphic);
},
/* function(error){
console.log('Error');
} */
));