maplibre-gl 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/generate-typings.ts +11 -1
- package/dist/maplibre-gl-csp-worker.js +1 -1
- package/dist/maplibre-gl-csp.js +1 -1
- package/dist/maplibre-gl-dev.js +268 -60
- package/dist/maplibre-gl.d.ts +10 -0
- package/dist/maplibre-gl.js +4 -4
- package/dist/style-spec/index.d.ts +1781 -0
- package/package.json +2 -2
- package/src/data/bucket/symbol_bucket.test.ts +30 -19
- package/src/index.test.ts +9 -0
- package/src/index.ts +11 -1
- package/src/source/worker_tile.ts +9 -1
- package/src/style-spec/CHANGELOG.md +10 -0
- package/src/style-spec/composite.test.ts +7 -8
- package/src/style-spec/expression/index.ts +13 -13
- package/src/style-spec/expression/parsing_context.ts +4 -4
- package/src/style-spec/expression/parsing_error.ts +2 -2
- package/src/style-spec/migrate/v8.test.ts +12 -14
- package/src/style-spec/migrate/v9.test.ts +2 -4
- package/src/style-spec/migrate.test.ts +6 -8
- package/src/style-spec/package.json +2 -1
- package/src/symbol/symbol_layout.ts +56 -56
- package/src/ui/map.test.ts +11 -0
- package/src/ui/map.ts +11 -0
|
@@ -151,55 +151,55 @@ export function evaluateVariableOffset(anchor: TextAnchor, offset: [number, numb
|
|
|
151
151
|
return (offset[1] !== INVALID_TEXT_OFFSET) ? fromTextOffset(anchor, offset[0], offset[1]) : fromRadialOffset(anchor, offset[0]);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
export function performSymbolLayout(
|
|
155
|
-
bucket: SymbolBucket
|
|
154
|
+
export function performSymbolLayout(args: {
|
|
155
|
+
bucket: SymbolBucket;
|
|
156
156
|
glyphMap: {
|
|
157
157
|
[_: string]: {
|
|
158
158
|
[x: number]: StyleGlyph;
|
|
159
159
|
};
|
|
160
|
-
}
|
|
160
|
+
};
|
|
161
161
|
glyphPositions: {
|
|
162
162
|
[_: string]: {
|
|
163
163
|
[x: number]: GlyphPosition;
|
|
164
164
|
};
|
|
165
|
-
}
|
|
166
|
-
imageMap: {[_: string]: StyleImage}
|
|
167
|
-
imagePositions: {[_: string]: ImagePosition}
|
|
168
|
-
showCollisionBoxes: boolean
|
|
169
|
-
canonical: CanonicalTileID
|
|
170
|
-
) {
|
|
171
|
-
bucket.createArrays();
|
|
165
|
+
};
|
|
166
|
+
imageMap: {[_: string]: StyleImage};
|
|
167
|
+
imagePositions: {[_: string]: ImagePosition};
|
|
168
|
+
showCollisionBoxes: boolean;
|
|
169
|
+
canonical: CanonicalTileID;
|
|
170
|
+
}) {
|
|
171
|
+
args.bucket.createArrays();
|
|
172
172
|
|
|
173
|
-
const tileSize = 512 * bucket.overscaling;
|
|
174
|
-
bucket.tilePixelRatio = EXTENT / tileSize;
|
|
175
|
-
bucket.compareText = {};
|
|
176
|
-
bucket.iconsNeedLinear = false;
|
|
173
|
+
const tileSize = 512 * args.bucket.overscaling;
|
|
174
|
+
args.bucket.tilePixelRatio = EXTENT / tileSize;
|
|
175
|
+
args.bucket.compareText = {};
|
|
176
|
+
args.bucket.iconsNeedLinear = false;
|
|
177
177
|
|
|
178
|
-
const layout = bucket.layers[0].layout;
|
|
179
|
-
const unevaluatedLayoutValues = bucket.layers[0]._unevaluatedLayout._values;
|
|
178
|
+
const layout = args.bucket.layers[0].layout;
|
|
179
|
+
const unevaluatedLayoutValues = args.bucket.layers[0]._unevaluatedLayout._values;
|
|
180
180
|
|
|
181
181
|
const sizes: Sizes = {
|
|
182
182
|
// Filled in below, if *SizeData.kind is 'composite'
|
|
183
183
|
// compositeIconSizes: undefined,
|
|
184
184
|
// compositeTextSizes: undefined,
|
|
185
|
-
layoutIconSize: unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(bucket.zoom + 1), canonical),
|
|
186
|
-
layoutTextSize: unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(bucket.zoom + 1), canonical),
|
|
185
|
+
layoutIconSize: unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(args.bucket.zoom + 1), args.canonical),
|
|
186
|
+
layoutTextSize: unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(args.bucket.zoom + 1), args.canonical),
|
|
187
187
|
textMaxSize: unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(18))
|
|
188
188
|
} as Sizes;
|
|
189
189
|
|
|
190
|
-
if (bucket.textSizeData.kind === 'composite') {
|
|
191
|
-
const {minZoom, maxZoom} = bucket.textSizeData;
|
|
190
|
+
if (args.bucket.textSizeData.kind === 'composite') {
|
|
191
|
+
const {minZoom, maxZoom} = args.bucket.textSizeData;
|
|
192
192
|
sizes.compositeTextSizes = [
|
|
193
|
-
unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(minZoom), canonical),
|
|
194
|
-
unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), canonical)
|
|
193
|
+
unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(minZoom), args.canonical),
|
|
194
|
+
unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), args.canonical)
|
|
195
195
|
];
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
if (bucket.iconSizeData.kind === 'composite') {
|
|
199
|
-
const {minZoom, maxZoom} = bucket.iconSizeData;
|
|
198
|
+
if (args.bucket.iconSizeData.kind === 'composite') {
|
|
199
|
+
const {minZoom, maxZoom} = args.bucket.iconSizeData;
|
|
200
200
|
sizes.compositeIconSizes = [
|
|
201
|
-
unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(minZoom), canonical),
|
|
202
|
-
unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), canonical)
|
|
201
|
+
unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(minZoom), args.canonical),
|
|
202
|
+
unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), args.canonical)
|
|
203
203
|
];
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -208,11 +208,11 @@ export function performSymbolLayout(
|
|
|
208
208
|
const keepUpright = layout.get('text-keep-upright');
|
|
209
209
|
const textSize = layout.get('text-size');
|
|
210
210
|
|
|
211
|
-
for (const feature of bucket.features) {
|
|
212
|
-
const fontstack = layout.get('text-font').evaluate(feature, {}, canonical).join(',');
|
|
213
|
-
const layoutTextSizeThisZoom = textSize.evaluate(feature, {}, canonical);
|
|
214
|
-
const layoutTextSize = sizes.layoutTextSize.evaluate(feature, {}, canonical);
|
|
215
|
-
const layoutIconSize = sizes.layoutIconSize.evaluate(feature, {}, canonical);
|
|
211
|
+
for (const feature of args.bucket.features) {
|
|
212
|
+
const fontstack = layout.get('text-font').evaluate(feature, {}, args.canonical).join(',');
|
|
213
|
+
const layoutTextSizeThisZoom = textSize.evaluate(feature, {}, args.canonical);
|
|
214
|
+
const layoutTextSize = sizes.layoutTextSize.evaluate(feature, {}, args.canonical);
|
|
215
|
+
const layoutIconSize = sizes.layoutIconSize.evaluate(feature, {}, args.canonical);
|
|
216
216
|
|
|
217
217
|
const shapedTextOrientations: ShapedTextOrientations = {
|
|
218
218
|
horizontal: {} as Record<TextJustify, Shaping>,
|
|
@@ -222,14 +222,14 @@ export function performSymbolLayout(
|
|
|
222
222
|
let textOffset: [number, number] = [0, 0];
|
|
223
223
|
if (text) {
|
|
224
224
|
const unformattedText = text.toString();
|
|
225
|
-
const spacing = layout.get('text-letter-spacing').evaluate(feature, {}, canonical) * ONE_EM;
|
|
225
|
+
const spacing = layout.get('text-letter-spacing').evaluate(feature, {}, args.canonical) * ONE_EM;
|
|
226
226
|
const spacingIfAllowed = allowsLetterSpacing(unformattedText) ? spacing : 0;
|
|
227
227
|
|
|
228
|
-
const textAnchor = layout.get('text-anchor').evaluate(feature, {}, canonical);
|
|
228
|
+
const textAnchor = layout.get('text-anchor').evaluate(feature, {}, args.canonical);
|
|
229
229
|
const variableTextAnchor = layout.get('text-variable-anchor');
|
|
230
230
|
|
|
231
231
|
if (!variableTextAnchor) {
|
|
232
|
-
const radialOffset = layout.get('text-radial-offset').evaluate(feature, {}, canonical);
|
|
232
|
+
const radialOffset = layout.get('text-radial-offset').evaluate(feature, {}, args.canonical);
|
|
233
233
|
// Layers with variable anchors use the `text-radial-offset` property and the [x, y] offset vector
|
|
234
234
|
// is calculated at placement time instead of layout time
|
|
235
235
|
if (radialOffset) {
|
|
@@ -237,25 +237,25 @@ export function performSymbolLayout(
|
|
|
237
237
|
// but doesn't actually specify what happens if you use both. We go with the radial offset.
|
|
238
238
|
textOffset = evaluateVariableOffset(textAnchor, [radialOffset * ONE_EM, INVALID_TEXT_OFFSET]) as [number, number];
|
|
239
239
|
} else {
|
|
240
|
-
textOffset = (layout.get('text-offset').evaluate(feature, {}, canonical).map(t => t * ONE_EM) as [number, number]);
|
|
240
|
+
textOffset = (layout.get('text-offset').evaluate(feature, {}, args.canonical).map(t => t * ONE_EM) as [number, number]);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
let textJustify = textAlongLine ?
|
|
245
245
|
'center' :
|
|
246
|
-
layout.get('text-justify').evaluate(feature, {}, canonical);
|
|
246
|
+
layout.get('text-justify').evaluate(feature, {}, args.canonical);
|
|
247
247
|
|
|
248
248
|
const symbolPlacement = layout.get('symbol-placement');
|
|
249
249
|
const maxWidth = symbolPlacement === 'point' ?
|
|
250
|
-
layout.get('text-max-width').evaluate(feature, {}, canonical) * ONE_EM :
|
|
250
|
+
layout.get('text-max-width').evaluate(feature, {}, args.canonical) * ONE_EM :
|
|
251
251
|
0;
|
|
252
252
|
|
|
253
253
|
const addVerticalShapingForPointLabelIfNeeded = () => {
|
|
254
|
-
if (bucket.allowVerticalPlacement && allowsVerticalWritingMode(unformattedText)) {
|
|
254
|
+
if (args.bucket.allowVerticalPlacement && allowsVerticalWritingMode(unformattedText)) {
|
|
255
255
|
// Vertical POI label placement is meant to be used for scripts that support vertical
|
|
256
256
|
// writing mode, thus, default left justification is used. If Latin
|
|
257
257
|
// scripts would need to be supported, this should take into account other justifications.
|
|
258
|
-
shapedTextOrientations.vertical = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor,
|
|
258
|
+
shapedTextOrientations.vertical = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor,
|
|
259
259
|
'left', spacingIfAllowed, textOffset, WritingMode.vertical, true, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
|
|
260
260
|
}
|
|
261
261
|
};
|
|
@@ -277,7 +277,7 @@ export function performSymbolLayout(
|
|
|
277
277
|
} else {
|
|
278
278
|
// If using text-variable-anchor for the layer, we use a center anchor for all shapings and apply
|
|
279
279
|
// the offsets for the anchor in the placement step.
|
|
280
|
-
const shaping = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, 'center',
|
|
280
|
+
const shaping = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, 'center',
|
|
281
281
|
justification, spacingIfAllowed, textOffset, WritingMode.horizontal, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
|
|
282
282
|
if (shaping) {
|
|
283
283
|
shapedTextOrientations.horizontal[justification] = shaping;
|
|
@@ -293,7 +293,7 @@ export function performSymbolLayout(
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
// Horizontal point or line label.
|
|
296
|
-
const shaping = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify, spacingIfAllowed,
|
|
296
|
+
const shaping = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify, spacingIfAllowed,
|
|
297
297
|
textOffset, WritingMode.horizontal, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
|
|
298
298
|
if (shaping) shapedTextOrientations.horizontal[textJustify] = shaping;
|
|
299
299
|
|
|
@@ -302,7 +302,7 @@ export function performSymbolLayout(
|
|
|
302
302
|
|
|
303
303
|
// Verticalized line label.
|
|
304
304
|
if (allowsVerticalWritingMode(unformattedText) && textAlongLine && keepUpright) {
|
|
305
|
-
shapedTextOrientations.vertical = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify,
|
|
305
|
+
shapedTextOrientations.vertical = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify,
|
|
306
306
|
spacingIfAllowed, textOffset, WritingMode.vertical, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
|
|
307
307
|
}
|
|
308
308
|
}
|
|
@@ -311,36 +311,36 @@ export function performSymbolLayout(
|
|
|
311
311
|
let shapedIcon;
|
|
312
312
|
let isSDFIcon = false;
|
|
313
313
|
if (feature.icon && feature.icon.name) {
|
|
314
|
-
const image = imageMap[feature.icon.name];
|
|
314
|
+
const image = args.imageMap[feature.icon.name];
|
|
315
315
|
if (image) {
|
|
316
316
|
shapedIcon = shapeIcon(
|
|
317
|
-
imagePositions[feature.icon.name],
|
|
318
|
-
layout.get('icon-offset').evaluate(feature, {}, canonical),
|
|
319
|
-
layout.get('icon-anchor').evaluate(feature, {}, canonical));
|
|
317
|
+
args.imagePositions[feature.icon.name],
|
|
318
|
+
layout.get('icon-offset').evaluate(feature, {}, args.canonical),
|
|
319
|
+
layout.get('icon-anchor').evaluate(feature, {}, args.canonical));
|
|
320
320
|
// null/undefined SDF property treated same as default (false)
|
|
321
321
|
isSDFIcon = !!image.sdf;
|
|
322
|
-
if (bucket.sdfIcons === undefined) {
|
|
323
|
-
bucket.sdfIcons = isSDFIcon;
|
|
324
|
-
} else if (bucket.sdfIcons !== isSDFIcon) {
|
|
322
|
+
if (args.bucket.sdfIcons === undefined) {
|
|
323
|
+
args.bucket.sdfIcons = isSDFIcon;
|
|
324
|
+
} else if (args.bucket.sdfIcons !== isSDFIcon) {
|
|
325
325
|
warnOnce('Style sheet warning: Cannot mix SDF and non-SDF icons in one buffer');
|
|
326
326
|
}
|
|
327
|
-
if (image.pixelRatio !== bucket.pixelRatio) {
|
|
328
|
-
bucket.iconsNeedLinear = true;
|
|
327
|
+
if (image.pixelRatio !== args.bucket.pixelRatio) {
|
|
328
|
+
args.bucket.iconsNeedLinear = true;
|
|
329
329
|
} else if (layout.get('icon-rotate').constantOr(1) !== 0) {
|
|
330
|
-
bucket.iconsNeedLinear = true;
|
|
330
|
+
args.bucket.iconsNeedLinear = true;
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
const shapedText = getDefaultHorizontalShaping(shapedTextOrientations.horizontal) || shapedTextOrientations.vertical;
|
|
336
|
-
bucket.iconsInText = shapedText ? shapedText.iconsInText : false;
|
|
336
|
+
args.bucket.iconsInText = shapedText ? shapedText.iconsInText : false;
|
|
337
337
|
if (shapedText || shapedIcon) {
|
|
338
|
-
addFeature(bucket, feature, shapedTextOrientations, shapedIcon, imageMap, sizes, layoutTextSize, layoutIconSize, textOffset, isSDFIcon, canonical);
|
|
338
|
+
addFeature(args.bucket, feature, shapedTextOrientations, shapedIcon, args.imageMap, sizes, layoutTextSize, layoutIconSize, textOffset, isSDFIcon, args.canonical);
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
if (showCollisionBoxes) {
|
|
343
|
-
bucket.generateCollisionDebugBuffers();
|
|
342
|
+
if (args.showCollisionBoxes) {
|
|
343
|
+
args.bucket.generateCollisionDebugBuffers();
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
package/src/ui/map.test.ts
CHANGED
|
@@ -40,6 +40,17 @@ afterEach(() => {
|
|
|
40
40
|
|
|
41
41
|
describe('Map', () => {
|
|
42
42
|
|
|
43
|
+
test('version', () => {
|
|
44
|
+
const map = createMap({interactive: true, style: null});
|
|
45
|
+
|
|
46
|
+
expect(typeof map.version === 'string').toBeTruthy();
|
|
47
|
+
|
|
48
|
+
// Semver regex: https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39
|
|
49
|
+
// Backslashes are doubled to escape them
|
|
50
|
+
const regexp = new RegExp('^([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$');
|
|
51
|
+
expect(regexp.test(map.version)).toBeTruthy();
|
|
52
|
+
});
|
|
53
|
+
|
|
43
54
|
test('constructor', () => {
|
|
44
55
|
const map = createMap({interactive: true, style: null});
|
|
45
56
|
expect(map.getContainer()).toBeTruthy();
|
package/src/ui/map.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {extend, bindAll, warnOnce, uniqueId, isImageBitmap} from '../util/util';
|
|
2
2
|
import browser from '../util/browser';
|
|
3
3
|
import DOM from '../util/dom';
|
|
4
|
+
import packageJSON from '../../package.json' assert {type: 'json'};
|
|
4
5
|
import {getImage, GetImageCallback, getJSON, ResourceType} from '../util/ajax';
|
|
5
6
|
import {RequestManager} from '../util/request_manager';
|
|
6
7
|
import Style from '../style/style';
|
|
@@ -58,6 +59,8 @@ import {Callback} from '../types/callback';
|
|
|
58
59
|
import type {ControlPosition, IControl} from './control/control';
|
|
59
60
|
import type {MapGeoJSONFeature} from '../util/vectortile_to_geojson';
|
|
60
61
|
|
|
62
|
+
const version = packageJSON.version;
|
|
63
|
+
|
|
61
64
|
/* eslint-enable no-use-before-define */
|
|
62
65
|
export type MapOptions = {
|
|
63
66
|
hash?: boolean | string;
|
|
@@ -2925,6 +2928,14 @@ class Map extends Camera {
|
|
|
2925
2928
|
_setCacheLimits(limit: number, checkThreshold: number) {
|
|
2926
2929
|
setCacheLimits(limit, checkThreshold);
|
|
2927
2930
|
}
|
|
2931
|
+
|
|
2932
|
+
/**
|
|
2933
|
+
* Returns the package version of the library
|
|
2934
|
+
* @returns {string} Package version of the library
|
|
2935
|
+
*/
|
|
2936
|
+
get version(): string {
|
|
2937
|
+
return version;
|
|
2938
|
+
}
|
|
2928
2939
|
}
|
|
2929
2940
|
|
|
2930
2941
|
export default Map;
|