Hey guys, im fairly new to the javascript API.
I made a viewer where the user is able to draw and edit shapes and text. I am trying to figure out how to remove a single graphic that is selected.
the code below removes all graphics regardless if its selected or not. anyideas on what Im doing wrong?
map.graphics.on("click", function(evt){
//window.alert("click caught");
event.stop(evt);
editingEnabled = true
if (evt.ctrlKey === true || evt.metaKey === true) { //delete feature if ctrl key is depressed
window.alert("delete caught");
map.graphics.clear(); // removes all graphics as opposed to only selected graphic
currentLayer = this;
editToolbar.deactivate();
editingEnabled=false;
}
});
//FIXED CODE (thanks to tim witt) - just in case anyone came accross the same issue.
map.graphics.on("click", function(evt){
//window.alert("click caught");
event.stop(evt);
editingEnabled = true
if (evt.ctrlKey === true || evt.metaKey === true) { //delete feature if ctrl key is depressed
window.alert("delete caught");
map.graphics.remove(evt.graphic); // this removes single graphic
currentLayer = this;
editToolbar.deactivate();
editingEnabled=false;
}
});
Solved! Go to Solution.
Hey Ibrahim,
I was trying to do the same, when I eventually ended up going in a totally new direction. Check out the advanced draw tool I have created and feel free to use it: Advanced Draw - JSFiddle
I use the right-mouse click to delete graphics (and create a whole menu).
Let me know what you think!
Tim
Hey Ibrahim,
I was trying to do the same, when I eventually ended up going in a totally new direction. Check out the advanced draw tool I have created and feel free to use it: Advanced Draw - JSFiddle
I use the right-mouse click to delete graphics (and create a whole menu).
Let me know what you think!
Tim
Ill take a look, thanks a lot!
edit - thanks again, this is what I was looking for. Should help me a great deal.
No problem, glad I could help