Hi
My polygon vertices remain when i remove graphics.
My polygons come from db, as well i created new polygons on the spot.
While one of many polygon coming from db always stay editable and one of new polygon created always remain editablle.
the one editable polygon always leave its vertices on removal, even when i used sketchViewModel.complete();
I tried alot , but didn't get it how to get it fixed.
Any help will be appriceable.
//Clear All method
jQuery('#main').on('click', '.clear_all', function(){
//clear all graphics added to graphics layer
clearAll=true;
sketchViewModel.complete();
graphicsLayer.removeAll();
});
//Double click to delete boundaries
view.on("double-click", function(event){
view.hitTest(event).then(function(response) {
var results = response.results;
sketchViewModel.complete();
results.forEach(function(result) {
if(result.graphic.geometry.type==='polygon'&&result.graphic.layer === sketchViewModel.layer && result.graphic.attributes && result.graphic.attributes.newDevelopment){
graphicsLayer.remove(result.graphic);
}
});
});
});
For making them editable, i use this code below
view.when(function() {
..
..
// Listen to sketchViewModel's update event to do graphic reshape validation
sketchViewModel.on(["update", "undo", "redo"], onGraphicUpdate);
//now the graphic has been added to the graphics layer and the SketchviewMdoel is created
//to show it as editable when page load
sketchViewModel.update([newDevelopmentGraphic], {tool: "reshape"});
});//End View.When
function onGraphicUpdate(event) {
// get the graphic as it is being updated
const graphic = event.graphics[0];
// check if the update event's the toolEventInfo.type is move then stop move event
if (event.toolEventInfo && event.toolEventInfo.type.includes("move")){
sketchViewModel.cancel();
markersketchViewModel.cancel();
}
// If toolEventInfo.type is reshape-stop then it means user finished moving or reshaping the graphic, call complete method. This will change update event state to complete and we will check the validity of the graphic location.
if (
event.toolEventInfo &&
(event.toolEventInfo.type === "move-stop" ||
event.toolEventInfo.type === "reshape-stop")
) {
sketchViewModel.complete();
markersketchViewModel.complete();
} else if (event.state === "cancel" || event.state === "complete") {
//check if the graphics are done being reshaped, printout updated graphic's geometry and reshape stage.
// graphic reshaping has been completed or cancelled
graphic.attributes.state = "updated";
sketchViewModel.update([graphic], { tool: "reshape" });
}
else{
graphic.symbol = validSymbol;
}
}//End OnGraphicsUpdate
// This function is called when a user clicks on the view.
function setUpGraphicClickHandler() {
view.on("click", function(event) {
view.hitTest(event).then(function(response) {
var results = response.results;
if(results.length === 0){
sketchViewModel.complete();
markersketchViewModel.complete();
}
// Check if the new development graphic and temp graphics with attribute named newDevelopment was clicked and pass
// the graphic to sketchViewModel.update() with reshape tool.
results.forEach(function(result) {
if (
result.graphic.layer === sketchViewModel.layer &&
result.graphic.attributes &&
result.graphic.attributes.newDevelopment
) {
sketchViewModel.update([result.graphic], { tool: "reshape" });
}
else if(sketchViewModel.state !== 'active'){
sketchViewModel.cancel();
view.popup.open({features: [result.graphic], location: result.graphic.geometry});
}
});
});
});
}//End setUpGraphicClickHandler