maplibre-native
maplibre-native copied to clipboard
Implementation of multi-sprites in mbgl-core
In order to solve https://github.com/maplibre/maplibre-native/issues/641. Implemented in the same way as for Maplibre GL JS.
In detail
In Style JSON, sprite
property can now be a string or an array. If this is an array that must contains object(s) with id and urls.
SpriteLoader
can now manage multiple sprites in parallel.
Style::Impl
now stores the information about how much sprites are loaded. Included a method areSpritesLoaded()
to be adequate with the old boolean property that serves the same goal.
When using a string as sprite, that creates internally a Sprite object with id default and the url. When using an array, there is a parsing to create adequate Sprite objects.
Usage
In images identifiers you need to prepend the sprite id to the image. Example :
"icon-image": "hiking:myimage",
That leads to the image identifier 'myimage' for the sprite object with id 'hiking'. If id of your sprite is 'default', you don't need to prepend it :
"icon-image": "myimage",
Tip: If your icon-image is property driven, you can use this instead :
"icon-image": [
"concat",
"hiking:",
[
"get",
"myproperty"
]
],
I resolved some of the issues, but one big issue still exist. In the current commit version you can have multiple sprites with the same id. MapLibre GL JS doesn't allow that and I need to handle this case + unit tests.
I implemented checks about id uniqueness.
I added also 2 style parsing tests sprites-missing-fields
and sprites-not-same-ids
within the style_parser
test directory to check attributes of sprites and id uniqueness.
4 additional tests (SpriteAsArrayEmpty
,SpriteAsArraySingle
, SpriteAsArrayMultiple
and SpriteAsString
) added to test compatibility with array of sprite or single sprite url inside style_parser.test.cpp
.
Seems to be good for me. Tell me if something is wrong.
Bloaty Results 🐋
Compared to main
FILE SIZE VM SIZE
-------------- --------------
+0.3% +429Ki +0.3% +81.4Ki TOTAL
Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-1858-compared-to-main.txt
Compared to d38709084a9865fe0bb8300aec70ebf8243b3d43 (legacy)
FILE SIZE VM SIZE
-------------- --------------
+18% +21.4Mi +399% +23.8Mi TOTAL
Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-1858-compared-to-legacy.txt
@geolives Will do a manual test today!
Since this feature already exists in MapLibre GL JS if I remember correctly, can we copy-paste the render test from there?
@wipfli Yes I think so. @geolives Let me know if you want me to take a look at this, because I have been meaning to do that anyway.
It's probably better if you can do it, as my understandings about the render tests are minor. Thanks :)
Bloaty Results (iOS) 🐋
Compared to main
FILE SIZE VM SIZE
-------------- --------------
+0.2% +34.5Ki +0.2% +32.0Ki TOTAL
Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results-ios/pr-1858-compared-to-main.txt
iOS render test passes locally.
On CI it complains about missing metrics.