feat: added support for GeometryCollections#1384
feat: added support for GeometryCollections#1384shaietz wants to merge 5 commits intoopenlayers:mainfrom
Conversation
There was a problem hiding this comment.
Thanks for your work on this, @shaietz. The starting point would be to create a geojson with valid GeometryCollections, preferably one with two simple geometries and one with a nested geometry collection and a simple geometry.
A test would also be crucial to make problems with the added code obvious.
I added comments for each of the problems I see from looking at the code. Please address them. Let me know when you have questions.
| } | ||
| } | ||
|
|
||
| return styles.length > 0 ? styles : undefined; |
There was a problem hiding this comment.
This won't work. Styles are reused across styleFunction() calls, so you need to clone them, and each style needs to be configured with the geometry of the geometry collection.
There was a problem hiding this comment.
i'm not sure i understand what you mean, anyways i have removed the push of the substyle to the styles array because it was not necessary, so is this still relevant?
There was a problem hiding this comment.
Yes, what I wrote is still relevant. Also regarding a test case with nested geometry collections.
There was a problem hiding this comment.
hi, sorry for the long break, i ended up not needing this feature which is the reason i opened the issue in the first place, however i have some free time now and want to finish this up.
regarding this:
This won't work. Styles are reused across styleFunction() calls, so you need to clone them, and each style needs to be configured with the geometry of the geometry collection.
i don't understand why this won't work and what needs to be done in order for it to work, since i call the styleFunction() recursively for each sub geometry shouldn't it handle handle adding the individual styles to the styles array correctly?
also, i added a nested geometry collection to the geojson-inline.json and it seems to be working correctly, should i also add a test to stylefunction.test.js?
thanks for your patience
There was a problem hiding this comment.
The reason why it appears to work is because OpenLayers takes care of correct rendering of all points of the GeometryCollection, and the last style will be used. With geometry collections with mixed types, that won't work so well.
Honestly, I cannot think of a way to deal with this properly. Maybe taking a look at how MapLibre deals with GeometryCollection geometries from GeoJSON sources could make sense.
Issue #1383 add support for GeometryCollection Feature type
modified stylefunction to handle GeometryCollections by calling the stylefunction on each geometry individually