ESRI JS Sketch Widget: How to disable at certain scales

415 views Asked by At

I am trying to figure out a way to disable the Sketch widget at certain scales.

Currently I have working code that will completely add or remove the widget, but that does not meet my requirements.

I see that the Sketch widget has a "state" property, but it is read only and I can find no methods or other properties to affect the state.

I need to be able to disable the entire widget or at least disable all the draw/editing tools.

2

There are 2 answers

0
cabesuon On

One way to disable the buttons of the widget is by setting pointer-events style property to none.

So, let say your widget variable is sketch, then

const buttons = sketch.container.getElementsByTagName("button");
for (let i = 0; i < buttons.length; i++) {
  buttons[i].classList.add("no-click");
}

where no-click is just,

.no-click {
  pointer-events: none !important;
}

I am not sure of your implementation, but I think you can get an idea with this snippets.

It is important that the widget is loaded before calling getElementsByTagName, if not you will get 0 result.

0
vivek shukla On

You can't disable the sketch tool since already user has started drawing the geometry on map.

You can control the map Zoom behavior once user has activated the draw tool on Map; I mean don't allow user to zoom out from a certain map scale (if tool is active).