AnsweredAssumed Answered

How to update graphic location as you drag (ArcJSAPI 4.4)

Question asked by devonc1301 on Sep 25, 2017
Latest reply on Sep 27, 2017 by devonc1301

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;
}

Outcomes