Open dragonfist453 opened 2 years ago
See also #2434 for a similar request, with a lengthy discussion. The problem is that GeoJSON is converted into vector tiles for processing & rendering, and the vector tile specification does not support nested properties — fixing this is a pretty difficult architectural problem, more than it appears at first.
Motivation
I was using a layer which has a property in the properties called "layer_properties" that contains an object containing further detailed properties unique to the layer type. For example, we have:
Using the existing API, there is no easy way to access jet_wind_level or jet_wind_speed inside layer_properties as get will give me layer_properties as a string like "{jet_wind_level: 290, jet_wind_speed: 90}". This does not help me much and I need to implement an algorithm in styles API that slices the string to get me the value given attribute.
A lot of layers for weather have these sort of composite objects not necessarily named "layer_properties" that may need to be accessed.
Design
It helps a lot for data that could be provided this way and it will make it a lot more powerful. There should be no drawbacks as it just makes the styles expressions API work for more versatile use-cases.
Mock-Up
It could be tried as a ['get-composite', 'jet_wind_level', 'layer_properties'] (as per above given example) to provide the string "290" by accessing the object conveniently. This should ease up and make this wonderful API much more convenient to use.
Alternative followed for this problem
For others facing this problem, I had to implement a simple slicing function that looks complex like so:
Using this as
getAttrFromCompositeObject('jet_wind_speed')
would get me the data from layer_properties but this only works for text-field or icon-image or for any place that takes a value type. When a string is asked, like in a "formatted" type, it will not work and that does lead to problems. If this could be completely solved by adding a feature to access composite objects, it would make the API very powerful for anybody using it