Skip to content

Commit 66e1009

Browse files
smellyshovelambientlightzbigniewmatysek-tomtom
authored
Add support for multiple sprites in one style (#1805)
* Add debug-page * Modify example * First working proto * Custom sprites' naming * Revert * Better test case * 1st working prototype * Cancelation handling * WIP on new Sprite type * New syntax proto * WIP on validation * Working validation * Strticter validation for duplicates * Cover validator with tests * WIP on unit tests * Fix ESlint * Provide doc for the new API. Try to suppress failing tests * Fix integration tests * After-review changes * Update sprite doc and example * Type validateSprite's options * WIP on unit testing the loadSprite function - convert base64 to img * Unit tests for loadSprite * Add render-tests * WIP on runtime modification * Implement API: addSprite, removeSprite * basic setStyle / setGlyphs behaviour * setSprite, getSprite, setGlyphs, getGlyphs implementation * update validation, state, async related logic in style's new APIs * glyph diff sample * jsdoc in removeSprite * lint fix, remove console statements * Fix typo * Make 4th param optional * Fix ESLint * Update src/style/style.ts Co-authored-by: Zbigniew Matysek <47562286+zbigniewmatysek-tomtom@users.noreply.github.com> * Fix broken render test * Revert "Fix broken render test" This reverts commit 48baedc. * Fix render tests * Address feedback * 100% test coverage for loadSprite * Refact * Try fix the build. * Try fix the build * Fix unit tests * Test `_load` for `sprite: undefined` * Add changelog entry * Remove sprite better docs Co-authored-by: ambientlight <primary.taras.vozniuk@gmail.com> Co-authored-by: Zbigniew Matysek <47562286+zbigniewmatysek-tomtom@users.noreply.github.com>
1 parent 05096ba commit 66e1009

32 files changed

Lines changed: 1087 additions & 83 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## main
22
### ✨ Features and improvements
3+
- Add support for multiple `sprite` declarations in one style file ([#1805](https://github.com/maplibre/maplibre-gl-js/pull/1805))
34
- *...Add new stuff here...*
5+
-
46
### 🐞 Bug fixes
57
- Fix issue [#1024](https://github.com/maplibre/maplibre-gl-js/pull/1024) - Zoom center not under cursor when terrain is on
68
- Fix errors when running style-spec bin scripts and added missing help. Removed unnecessary script 'gl-style-composite'. ([#1971](https://github.com/maplibre/maplibre-gl-js/pull/1971))

build/generate-style-code.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function nativeType(property) {
2929
return 'Color';
3030
case 'padding':
3131
return 'Padding';
32+
case 'sprite':
33+
return 'Sprite';
3234
case 'formatted':
3335
return 'Formatted';
3436
case 'resolvedImage':
@@ -91,6 +93,8 @@ function runtimeType(property) {
9193
return 'ColorType';
9294
case 'padding':
9395
return 'PaddingType';
96+
case 'sprite':
97+
return 'SpriteType';
9498
case 'formatted':
9599
return 'FormattedType';
96100
case 'Image':

build/generate-style-spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export type ColorSpecification = string;
122122
123123
export type PaddingSpecification = number | number[];
124124
125+
export type SpriteSpecification = string | {id: string; url: string}[];
126+
125127
export type FormattedSpecification = string;
126128
127129
export type ResolvedImageSpecification = string;

src/render/glyph_manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ export default class GlyphManager {
100100
return;
101101
}
102102

103+
if (!this.url) {
104+
callback(new Error('glyphsUrl is not set'));
105+
return;
106+
}
107+
103108
let requests = entry.requests[range];
104109
if (!requests) {
105110
requests = entry.requests[range] = [];

src/render/image_manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ class ImageManager extends Evented {
132132
return true;
133133
}
134134

135-
updateImage(id: string, image: StyleImage) {
135+
updateImage(id: string, image: StyleImage, validate = true) {
136136
const oldImage = this.images[id];
137-
if (oldImage.data.width !== image.data.width || oldImage.data.height !== image.data.height) {
137+
if (validate && (oldImage.data.width !== image.data.width || oldImage.data.height !== image.data.height)) {
138138
throw new Error(`size mismatch between old image (${oldImage.data.width}x${oldImage.data.height}) and new image (${image.data.width}x${image.data.height}).`);
139139
}
140140
image.version = oldImage.version + 1;

src/source/worker_tile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class WorkerTile {
140140

141141
const stacks = mapObject(options.glyphDependencies, (glyphs) => Object.keys(glyphs).map(Number));
142142
if (Object.keys(stacks).length) {
143-
actor.send('getGlyphs', {uid: this.uid, stacks}, (err, result) => {
143+
actor.send('getGlyphs', {uid: this.uid, stacks, source: this.source, tileID: this.tileID, type: 'glyphs'}, (err, result) => {
144144
if (!error) {
145145
error = err;
146146
glyphMap = result;

src/style-spec/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@maplibre/maplibre-gl-style-spec",
33
"description": "a specification for maplibre gl styles",
4-
"version": "17.0.2",
4+
"version": "17.1.0",
55
"author": "MapLibre",
66
"keywords": [
77
"mapbox",

src/style-spec/reference/v8.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
}
7878
},
7979
"sprite": {
80-
"type": "string",
81-
"doc": "A base URL for retrieving the sprite image and metadata. The extensions `.png`, `.json` and scale factor `@2x.png` will be automatically appended. This property is required if any layer uses the `background-pattern`, `fill-pattern`, `line-pattern`, `fill-extrusion-pattern`, or `icon-image` properties. The URL must be absolute, containing the [scheme, authority and path components](https://en.wikipedia.org/wiki/URL#Syntax).",
82-
"example": "mapbox://sprites/mapbox/bright-v8"
80+
"type": "sprite",
81+
"doc": "An array of `{id: 'my-sprite', url: 'https://example.com/sprite'} objects. Each object should represent a unique URL to load a sprite from and and a unique ID to use as a prefix when referencing images from that sprite (i.e. 'my-sprite:image'). All the URLs are internally extended to load both .json and .png files. If the `id` field is equal to 'default', the prefix is omitted (just 'image' instead of 'default:image'). All the IDs and URLs must be unique. For backwards compatibility, instead of an array, one can also provide a single string that represent a URL to load the sprite from. The images in this case won't be prefixed.",
82+
"example": "https://api.maptiler.com/maps/openstreetmap/sprite"
8383
},
8484
"glyphs": {
8585
"type": "string",

src/style-spec/style-spec.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ function validSchema(k, v, obj, ref, version, kind) {
6868
'formatted',
6969
'resolvedImage',
7070
'promoteId',
71-
'padding'
71+
'padding',
72+
'sprite'
7273
]);
7374
const keys = [
7475
'default',

src/style-spec/validate/validate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import validateString from './validate_string';
2222
import validateFormatted from './validate_formatted';
2323
import validateImage from './validate_image';
2424
import validatePadding from './validate_padding';
25+
import validateSprite from './validate_sprite';
2526

2627
const VALIDATORS = {
2728
'*'() {
@@ -43,7 +44,8 @@ const VALIDATORS = {
4344
'string': validateString,
4445
'formatted': validateFormatted,
4546
'resolvedImage': validateImage,
46-
'padding': validatePadding
47+
'padding': validatePadding,
48+
'sprite': validateSprite,
4749
};
4850

4951
// Main recursive validation function. Tracks:

0 commit comments

Comments
 (0)