Hi,
I'm trying to add Sketch widget to my map as well as add some polygons based on info previously submitted.
When adding the widget an error is shown in the console and widget is not visible. Used a lot of time to figure it out without any luck. Hopefully someone can help me.
Here is the error message:
And here is my complete code:
require([
"esri/widgets/Sketch",
"esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/layers/GraphicsLayer"
], (Sketch, Map, MapView, Graphic, GraphicsLayer) => {
let graphicsLayer = new GraphicsLayer();
var jsonString = "${sys_json_object}"; // server-side directive to import json
var jsonObj = JSON.parse(jsonString);
var map = new Map({
basemap: "streets-navigation-vector",
layers: [graphicsLayer]
});
var view = new MapView({
container: "viewDiv",
map: map,
zoom: jsonObj.zoom,
center: [jsonObj.center.longitude, jsonObj.center.latitude]
});
view.when(() => {
let sketch = new Sketch({
layer: graphicsLayer,
view: view
});
view.ui.add(sketch, 'top-right');
var polygon = {
type: "polygon",
rings: jsonObj.rings,
spatialReference: jsonObj.spatialReference
};
var fillSymbol = {
type: "simple-fill",
color: [227, 139, 79, 0.8], // Orange, semi-transparent
outline: {
color: [255, 255, 255],
width: 1
}
};
var polygonGraphic = new Graphic({
geometry: polygon,
symbol: fillSymbol
});
graphicsLayer.graphics.add(polygonGraphic);
});
});
If I comment out line 34, the polygon is drawn correctly, but obviously no widget shown.
Hello, maybe try adding your polygonGraphic before creating your Sketch
Can post your source where the viewDiv is created. The problem dont seems like to be with your Sketch.