I am trying to add and display graphics to a map post load.
My code is able to add it to the graphicslayer, and it advises me that it has added it.
Yet it doesn't show it on the map.
I've just spent over a day on documentation and i cannot figure it out.
watchUtils.on(this.graphicsLayer, "graphics", "change", () => {console.log('Graphics added!');});
let polygon = {
type: "polygon", // autocasts as Polygon
rings: this.fromLATLONGtoXY(bigPolygon),
};
const simSymbol = {
type: "simple-fill",
color: [138, 43, 226, 0.5],
style: "solid",
outline: {
color: "blue",
width: 1
}
}
let graphic = new Graphic({
geometry: polygon as Polygon,
symbol: simSymbol
});
this.graphicsLayer.add(graphic);
After running the function i get a "Graphics added!" in console, but no graphic is shown on map.
Solved! Go to Solution.
Ended up fixing this by completely deleting the page code and starting from scratch. Essentially copy and pasting into another file and running it from that file.
It worked then, there must have been something funny going on in the cache that cause the issue.
You might want to post more code to give us a better context in order to see if we can help. Also, have you tried removing the 'as Polygon' from line 20? I have a very simple test file and it does not use that syntax.
Removing polygon wasn't it.
There is really not much more code other than a bigPolygon that has series of LatLng that get converted to XY coordinate using the webMercatorUtils.lngLatToXY. The out put for that is correct.
Is the spatial reference correct?
No changes to spatial reference, they are same
Ended up fixing this by completely deleting the page code and starting from scratch. Essentially copy and pasting into another file and running it from that file.
It worked then, there must have been something funny going on in the cache that cause the issue.