Hi, previously I was using the undocumented property (_activateCreateTool) with the Sketch widgit, which was working fine. I am now in the process of migrating to v4.32+ and using the new components. The previous undocumented _activeCreateTool is no longer supported, so I was wondering how to accomplish the same thing with the new Sketch component?
Solved! Go to Solution.
It's hard to understand what you want to do, but I think you are trying to programatically activate a drawing tool.
You can do that with a .create() function
const arcgisSketch = document.querySelector("arcgis-sketch");
arcgisSketch.addEventListener("arcgisReady", (event) => {
setTimeout(()=> {
// what you used before
// arcgisSketch._store.widget._activateCreateTool("polygon")
// what I think you should use now
arcgisSketch.create("polygon")
}, 2000)
});
Here is a working demo with your old method, and a new one. Both activate the polygon button in the UI just the same. https://codepen.io/edvinasHB/pen/pvoXpNz
There is a method available on the sketch widget which lets you initiate the creation tool with a specfic swt of options. Does this fit what you are trying to do? https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html#create
In order to use it, you would have to get reference to the DOM element, and then call the method upon it.
I know about that, and I am doing that already. But what I actually need is to set which of the available tools to set as currently active in my code. So when the user wants to create a Polygon on the map the polygon tool is selected rather than the default select tool.
I'm still a bit confused about what exactly you are trying to do, but if you need more control/information about the inner workings of the sketch tool I would look at the information available in the sketchviewmodel. This has all of the internal logic of the widget.
I am not using the widgit I am trying upgrade my code to use the new sketch component.
Previously the widgit had an undocumented property called _activateCreateTool which did exactly what I wanted.
This property does not exist in the new sketch component, so I am unable to use it anymore. So all I want to know is how to get the same functionality that was supplied by the _activateCreateTool property in the widgit in the new component.
I don’t know myself how that particular internal method works / what it did. But If you aren’t using the widget but need sketch functionality then you should be instantiating a sketch view model to handle the interaction. If you are using the new sketch component, you should be going through its exposed methods, or its own sketch view model property to make changes.
my reading from the internal method name is that it is just activating one of the draw tools?
It's hard to understand what you want to do, but I think you are trying to programatically activate a drawing tool.
You can do that with a .create() function
const arcgisSketch = document.querySelector("arcgis-sketch");
arcgisSketch.addEventListener("arcgisReady", (event) => {
setTimeout(()=> {
// what you used before
// arcgisSketch._store.widget._activateCreateTool("polygon")
// what I think you should use now
arcgisSketch.create("polygon")
}, 2000)
});
Here is a working demo with your old method, and a new one. Both activate the polygon button in the UI just the same. https://codepen.io/edvinasHB/pen/pvoXpNz
This isn't something that is exposed as a public API, so it's not available on the component. You can submit an enhancement request and we can take a look at adding it.