Select to view content in your preferred language

how to stop move when reshape graphic with sketchviewModel?

2521
5
Jump to solution
10-15-2019 07:31 PM
yanli
by
Emerging Contributor

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

Accepted Solutions
UndralBatsukh
Esri Regular 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

5 Replies
UndralBatsukh
Esri Regular 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();
}
yanli
by
Emerging Contributor

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

0 Kudos
KenBuja
MVP Esteemed 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

0 Kudos
JeremySwagger
Deactivated User

I would actually recommend using move-start to completely keep the geometry in place. Otherwise with move, the user can actually move the geometry slightly. move is triggered right after the first action has been made. move-start allows us to interrupt any move action before it happens. It is a small difference, I know, but it may prevent geometry mismatches downstream and maintain shape integrity.

Robert_van_Gilst
Occasional Contributor

This seems to be broken in version 2.24 I get the following error when calling sketch.cancel() when type is "move-start"

Reshape.js:formatted:479 

Uncaught TypeError: Cannot read properties of null (reading 'data')
    at d._onGraphicMoveStartCallback (Reshape.js:formatted:479:58)
    at Object.onGraphicMoveStart (Reshape.js:formatted:426:49)
    at f._dragHandler (VM6316 GraphicMover.js:15:308)
    at VM6316 GraphicMover.js:8:9
    at q._callback (VM6024:2298:475)
    at k._handleEvent (VM6024:2289:385)
    at Object.eventCallback (VM6024:2286:289)
    at z._continuePropagation (VM6024:2273:181)
    at z._doNewPropagation (VM6024:2272:223)
    at z._emitInputEvent (VM6024:2272:6)
0 Kudos