I'm trying to click a feature to select it and then drag it to a new location. Currently the location of the graphic only updates when I let go even though I have the coords updating as it moves (when evt.action == "update"
). I'm wondering how to make the graphic follow the cursor as I drag it.
view.on("drag", function(evt) {
switch(evt.action) {
case "update":
evt.stopPropagation(); //to stop map panning, same issue with this or not
var screenPoint = { x: evt.x, y: evt.y };
view.hitTest(screenPoint).then(function(response) {
updateSelectedFeatureGraphic(view.toMap(screenPoint));
});
break;
}
});
function updateSelectedFeatureGraphic(geometry) {
if (selectedFeatureGraphic)
removeSelectedFeatureGraphic();
selectedFeatureGraphic = new Graphic({
geometry: geometry,
symbol: new SimpleMarkerSymbol({
style: "circle",
color: "#80ffff",
size: "12px", outline: {
color: "#80ffff",
width: 1
}
})
});
view.graphics.add(selectedFeatureGraphic);
}
function removeSelectedFeatureGraphic() {
view.graphics.remove(selectedFeatureGraphic);
selectedFeatureGraphic = null;
}
Solved! Go to Solution.
Here's a sample that does this: JS Bin - Collaborative JavaScript Debugging
Only works on point graphics. Graphics will other geometries will be more involved but also possible with a little work.
Here's a sample that does this: JS Bin - Collaborative JavaScript Debugging
Only works on point graphics. Graphics will other geometries will be more involved but also possible with a little work.
Looks like I didn't need to be doing a hit test for the update action type. Thanks!