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

1606
2
Jump to solution
09-25-2017 03:36 PM
DevonCanady
New Contributor II

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;
}
0 Kudos
1 Solution

Accepted Solutions
ThomasSolow
Occasional Contributor III

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.

View solution in original post

2 Replies
ThomasSolow
Occasional Contributor III

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.

DevonCanady
New Contributor II

Looks like I didn't need to be doing a hit test for the update action type. Thanks!

0 Kudos