Select to view content in your preferred language

Polygon graphics grouping issue

725
2
10-31-2017 06:26 AM
YohanBienvenue
Frequent Contributor

ArcGIS API for Javascript 3.22

When adding graphics to a GraphicsLayer, I noticed that all my Graphics using a SimpleFillSymbol (i.e. polygon geometry) are bunched together in a single SVG <g> element. My other graphics using SimpleLineSymbol (i.e. polyline geometry) or TextSymbol are added separately in their own <path> and <text> elements, respectively.

I'm not sure if the API does intentionally or not, maybe for some sort of performance reason. If so, I'm wondering if this can be avoided because it really messes with my graphics ordering. In our webapp users should be able to edit and manipulate graphics ordering, but this <path> grouping into a single <g> seems to make it impossible, since all graphics using SimpleFillSymbol will have their own order v.s. all other Graphics.

See below screenshot for example, where I drew 3 shapes along with a bunch of text measures for those shapes. You can see that all the TextSymbol are drawn above all the shapes, regardless of the order I added them to the layer.

Any way to add them as simple <path> elements like the Graphics using SimpleLineSymbol?

Thanks,

Yohan

0 Kudos
2 Replies
DavidBlanchard
Esri Contributor

To the best of my knowledge, individual graphics within a graphics layer do not provide any guarantees as to how they will be ordered. The fact that graphics using SimpleLineSymbols are layered in the order in which they are added is most likely just a coincidence of the way the API was written and could change with any new version.

If you need a specific ordering, you should look a creating multiple Graphics Layers and ordering those.

0 Kudos
YohanBienvenue
Frequent Contributor

Well, it's worse then just a guarantee of order, because even if I tried to handle the order myself with graphic.getDojoShape() move functions, it won't work since the polygon graphics are in their own subgroup v.s. the other types. Also I tried to cheat and move the SVG polygon graphics manually out of this subgroup, but the API just puts them back in at the next GraphicsLayer refresh. The fact that the API forces this polygon subgroup makes it impossible for me to handle the ordering myself using a single GraphicsLayer.

So yeah, as you suggest I guess the only alternative is using one graphic per GraphicsLayer, the Leaflet way. Although I don't think it will be possible to do such a refactoring in our webapp at this point. For now the users just won't be able to control the ordering for individual polygons v.s. other types.

Thanks David

0 Kudos