maplibre-native icon indicating copy to clipboard operation
maplibre-native copied to clipboard

Implementation of multi-sprites in mbgl-core

Open geolives-contact opened this issue 1 year ago • 9 comments

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"
          ]
        ],

geolives-contact avatar Nov 13 '23 10:11 geolives-contact

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.

geolives-contact avatar Nov 23 '23 14:11 geolives-contact

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.

geolives-contact avatar Nov 27 '23 15:11 geolives-contact

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

github-actions[bot] avatar Nov 27 '23 15:11 github-actions[bot]

@geolives Will do a manual test today!

louwers avatar Dec 04 '23 12:12 louwers

Since this feature already exists in MapLibre GL JS if I remember correctly, can we copy-paste the render test from there?

wipfli avatar Dec 11 '23 09:12 wipfli

@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.

louwers avatar Dec 11 '23 13:12 louwers

It's probably better if you can do it, as my understandings about the render tests are minor. Thanks :)

geolives-contact avatar Dec 11 '23 13:12 geolives-contact

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

github-actions[bot] avatar Feb 15 '24 19:02 github-actions[bot]

iOS render test passes locally.

On CI it complains about missing metrics.

louwers avatar Feb 17 '24 16:02 louwers