Skip to content

Commit

Permalink
Implementation of multi-sprites in mbgl-core (#1858)
Browse files Browse the repository at this point in the history
Co-authored-by: Christophe Brasseur <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <[email protected]>
Co-authored-by: Bart Louwers <[email protected]>
  • Loading branch information
5 people authored Feb 27, 2024
1 parent 9e8837b commit f4c6fab
Show file tree
Hide file tree
Showing 39 changed files with 649 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
- name: Build RenderTest .ipa and .xctest for AWS Device Farm
run: |
set -e
bazel run --//:renderer=metal //platform/ios:xcodeproj
bazel run //platform/ios:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal"
build_dir="$(mktemp -d)"
xcodebuild build-for-testing -scheme RenderTest -project MapLibre.xcodeproj -derivedDataPath "$build_dir"
render_test_app_dir="$(dirname "$(find "$build_dir" -name RenderTestApp.app)")"
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ list(APPEND SRC_FILES
${PROJECT_SOURCE_DIR}/src/mbgl/style/collection.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/color_ramp_property_value.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/constant.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/sprite.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/coordinate.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/custom_geometry_source_options.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/filter.cpp
Expand Down Expand Up @@ -759,6 +760,8 @@ list(APPEND SRC_FILES
${PROJECT_SOURCE_DIR}/src/mbgl/style/expression/within.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/filter.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/image.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/sprite.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/sprite.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/image_impl.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/image_impl.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layer.cpp
Expand Down
4 changes: 4 additions & 0 deletions bazel/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ MLN_CORE_SOURCE = [
"src/mbgl/style/conversion/stringify.hpp",
"src/mbgl/style/conversion/tileset.cpp",
"src/mbgl/style/conversion/transition_options.cpp",
"src/mbgl/style/conversion/sprite.hpp",
"src/mbgl/style/conversion/sprite.cpp",
"src/mbgl/style/custom_tile_loader.cpp",
"src/mbgl/style/custom_tile_loader.hpp",
"src/mbgl/style/expression/assertion.cpp",
Expand Down Expand Up @@ -437,6 +439,8 @@ MLN_CORE_SOURCE = [
"src/mbgl/style/expression/value.cpp",
"src/mbgl/style/expression/within.cpp",
"src/mbgl/style/filter.cpp",
"src/mbgl/style/sprite.hpp",
"src/mbgl/style/sprite.cpp",
"src/mbgl/style/image.cpp",
"src/mbgl/style/image_impl.cpp",
"src/mbgl/style/image_impl.hpp",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"network": [
[
"probeNetwork - default - end",
2,
35923
],
[
"probeNetwork - default - start",
0,
0
]
],
"gfx": [
[
"probeGFX - default - end",
1,
4,
9,
1,
[
22080,
22080
],
[
46,
46
],
[
384,
384
]
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"network": [
[
"probeNetwork - default - end",
4,
247582
],
[
"probeNetwork - default - start",
0,
0
]
],
"gfx": [
[
"probeGFX - default - end",
2,
6,
13,
1,
[
28480,
28480
],
[
46,
46
],
[
384,
384
]
]
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"version": 8,
"metadata": {
"test": {
"pixelRatio": 1,
"width": 128,
"height": 64
}
},
"center": [
0,
0
],
"zoom": 0,
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [25, 0]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-25, 0]
}
}
]
}
}
},
"sprite": [{
"id": "default",
"url": "local://sprites/emerald"
}],
"layers": [
{
"id": "default",
"type": "symbol",
"source": "geojson",
"layout": {
"symbol-placement": "point",
"icon-image": "post_icon"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions metrics/integration/render-tests/sprites/array-multiple/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"version": 8,
"metadata": {
"test": {
"pixelRatio": 1,
"width": 128,
"height": 64
}
},
"center": [
0,
0
],
"zoom": 0,
"sources": {
"source-one": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [25, 0]
}
}
]
}
},
"source-two": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-25, 0]
}
}
]
}
}
},
"sprite": [
{
"id": "default",
"url": "local://sprites/emerald"
},
{
"id": "sprite",
"url": "local://sprites/sprite"
}
],
"layers": [
{
"id": "default-sprite-features",
"type": "symbol",
"source": "source-one",
"layout": {
"symbol-placement": "point",
"icon-image": "post_icon"
}
},
{
"id": "sprite-sprite-features",
"type": "symbol",
"source": "source-two",
"layout": {
"symbol-placement": "point",
"icon-image": "sprite:night-lighthouse-12"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"network": [
[
"probeNetwork - default - end",
2,
35923
],
[
"probeNetwork - default - start",
0,
0
]
],
"gfx": [
[
"probeGFX - default - end",
1,
4,
9,
1,
[
22080,
22080
],
[
46,
46
],
[
384,
384
]
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"network": [
[
"probeNetwork - default - end",
4,
247582
],
[
"probeNetwork - default - start",
0,
0
]
],
"gfx": [
[
"probeGFX - default - end",
2,
6,
13,
1,
[
28480,
28480
],
[
46,
46
],
[
384,
384
]
]
]
}
1 change: 1 addition & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

- Add support for the [`slice` expression](https://maplibre.org/maplibre-style-spec/expressions/#slice) ([#1113](https://github.com/maplibre/maplibre-native/pull/1133))
- Add support for the [`index-of` expression](https://maplibre.org/maplibre-style-spec/expressions/#index-of) ([#1113](https://github.com/maplibre/maplibre-native/pull/1113))
- Add support for [multi sprites](https://github.com/maplibre/maplibre-native/pull/1858). More information on this feature can be found in the [Style Spec Documentation](https://maplibre.org/maplibre-style-spec/sprite/#multiple-sprite-sources).
- Change to a more natural fling animation and allow setting `flingThreshold` and `flingAnimationBaseTime` in `UiSettings` ([#963](https://github.com/maplibre/maplibre-native/pull/963))

- 💥 Breaking: Change package of all classes from `com.mapbox.mapboxsdk` to `org.maplibre.android` ([#1201](https://github.com/maplibre/maplibre-native/pull/1201)). This means you will need to fix your imports.
Expand Down
19 changes: 11 additions & 8 deletions platform/default/src/mbgl/storage/offline_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <mbgl/style/sources/image_source.hpp>
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/tileset.hpp>
#include <mbgl/style/sprite.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/util/i18n.hpp>
#include <mbgl/util/mapbox.hpp>
Expand Down Expand Up @@ -223,8 +224,8 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
: NON_IDEOGRAPH_GLYPH_RANGES_PER_FONT_STACK);
}

if (!parser.spriteURL.empty()) {
result->requiredResourceCount += 4;
if (!parser.sprites.empty()) {
result->requiredResourceCount += 4 * parser.sprites.size();
}

return *result;
Expand All @@ -246,7 +247,6 @@ void OfflineDownload::activateDownload() {
parser.parse(*styleResponse.data);

auto tileServerOptions = onlineFileSource.getResourceOptions().tileServerOptions();
parser.spriteURL = util::mapbox::canonicalizeSpriteURL(tileServerOptions, parser.spriteURL);
parser.glyphURL = util::mapbox::canonicalizeGlyphURL(tileServerOptions, parser.glyphURL);

for (const auto& source : parser.sources) {
Expand Down Expand Up @@ -343,12 +343,15 @@ void OfflineDownload::activateDownload() {
}
}

if (!parser.spriteURL.empty()) {
if (!parser.sprites.empty()) {
// Always request 1x and @2x sprite images for portability.
queueResource(Resource::spriteImage(parser.spriteURL, 1));
queueResource(Resource::spriteImage(parser.spriteURL, 2));
queueResource(Resource::spriteJSON(parser.spriteURL, 1));
queueResource(Resource::spriteJSON(parser.spriteURL, 2));
for (const auto& sprite : parser.sprites) {
std::string spriteURL = util::mapbox::canonicalizeSpriteURL(tileServerOptions, sprite.spriteURL);
queueResource(Resource::spriteImage(spriteURL, 1));
queueResource(Resource::spriteImage(spriteURL, 2));
queueResource(Resource::spriteJSON(spriteURL, 1));
queueResource(Resource::spriteJSON(spriteURL, 2));
}
}

continueDownload();
Expand Down
4 changes: 4 additions & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ MapLibre welcomes participation and contributions from everyone. Please read [`C

## main

## 6.2.0

- Add support for [multi sprites](https://github.com/maplibre/maplibre-native/pull/1858). More information on this feature can be found in the [Style Spec Documentation](https://maplibre.org/maplibre-style-spec/sprite/#multiple-sprite-sources).

## 6.1.1

- Tighten camera equality requirements ([#2139](https://github.com/maplibre/maplibre-native/pull/2139)).
Expand Down
Loading

0 comments on commit f4c6fab

Please sign in to comment.