how to stop move when reshape graphic with sketchviewModel?

366
3
Jump to solution
10-15-2019 07:31 PM
Highlighted
by
New Contributor II

i  want to  remove    move event  when reshape   graphic  with  SketchViewModel ,how to do?

view.when(function() {
// Query all buffer features from the school buffers featurelayer
bufferLayer.queryFeatures().then(function(results) {
buffers = results.features[0].geometry;
});

// Add the boundary polygon and new lot polygon graphics
addGraphics();

// Create a new instance of sketchViewModel
sketchViewModel = new SketchViewModel({
view: view,
layer: graphicsLayer,
updateOnGraphicClick: true,
defaultUpdateOptions: {
// set the default options for the update operations
toggleToolOnClick: false // only reshape operation will be enabled
}
});

// Listen to sketchViewModel's update event to do
// graphic reshape or move validation
sketchViewModel.on(["update", "undo", "redo"], onGraphicUpdate);
});

function onGraphicUpdate(event) {
// get the graphic as it is being updated
const graphic = event.graphics[0];
// check if the graphic is intersecting school buffers or is
// still contained by the boundary polygon as the graphic is being updated
intersects = geometryEngine.intersects(buffers, graphic.geometry);
contains = geometryEngine.contains(boundaryPolygon, graphic.geometry);

// change the graphic symbol to valid or invalid symbol
// depending the graphic location
graphic.symbol =
intersects || !contains ? invalidSymbol : validSymbol;

// check if the update event's the toolEventInfo.type is move-stop or 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 === "reshape-stop"
) {
if (contains && !intersects) {
//sketchViewModel.complete();
}
} else if (event.state === "cancel" || event.state === "complete") {
// graphic moving or reshaping has been completed or cancelled
// if the graphic is in an illegal spot, call sketchviewmodel's update method again
// giving user a chance to correct the location of the graphic
if (!contains || intersects) {
sketchViewModel.update([graphic], { tool: "reshape" });
}
} else if (
event.toolEventInfo &&
event.toolEventInfo.type === "move-start"
) {
// How to stop move here?
return;
} else if (
event.toolEventInfo &&
event.toolEventInfo.type === "move"
) {

return;
} else if (
event.toolEventInfo &&
event.toolEventInfo.type === "move-stop"
) {

return;
}
}
Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Contributor

Hi there, 

You can prevent the move operation for graphics by the cancel method on Sketch or SketchViewModel as shown below.

if (event.toolEventInfo && event.toolEventInfo.type.includes("move")){
sketch.cancel();
}

View solution in original post

3 Replies
Highlighted
Esri Contributor

Hi there, 

You can prevent the move operation for graphics by the cancel method on Sketch or SketchViewModel as shown below.

if (event.toolEventInfo && event.toolEventInfo.type.includes("move")){
sketch.cancel();
}

View solution in original post

Highlighted
by
New Contributor II

Thank you! it  works fine!

by the way,how to formate the   javascript code in commutiy question like your reply code.

I'am newer for the commutiy

Reply
0 Kudos
Highlighted
MVP Honored Contributor

You can format your code using Syntax Highlighter. See this discussion for more information: https://community.esri.com/docs/DOC-8587-updated-content-text-editor 

Note that this highlighter is not available when responding to a message through your Inbox.

Also, when your question is answered, click the "Mark Correct" button on that post

Reply
0 Kudos