I've encountered some pretty strange behavior trying to adjust the viewModel of the Sketch Widget.
Following this tutorial for the SketchViewModel Styler, I've attempted to add in a custom polygonSymbol using the SketchViewModel. It works...
...to a point. It works fine with the rectangle and circle tools, but it will not work for the polygon tool until the sketch is finished, which is ultimately the what I want to target.
I can confirm this is happening in different versions of the API (4.19, 4.23), but I'm only seeing it in projects that use Esri Loader. I can create a new project that does not call the Sketch Widget or SketchViewModel via Esri Loader and it works fine. The code below is what I'm using for the sketch widget's viewModel. You can take the exact same code, plug it into the live demo at https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=sketch-geometries , and everything works as expected. The only reason I can see why this doesn't work as expected with the freehand polygon tool the way that I'm doing it is due to the presence of Esri Loader. Does anyone have a possible work around for this issue?
let sketchWidget = new Sketch({
view,
layer: sketchLayer,
creationMode: "single",
availableCreateTools,
viewModel: new SketchViewModel({
view: view,
layer: sketchLayer,
polygonSymbol: {
type: "simple-fill",
style: "cross",
color: "#EFC8B1",
outline: {
width: 3,
style: "solid",
color: "red",
},
},
}),
});
So, I found a work around to this. Apparently the polygon tool does not use the polygonSymbol for symbology, but the polyLINESymbol when using ESRI loader. No clue why this is or how to target the inside patterning, but being able to modify the lines will suffice.