Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Stretchable icons #16030

Merged
merged 13 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### ✨ New features

- [core] Implement stretchable icons ([#16030](https://github.com/mapbox/mapbox-gl-native/pull/16030))

[Stretchable icons](https://github.com/mapbox/mapbox-gl-js/issues/8917) allow defining certain areas of an icon that may be stretched, leaving the remaining areas of an icon at a fixed size.

- [core] Port line-sort-key and fill-sort-key ([#15839](https://github.com/mapbox/mapbox-gl-native/pull/15839))

The new feature allows to sort line and fill layer features. Similar to `symbol-sort-key`.
Expand Down
46 changes: 45 additions & 1 deletion include/mbgl/style/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,52 @@

#include <mbgl/util/image.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/util/optional.hpp>

#include <string>
#include <utility>
#include <vector>

namespace mbgl {
namespace style {

using ImageStretch = std::pair<float, float>;
using ImageStretches = std::vector<ImageStretch>;

class ImageContent {
public:
float left;
float top;
float right;
float bottom;

bool operator==(const ImageContent& rhs) const {
return left == rhs.left && top == rhs.top && right == rhs.right && bottom == rhs.bottom;
}
};

class Image {
public:
Image(std::string id, PremultipliedImage&&, float pixelRatio, bool sdf = false);
Image(std::string id,
PremultipliedImage&&,
float pixelRatio,
bool sdf,
ImageStretches stretchX = {},
ImageStretches stretchY = {},
optional<ImageContent> content = nullopt);
Image(std::string id,
PremultipliedImage&& image,
float pixelRatio,
ImageStretches stretchX = {},
ImageStretches stretchY = {},
optional<ImageContent> content = nullopt)
: Image(std::move(id),
std::move(image),
pixelRatio,
false,
std::move(stretchX),
std::move(stretchY),
std::move(content)) {}
Image(const Image&);

std::string getID() const;
Expand All @@ -23,6 +60,13 @@ class Image {
// Whether this image should be interpreted as a signed distance field icon.
bool isSdf() const;

// Stretch areas of this image.
const ImageStretches& getStretchX() const;
const ImageStretches& getStretchY() const;

// The space where text can be fit into this image.
const optional<ImageContent>& getContent() const;

class Impl;
Immutable<Impl> baseImpl;
};
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/util/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ struct Exception : std::runtime_error {
Exception(const std::string &msg) : std::runtime_error(msg) {}
};

struct SpriteImageException : Exception {
SpriteImageException(const char *msg) : Exception(msg) {}
SpriteImageException(const std::string &msg) : Exception(msg) {}
struct StyleImageException : Exception {
StyleImageException(const char *msg) : Exception(msg) {}
StyleImageException(const std::string &msg) : Exception(msg) {}
};

struct MisuseException : Exception {
Expand Down
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 93 files
+44 −0 CHANGELOG.md
+61 −0 bench/benchmarks/placement.js
+4 −3 bench/lib/create_map.js
+2 −1 bench/lib/tile_parser.js
+2 −0 bench/versions/benchmarks.js
+2 −2 bench/versions/index.html
+2 −0 build/generate-flow-typed-style-spec.js
+73 −0 debug/featurestate.html
+129 −0 debug/stretchable.html
+1 −1 package.json
+14 −9 src/data/array_types.js
+1 −0 src/data/bucket.js
+2 −2 src/data/bucket/circle_bucket.js
+2 −2 src/data/bucket/fill_bucket.js
+2 −1 src/data/bucket/fill_extrusion_bucket.js
+3 −2 src/data/bucket/symbol_attributes.js
+25 −28 src/data/bucket/symbol_bucket.js
+24 −12 src/data/feature_index.js
+18 −5 src/data/feature_position_map.js
+2 −2 src/data/program_configuration.js
+1 −1 src/geo/lng_lat.js
+10 −15 src/render/draw_hillshade.js
+10 −10 src/render/draw_raster.js
+8 −2 src/render/image_atlas.js
+46 −2 src/render/image_manager.js
+30 −10 src/render/painter.js
+0 −104 src/render/tile_mask.js
+5 −1 src/shaders/symbol_icon.vertex.glsl
+4 −1 src/shaders/symbol_sdf.vertex.glsl
+5 −3 src/source/geojson_source.js
+0 −1 src/source/raster_dem_tile_source.js
+0 −1 src/source/raster_tile_source.js
+12 −13 src/source/source_cache.js
+5 −5 src/source/source_state.js
+7 −83 src/source/tile.js
+8 −0 src/source/tile_cache.js
+15 −0 src/source/tile_id.js
+4 −3 src/source/vector_tile_source.js
+2 −0 src/source/worker_source.js
+6 −2 src/source/worker_tile.js
+8 −0 src/style-spec/CHANGELOG.md
+1 −1 src/style-spec/package.json
+11 −3 src/style-spec/reference/v8.json
+6 −2 src/style-spec/types.js
+22 −2 src/style-spec/validate/validate_source.js
+2 −2 src/style/load_sprite.js
+15 −25 src/style/style.js
+11 −3 src/style/style_image.js
+8 −0 src/symbol/collision_feature.js
+163 −37 src/symbol/quads.js
+15 −2 src/symbol/shaping.js
+3 −2 src/symbol/symbol_layout.js
+1 −0 src/ui/control/attribution_control.js
+25 −4 src/ui/map.js
+2 −5 src/util/vectortile_to_geojson.js
+ test/integration/render-tests/feature-state/promote-id/expected.png
+99 −0 test/integration/render-tests/feature-state/promote-id/style.json
+ test/integration/render-tests/icon-image/stretchable-content/expected.png
+41 −0 test/integration/render-tests/icon-image/stretchable-content/style.json
+ test/integration/render-tests/icon-image/stretchable/expected.png
+41 −0 test/integration/render-tests/icon-image/stretchable/style.json
+ test/integration/render-tests/icon-text-fit/stretch-fifteen-part/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-fifteen-part/style.json
+ test/integration/render-tests/icon-text-fit/stretch-nine-part-@2x/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-nine-part-@2x/style.json
+ test/integration/render-tests/icon-text-fit/stretch-nine-part-content-collision/expected.png
+156 −0 test/integration/render-tests/icon-text-fit/stretch-nine-part-content-collision/style.json
+ test/integration/render-tests/icon-text-fit/stretch-nine-part-content/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-nine-part-content/style.json
+ test/integration/render-tests/icon-text-fit/stretch-nine-part-just-height/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-nine-part-just-height/style.json
+ test/integration/render-tests/icon-text-fit/stretch-nine-part-just-width/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-nine-part-just-width/style.json
+ test/integration/render-tests/icon-text-fit/stretch-nine-part/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-nine-part/style.json
+ test/integration/render-tests/icon-text-fit/stretch-three-part/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-three-part/style.json
+ test/integration/render-tests/icon-text-fit/stretch-two-part/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-two-part/style.json
+ test/integration/render-tests/icon-text-fit/stretch-underscale/expected.png
+192 −0 test/integration/render-tests/icon-text-fit/stretch-underscale/style.json
+ test/integration/render-tests/raster-masking/overlapping-vector/expected.png
+90 −0 test/integration/render-tests/raster-masking/overlapping-vector/style.json
+61 −0 test/integration/sprites/stretch.json
+ test/integration/sprites/stretch.png
+17 −0 test/unit/changelog.js
+0 −41 test/unit/source/tile.test.js
+0 −151 test/unit/source/tile_mask.test.js
+2 −1 test/unit/style-spec/spec.test.js
+55 −5 test/unit/symbol/quads.test.js
+17 −0 test/unit/symbol/shaping.test.js
+13 −0 test/unit/ui/control/attribution.test.js
+34 −82 test/unit/ui/map.test.js
Binary file modified metrics/cache-style.db
Binary file not shown.
10 changes: 0 additions & 10 deletions metrics/ignores/platform-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@
"render-tests/fill-extrusion-pattern/tile-buffer": "https://github.com/mapbox/mapbox-gl-js/issues/3327",
"render-tests/fill-pattern/update-feature-state": "https://github.com/mapbox/mapbox-gl-native/issues/15895",
"render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary",
"render-tests/icon-text-fit/stretch-fifteen-part": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-nine-part": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-nine-part-@2x": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-nine-part-content": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-nine-part-content-collision": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-nine-part-just-height": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-nine-part-just-width": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-three-part": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-two-part": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/stretch-underscale": "https://github.com/mapbox/mapbox-gl-native/issues/16017",
"render-tests/icon-text-fit/text-variable-anchor-overlap": "https://github.com/mapbox/mapbox-gl-native/issues/15809",
"render-tests/mixed-zoom/z10-z11": "https://github.com/mapbox/mapbox-gl-native/issues/10397",
"render-tests/raster-masking/overlapping-zoom": "https://github.com/mapbox/mapbox-gl-native/issues/10195",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
34
],
[
192,
192
224,
224
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
34
],
[
192,
192
224,
224
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
94
],
[
272,
272
304,
304
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
94
],
[
444,
444
476,
476
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
66
],
[
212,
212
244,
244
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
66
],
[
212,
212
244,
244
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
94
],
[
272,
272
304,
304
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
34
],
[
192,
192
224,
224
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
82
],
[
272,
272
304,
304
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
34
],
[
192,
192
224,
224
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
34
],
[
192,
192
224,
224
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
34
],
[
192,
192
224,
224
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
94
],
[
272,
272
304,
304
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
94
],
[
444,
444
476,
476
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
66
],
[
212,
212
244,
244
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
66
],
[
212,
212
244,
244
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
94
],
[
272,
272
304,
304
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
34
],
[
192,
192
224,
224
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
82
],
[
272,
272
304,
304
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
34
],
[
192,
192
224,
224
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
46
],
[
320,
320
384,
384
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
1578
],
[
13856,
13856
15648,
15648
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
102
],
[
768,
768
896,
896
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
790
],
[
7232,
7232
8256,
8256
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
30814
],
[
286816,
286816
327232,
327232
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
30814
],
[
286816,
286816
327232,
327232
]
]
]
Expand Down
Loading