maplibre-gl 2.0.2 → 2.1.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-struct-arrays.ts +1 -1
- package/build/post-ts-build.js +0 -9
- package/build/release-notes.js +7 -32
- package/dist/maplibre-gl.css +1 -1
- package/dist/maplibre-gl.d.ts +57 -219
- package/dist/maplibre-gl.js +4 -4
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +37 -53
- package/src/css/maplibre-gl.css +21 -21
- package/src/data/array_types.ts +1 -1
- package/src/data/bucket/circle_bucket.ts +1 -1
- package/src/data/bucket/fill_bucket.test.ts +1 -1
- package/src/data/bucket/fill_bucket.ts +1 -1
- package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
- package/src/data/bucket/line_bucket.test.ts +1 -1
- package/src/data/bucket/line_bucket.ts +1 -1
- package/src/data/bucket/symbol_bucket.test.ts +1 -1
- package/src/data/bucket/symbol_bucket.ts +4 -4
- package/src/data/bucket.ts +1 -1
- package/src/data/evaluation_feature.ts +1 -1
- package/src/data/feature_index.ts +1 -1
- package/src/data/load_geometry.ts +1 -1
- package/src/data/program_configuration.ts +1 -1
- package/src/geo/edge_insets.ts +1 -1
- package/src/geo/transform.test.ts +1 -1
- package/src/geo/transform.ts +1 -1
- package/src/index.ts +1 -1
- package/src/render/draw_debug.ts +1 -1
- package/src/render/draw_symbol.ts +1 -1
- package/src/render/glyph_manager.ts +1 -1
- package/src/render/painter.ts +5 -3
- package/src/render/program/circle_program.ts +1 -1
- package/src/render/program/line_program.ts +3 -3
- package/src/render/program/symbol_program.ts +1 -1
- package/src/source/geojson_source.test.ts +29 -1
- package/src/source/geojson_source.ts +2 -4
- package/src/source/geojson_wrapper.ts +1 -1
- package/src/source/image_source.test.ts +153 -0
- package/src/source/query_features.test.ts +1 -1
- package/src/source/query_features.ts +1 -1
- package/src/source/raster_dem_tile_source.test.ts +2 -1
- package/src/source/raster_dem_tile_source.ts +1 -1
- package/src/source/raster_tile_source.test.ts +2 -1
- package/src/source/raster_tile_source.ts +1 -1
- package/src/source/source_cache.test.ts +2 -2
- package/src/source/source_cache.ts +1 -1
- package/src/source/tile.test.ts +1 -1
- package/src/source/tile.ts +1 -1
- package/src/source/tile_id.test.ts +10 -12
- package/src/source/tile_id.ts +3 -3
- package/src/source/vector_tile_source.test.ts +2 -1
- package/src/source/vector_tile_source.ts +2 -2
- package/src/source/vector_tile_worker_source.test.ts +306 -0
- package/src/style/load_sprite.ts +2 -1
- package/src/style/properties.ts +1 -1
- package/src/style/query_utils.ts +1 -1
- package/src/style/style.test.ts +4 -0
- package/src/style/style.ts +1 -1
- package/src/style/style_layer/circle_style_layer.ts +1 -1
- package/src/style/style_layer/custom_style_layer.ts +2 -2
- package/src/style/style_layer/fill_extrusion_style_layer.ts +2 -2
- package/src/style/style_layer/fill_style_layer.ts +1 -1
- package/src/style/style_layer/line_style_layer.ts +1 -1
- package/src/style/style_layer/symbol_style_layer.ts +19 -0
- package/src/style/style_layer/symbol_style_layer_properties.ts +6 -0
- package/src/style/style_layer.ts +1 -1
- package/src/style-spec/CHANGELOG.md +6 -0
- package/src/style-spec/expression/index.ts +1 -1
- package/src/style-spec/feature_filter/feature_filter.test.ts +1 -1
- package/src/style-spec/migrate.test.ts +112 -0
- package/src/style-spec/package.json +1 -1
- package/src/style-spec/reference/v8.json +68 -2
- package/src/style-spec/style-spec.ts +0 -3
- package/src/style-spec/types.ts +2 -0
- package/src/style-spec/validate_spec.test.ts +29 -0
- package/src/symbol/anchor.ts +1 -1
- package/src/symbol/check_max_angle.test.ts +1 -1
- package/src/symbol/check_max_angle.ts +1 -1
- package/src/symbol/clip_line.test.ts +1 -1
- package/src/symbol/clip_line.ts +1 -1
- package/src/symbol/collision_feature.test.ts +1 -1
- package/src/symbol/collision_feature.ts +1 -1
- package/src/symbol/collision_index.ts +20 -20
- package/src/symbol/get_anchors.test.ts +1 -1
- package/src/symbol/get_anchors.ts +1 -1
- package/src/symbol/grid_index.test.ts +42 -19
- package/src/symbol/grid_index.ts +62 -33
- package/src/symbol/mergelines.test.ts +1 -1
- package/src/symbol/path_interpolator.test.ts +1 -1
- package/src/symbol/path_interpolator.ts +1 -1
- package/src/symbol/placement.ts +83 -54
- package/src/symbol/projection.ts +1 -1
- package/src/symbol/quads.ts +1 -1
- package/src/symbol/symbol_layout.ts +1 -1
- package/src/symbol/symbol_style_layer.test.ts +48 -1
- package/src/ui/camera.test.ts +0 -8
- package/src/ui/camera.ts +13 -3
- package/src/ui/control/navigation_control.ts +1 -1
- package/src/ui/events.ts +1 -1
- package/src/ui/handler/box_zoom.ts +1 -1
- package/src/ui/handler/click_zoom.ts +1 -1
- package/src/ui/handler/handler_util.ts +1 -1
- package/src/ui/handler/map_event.ts +1 -1
- package/src/ui/handler/mouse.ts +1 -1
- package/src/ui/handler/scroll_zoom.ts +1 -1
- package/src/ui/handler/tap_drag_zoom.ts +1 -1
- package/src/ui/handler/tap_recognizer.ts +1 -1
- package/src/ui/handler/tap_zoom.ts +1 -1
- package/src/ui/handler/touch_pan.ts +1 -1
- package/src/ui/handler/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler_inertia.ts +1 -1
- package/src/ui/handler_manager.ts +1 -1
- package/src/ui/map.test.ts +61 -0
- package/src/ui/map.ts +35 -10
- package/src/ui/marker.test.ts +1 -1
- package/src/ui/marker.ts +2 -1
- package/src/ui/popup.test.ts +1 -1
- package/src/ui/popup.ts +2 -2
- package/src/util/ajax.test.ts +206 -0
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/classify_rings.ts +1 -1
- package/src/util/dom.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +1 -1
- package/src/util/intersection_tests.ts +1 -1
- package/src/util/smart_wrap.ts +1 -1
- package/src/util/test/util.ts +14 -0
- package/src/util/util.test.ts +1 -1
- package/src/util/util.ts +1 -1
- package/CHANGELOG.md +0 -2585
- package/src/types/packages-types/vector-tile/index.d.ts +0 -27
- package/src/util/point.ts +0 -349
|
@@ -99,7 +99,7 @@ const lineUniformValues = (painter: Painter, tile: Tile, layer: LineStyleLayer):
|
|
|
99
99
|
return {
|
|
100
100
|
'u_matrix': calculateMatrix(painter, tile, layer),
|
|
101
101
|
'u_ratio': 1 / pixelsToTileUnits(tile, 1, transform.zoom),
|
|
102
|
-
'u_device_pixel_ratio':
|
|
102
|
+
'u_device_pixel_ratio': painter.pixelRatio,
|
|
103
103
|
'u_units_to_pixels': [
|
|
104
104
|
1 / transform.pixelsToGLUnits[0],
|
|
105
105
|
1 / transform.pixelsToGLUnits[1]
|
|
@@ -127,7 +127,7 @@ const linePatternUniformValues = (
|
|
|
127
127
|
'u_texsize': tile.imageAtlasTexture.size,
|
|
128
128
|
// camera zoom ratio
|
|
129
129
|
'u_ratio': 1 / pixelsToTileUnits(tile, 1, transform.zoom),
|
|
130
|
-
'u_device_pixel_ratio':
|
|
130
|
+
'u_device_pixel_ratio': painter.pixelRatio,
|
|
131
131
|
'u_image': 0,
|
|
132
132
|
'u_scale': [tileZoomRatio, crossfade.fromScale, crossfade.toScale],
|
|
133
133
|
'u_fade': crossfade.t,
|
|
@@ -160,7 +160,7 @@ const lineSDFUniformValues = (
|
|
|
160
160
|
return extend(lineUniformValues(painter, tile, layer), {
|
|
161
161
|
'u_patternscale_a': [tileRatio / widthA, -posA.height / 2],
|
|
162
162
|
'u_patternscale_b': [tileRatio / widthB, -posB.height / 2],
|
|
163
|
-
'u_sdfgamma': lineAtlas.width / (Math.min(widthA, widthB) * 256 *
|
|
163
|
+
'u_sdfgamma': lineAtlas.width / (Math.min(widthA, widthB) * 256 * painter.pixelRatio) / 2,
|
|
164
164
|
'u_image': 0,
|
|
165
165
|
'u_tex_y_a': posA.y,
|
|
166
166
|
'u_tex_y_b': posB.y,
|
|
@@ -195,7 +195,7 @@ const symbolSDFUniformValues = (
|
|
|
195
195
|
rotateInShader, pitchWithMap, painter, matrix, labelPlaneMatrix,
|
|
196
196
|
glCoordMatrix, isText, texSize), {
|
|
197
197
|
'u_gamma_scale': (pitchWithMap ? Math.cos(transform._pitch) * transform.cameraToCenterDistance : 1),
|
|
198
|
-
'u_device_pixel_ratio':
|
|
198
|
+
'u_device_pixel_ratio': painter.pixelRatio,
|
|
199
199
|
'u_is_halo': +isHalo
|
|
200
200
|
});
|
|
201
201
|
};
|
|
@@ -227,6 +227,33 @@ describe('GeoJSONSource#update', () => {
|
|
|
227
227
|
} as GeoJSONSourceOptions, mockDispatcher, undefined).load();
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
+
test('forwards Supercluster options with worker request, ignore max zoom of source', done => {
|
|
231
|
+
const mockDispatcher = wrapDispatcher({
|
|
232
|
+
send(message, params) {
|
|
233
|
+
expect(message).toBe('geojson.loadData');
|
|
234
|
+
expect(params.superclusterOptions).toEqual({
|
|
235
|
+
maxZoom: 12,
|
|
236
|
+
minPoints: 3,
|
|
237
|
+
extent: 8192,
|
|
238
|
+
radius: 1600,
|
|
239
|
+
log: false,
|
|
240
|
+
generateId: true
|
|
241
|
+
});
|
|
242
|
+
done();
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
new GeoJSONSource('id', {
|
|
247
|
+
data: {},
|
|
248
|
+
maxzoom: 10,
|
|
249
|
+
cluster: true,
|
|
250
|
+
clusterMaxZoom: 12,
|
|
251
|
+
clusterRadius: 100,
|
|
252
|
+
clusterMinPoints: 3,
|
|
253
|
+
generateId: true
|
|
254
|
+
} as GeoJSONSourceOptions, mockDispatcher, undefined).load();
|
|
255
|
+
});
|
|
256
|
+
|
|
230
257
|
test('transforms url before making request', () => {
|
|
231
258
|
const mapStub = {
|
|
232
259
|
_requestManager: {
|
|
@@ -291,7 +318,8 @@ describe('GeoJSONSource#update', () => {
|
|
|
291
318
|
|
|
292
319
|
const source = new GeoJSONSource('id', {data: {}} as GeoJSONSourceOptions, mockDispatcher, undefined);
|
|
293
320
|
source.map = {
|
|
294
|
-
transform: {} as Transform
|
|
321
|
+
transform: {} as Transform,
|
|
322
|
+
getPixelRatio() { return 1; }
|
|
295
323
|
} as any;
|
|
296
324
|
|
|
297
325
|
source.on('data', (e) => {
|
|
@@ -136,9 +136,7 @@ class GeoJSONSource extends Evented implements Source {
|
|
|
136
136
|
generateId: options.generateId || false
|
|
137
137
|
},
|
|
138
138
|
superclusterOptions: {
|
|
139
|
-
maxZoom: options.clusterMaxZoom !== undefined ?
|
|
140
|
-
Math.min(options.clusterMaxZoom, this.maxzoom - 1) :
|
|
141
|
-
(this.maxzoom - 1),
|
|
139
|
+
maxZoom: options.clusterMaxZoom !== undefined ? options.clusterMaxZoom : this.maxzoom - 1,
|
|
142
140
|
minPoints: Math.max(2, options.clusterMinPoints || 2),
|
|
143
141
|
extent: EXTENT,
|
|
144
142
|
radius: (options.clusterRadius || 50) * scale,
|
|
@@ -301,7 +299,7 @@ class GeoJSONSource extends Evented implements Source {
|
|
|
301
299
|
maxZoom: this.maxzoom,
|
|
302
300
|
tileSize: this.tileSize,
|
|
303
301
|
source: this.id,
|
|
304
|
-
pixelRatio:
|
|
302
|
+
pixelRatio: this.map.getPixelRatio(),
|
|
305
303
|
showCollisionBoxes: this.map.showCollisionBoxes,
|
|
306
304
|
promoteId: this.promoteId
|
|
307
305
|
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import ImageSource from './image_source';
|
|
2
|
+
import {Evented} from '../util/evented';
|
|
3
|
+
import Transform from '../geo/transform';
|
|
4
|
+
import {extend} from '../util/util';
|
|
5
|
+
import {useFakeXMLHttpRequest} from 'sinon';
|
|
6
|
+
import {RequestManager} from '../util/request_manager';
|
|
7
|
+
import Dispatcher from '../util/dispatcher';
|
|
8
|
+
import {stubAjaxGetImage} from '../util/test/util';
|
|
9
|
+
|
|
10
|
+
function createSource(options) {
|
|
11
|
+
options = extend({
|
|
12
|
+
coordinates: [[0, 0], [1, 0], [1, 1], [0, 1]]
|
|
13
|
+
}, options);
|
|
14
|
+
|
|
15
|
+
const source = new ImageSource('id', options, {send() {}} as any as Dispatcher, options.eventedParent);
|
|
16
|
+
return source;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class StubMap extends Evented {
|
|
20
|
+
transform: Transform;
|
|
21
|
+
_requestManager: RequestManager;
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.transform = new Transform();
|
|
26
|
+
this._requestManager = {
|
|
27
|
+
transformRequest: (url) => {
|
|
28
|
+
return {url};
|
|
29
|
+
}
|
|
30
|
+
} as any as RequestManager;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('ImageSource', () => {
|
|
35
|
+
const requests = [];
|
|
36
|
+
useFakeXMLHttpRequest().onCreate = (req) => { requests.push(req); };
|
|
37
|
+
stubAjaxGetImage(undefined);
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
global.fetch = null;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const respond = () => {
|
|
43
|
+
const req = requests.shift();
|
|
44
|
+
req.setStatus(200);
|
|
45
|
+
req.response = new ArrayBuffer(1);
|
|
46
|
+
req.onload();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
test('constructor', () => {
|
|
50
|
+
const source = createSource({url : '/image.png'});
|
|
51
|
+
|
|
52
|
+
expect(source.minzoom).toBe(0);
|
|
53
|
+
expect(source.maxzoom).toBe(22);
|
|
54
|
+
expect(source.tileSize).toBe(512);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('fires dataloading event', () => {
|
|
58
|
+
const source = createSource({url : '/image.png'});
|
|
59
|
+
source.on('dataloading', (e) => {
|
|
60
|
+
expect(e.dataType).toBe('source');
|
|
61
|
+
});
|
|
62
|
+
source.onAdd(new StubMap() as any);
|
|
63
|
+
respond();
|
|
64
|
+
expect(source.image).toBeTruthy();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('transforms url request', () => {
|
|
68
|
+
const source = createSource({url : '/image.png'});
|
|
69
|
+
const map = new StubMap() as any;
|
|
70
|
+
const spy = jest.spyOn(map._requestManager, 'transformRequest');
|
|
71
|
+
source.onAdd(map);
|
|
72
|
+
respond();
|
|
73
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect(spy.mock.calls[0][0]).toBe('/image.png');
|
|
75
|
+
expect(spy.mock.calls[0][1]).toBe('Image');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('updates url from updateImage', () => {
|
|
79
|
+
const source = createSource({url : '/image.png'});
|
|
80
|
+
const map = new StubMap() as any;
|
|
81
|
+
const spy = jest.spyOn(map._requestManager, 'transformRequest');
|
|
82
|
+
source.onAdd(map);
|
|
83
|
+
respond();
|
|
84
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(spy.mock.calls[0][0]).toBe('/image.png');
|
|
86
|
+
expect(spy.mock.calls[0][1]).toBe('Image');
|
|
87
|
+
source.updateImage({url: '/image2.png'});
|
|
88
|
+
respond();
|
|
89
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
90
|
+
expect(spy.mock.calls[1][0]).toBe('/image2.png');
|
|
91
|
+
expect(spy.mock.calls[1][1]).toBe('Image');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('sets coordinates', () => {
|
|
95
|
+
const source = createSource({url : '/image.png'});
|
|
96
|
+
const map = new StubMap() as any;
|
|
97
|
+
source.onAdd(map);
|
|
98
|
+
respond();
|
|
99
|
+
const beforeSerialized = source.serialize();
|
|
100
|
+
expect(beforeSerialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
101
|
+
source.setCoordinates([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
102
|
+
const afterSerialized = source.serialize();
|
|
103
|
+
expect(afterSerialized.coordinates).toEqual([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('sets coordinates via updateImage', () => {
|
|
107
|
+
const source = createSource({url : '/image.png'});
|
|
108
|
+
const map = new StubMap() as any;
|
|
109
|
+
source.onAdd(map);
|
|
110
|
+
respond();
|
|
111
|
+
const beforeSerialized = source.serialize();
|
|
112
|
+
expect(beforeSerialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
113
|
+
source.updateImage({
|
|
114
|
+
url: '/image2.png',
|
|
115
|
+
coordinates: [[0, 0], [-1, 0], [-1, -1], [0, -1]]
|
|
116
|
+
});
|
|
117
|
+
respond();
|
|
118
|
+
const afterSerialized = source.serialize();
|
|
119
|
+
expect(afterSerialized.coordinates).toEqual([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('fires data event when content is loaded', done => {
|
|
123
|
+
const source = createSource({url : '/image.png'});
|
|
124
|
+
source.on('data', (e) => {
|
|
125
|
+
if (e.dataType === 'source' && e.sourceDataType === 'content') {
|
|
126
|
+
expect(typeof source.tileID == 'object').toBeTruthy();
|
|
127
|
+
done();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
source.onAdd(new StubMap() as any);
|
|
131
|
+
respond();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('fires data event when metadata is loaded', done => {
|
|
135
|
+
const source = createSource({url : '/image.png'});
|
|
136
|
+
source.on('data', (e) => {
|
|
137
|
+
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
|
|
138
|
+
done();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
source.onAdd(new StubMap() as any);
|
|
142
|
+
respond();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('serialize url and coordinates', () => {
|
|
146
|
+
const source = createSource({url: '/image.png'});
|
|
147
|
+
|
|
148
|
+
const serialized = source.serialize();
|
|
149
|
+
expect(serialized.type).toBe('image');
|
|
150
|
+
expect(serialized.url).toBe('/image.png');
|
|
151
|
+
expect(serialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from './query_features';
|
|
5
5
|
import SourceCache from './source_cache';
|
|
6
6
|
import Transform from '../geo/transform';
|
|
7
|
-
import Point from '
|
|
7
|
+
import Point from '@mapbox/point-geometry';
|
|
8
8
|
import Dispatcher from '../util/dispatcher';
|
|
9
9
|
|
|
10
10
|
describe('QueryFeatures#rendered', () => {
|
|
@@ -4,7 +4,7 @@ import type CollisionIndex from '../symbol/collision_index';
|
|
|
4
4
|
import type Transform from '../geo/transform';
|
|
5
5
|
import type {RetainedQueryData} from '../symbol/placement';
|
|
6
6
|
import type {FilterSpecification} from '../style-spec/types';
|
|
7
|
-
import type Point from '
|
|
7
|
+
import type Point from '@mapbox/point-geometry';
|
|
8
8
|
import assert from 'assert';
|
|
9
9
|
import {mat4} from 'gl-matrix';
|
|
10
10
|
|
|
@@ -10,7 +10,8 @@ function createSource(options, transformCallback?) {
|
|
|
10
10
|
source.onAdd({
|
|
11
11
|
transform: {angle: 0, pitch: 0, showCollisionBoxes: false},
|
|
12
12
|
_getMapId: () => 1,
|
|
13
|
-
_requestManager: new RequestManager(transformCallback)
|
|
13
|
+
_requestManager: new RequestManager(transformCallback),
|
|
14
|
+
getPixelRatio() { return 1; }
|
|
14
15
|
} as any);
|
|
15
16
|
|
|
16
17
|
source.on('error', (e) => {
|
|
@@ -37,7 +37,7 @@ class RasterDEMTileSource extends RasterTileSource implements Source {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
loadTile(tile: Tile, callback: Callback<void>) {
|
|
40
|
-
const url = tile.tileID.canonical.url(this.tiles, this.scheme);
|
|
40
|
+
const url = tile.tileID.canonical.url(this.tiles, this.map.getPixelRatio(), this.scheme);
|
|
41
41
|
tile.request = getImage(this.map._requestManager.transformRequest(url, ResourceType.Tile), imageLoaded.bind(this));
|
|
42
42
|
|
|
43
43
|
tile.neighboringTiles = this._getNeighboringTiles(tile.tileID);
|
|
@@ -10,7 +10,8 @@ function createSource(options, transformCallback?) {
|
|
|
10
10
|
source.onAdd({
|
|
11
11
|
transform: {angle: 0, pitch: 0, showCollisionBoxes: false},
|
|
12
12
|
_getMapId: () => 1,
|
|
13
|
-
_requestManager: new RequestManager(transformCallback)
|
|
13
|
+
_requestManager: new RequestManager(transformCallback),
|
|
14
|
+
getPixelRatio() { return 1; }
|
|
14
15
|
} as any);
|
|
15
16
|
|
|
16
17
|
source.on('error', (e) => {
|
|
@@ -104,7 +104,7 @@ class RasterTileSource extends Evented implements Source {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
loadTile(tile: Tile, callback: Callback<void>) {
|
|
107
|
-
const url = tile.tileID.canonical.url(this.tiles, this.scheme);
|
|
107
|
+
const url = tile.tileID.canonical.url(this.tiles, this.map.getPixelRatio(), this.scheme);
|
|
108
108
|
tile.request = getImage(this.map._requestManager.transformRequest(url, ResourceType.Tile), (err, img) => {
|
|
109
109
|
delete tile.request;
|
|
110
110
|
|
|
@@ -4,7 +4,7 @@ import Tile from './tile';
|
|
|
4
4
|
import {OverscaledTileID} from './tile_id';
|
|
5
5
|
import Transform from '../geo/transform';
|
|
6
6
|
import LngLat from '../geo/lng_lat';
|
|
7
|
-
import Point from '
|
|
7
|
+
import Point from '@mapbox/point-geometry';
|
|
8
8
|
import {Event, ErrorEvent, Evented} from '../util/evented';
|
|
9
9
|
import {extend} from '../util/util';
|
|
10
10
|
import browser from '../util/browser';
|
|
@@ -15,7 +15,7 @@ class SourceMock extends Evented {
|
|
|
15
15
|
id: string;
|
|
16
16
|
minzoom: number;
|
|
17
17
|
maxzoom: number;
|
|
18
|
-
hasTile: (tileID: OverscaledTileID) => boolean
|
|
18
|
+
hasTile: (tileID: OverscaledTileID) => boolean;
|
|
19
19
|
sourceOptions: any;
|
|
20
20
|
|
|
21
21
|
constructor(id: string, sourceOptions: any, _dispatcher, eventedParent: Evented) {
|
|
@@ -7,7 +7,7 @@ import MercatorCoordinate from '../geo/mercator_coordinate';
|
|
|
7
7
|
import {keysDifference} from '../util/util';
|
|
8
8
|
import EXTENT from '../data/extent';
|
|
9
9
|
import Context from '../gl/context';
|
|
10
|
-
import Point from '
|
|
10
|
+
import Point from '@mapbox/point-geometry';
|
|
11
11
|
import browser from '../util/browser';
|
|
12
12
|
import {OverscaledTileID} from './tile_id';
|
|
13
13
|
import assert from 'assert';
|
package/src/source/tile.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {createSymbolBucket} from '../../test/util/
|
|
1
|
+
import {createSymbolBucket} from '../../test/util/create_symbol_layer';
|
|
2
2
|
import Tile from '../source/tile';
|
|
3
3
|
import GeoJSONWrapper, {Feature} from '../source/geojson_wrapper';
|
|
4
4
|
import {OverscaledTileID} from '../source/tile_id';
|
package/src/source/tile.ts
CHANGED
|
@@ -30,7 +30,7 @@ import type Transform from '../geo/transform';
|
|
|
30
30
|
import type {LayerFeatureStates} from './source_state';
|
|
31
31
|
import type {Cancelable} from '../types/cancelable';
|
|
32
32
|
import type {FilterSpecification} from '../style-spec/types';
|
|
33
|
-
import type Point from '
|
|
33
|
+
import type Point from '@mapbox/point-geometry';
|
|
34
34
|
import {mat4} from 'gl-matrix';
|
|
35
35
|
import type {VectorTileLayer} from '@mapbox/vector-tile';
|
|
36
36
|
|
|
@@ -33,35 +33,33 @@ describe('CanonicalTileID', () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('.url replaces {z}/{x}/{y}', () => {
|
|
36
|
-
expect(new CanonicalTileID(2, 1, 0).url(['{z}/{x}/{y}.json'])).toBe('2/1/0.json');
|
|
36
|
+
expect(new CanonicalTileID(2, 1, 0).url(['{z}/{x}/{y}.json'], 1)).toBe('2/1/0.json');
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
test('.url replaces {quadkey}', () => {
|
|
40
|
-
expect(new CanonicalTileID(1, 0, 0).url(['quadkey={quadkey}'])).toBe('quadkey=0');
|
|
41
|
-
expect(new CanonicalTileID(2, 0, 0).url(['quadkey={quadkey}'])).toBe('quadkey=00');
|
|
42
|
-
expect(new CanonicalTileID(2, 1, 1).url(['quadkey={quadkey}'])).toBe('quadkey=03');
|
|
43
|
-
expect(new CanonicalTileID(17, 22914, 52870).url(['quadkey={quadkey}'])).toBe('quadkey=02301322130000230');
|
|
40
|
+
expect(new CanonicalTileID(1, 0, 0).url(['quadkey={quadkey}'], 1)).toBe('quadkey=0');
|
|
41
|
+
expect(new CanonicalTileID(2, 0, 0).url(['quadkey={quadkey}'], 1)).toBe('quadkey=00');
|
|
42
|
+
expect(new CanonicalTileID(2, 1, 1).url(['quadkey={quadkey}'], 1)).toBe('quadkey=03');
|
|
43
|
+
expect(new CanonicalTileID(17, 22914, 52870).url(['quadkey={quadkey}'], 1)).toBe('quadkey=02301322130000230');
|
|
44
44
|
|
|
45
45
|
// Test case confirmed by quadkeytools package
|
|
46
46
|
// https://bitbucket.org/steele/quadkeytools/rollup/build/tsc/src/master/test/quadkey.js?fileviewer=file-view-default#quadkey.js-57
|
|
47
|
-
expect(new CanonicalTileID(6, 29, 3).url(['quadkey={quadkey}'])).toBe('quadkey=011123');
|
|
47
|
+
expect(new CanonicalTileID(6, 29, 3).url(['quadkey={quadkey}'], 1)).toBe('quadkey=011123');
|
|
48
48
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('.url replaces {bbox-epsg-3857}', () => {
|
|
52
|
-
expect(new CanonicalTileID(1, 0, 0).url(['bbox={bbox-epsg-3857}'])).toBe('bbox=-20037508.342789244,0,0,20037508.342789244');
|
|
52
|
+
expect(new CanonicalTileID(1, 0, 0).url(['bbox={bbox-epsg-3857}'], 1)).toBe('bbox=-20037508.342789244,0,0,20037508.342789244');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
test('.url replaces {ratio}', () => {
|
|
56
|
-
|
|
57
|
-
expect(new CanonicalTileID(1, 0, 0).url(['r={ratio}'])).toBe('r
|
|
58
|
-
devicePixelRatio = 1;
|
|
59
|
-
expect(new CanonicalTileID(1, 0, 0).url(['r={ratio}'])).toBe('r=');
|
|
56
|
+
expect(new CanonicalTileID(1, 0, 0).url(['r={ratio}'], 2)).toBe('r=@2x');
|
|
57
|
+
expect(new CanonicalTileID(1, 0, 0).url(['r={ratio}'], 1)).toBe('r=');
|
|
60
58
|
});
|
|
61
59
|
|
|
62
60
|
//Tests that multiple values of the same placeholder are replaced.
|
|
63
61
|
test('.url replaces {z}/{x}/{y}/{z}/{x}/{y}', () => {
|
|
64
|
-
expect(new CanonicalTileID(2, 1, 0).url(['{z}/{x}/{y}/{z}/{x}/{y}.json'])).toBe('2/1/0/2/1/0.json');
|
|
62
|
+
expect(new CanonicalTileID(2, 1, 0).url(['{z}/{x}/{y}/{z}/{x}/{y}.json'], 1)).toBe('2/1/0/2/1/0.json');
|
|
65
63
|
});
|
|
66
64
|
|
|
67
65
|
});
|
package/src/source/tile_id.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {getTileBBox} from '@mapbox/whoots-js';
|
|
2
2
|
import EXTENT from '../data/extent';
|
|
3
|
-
import Point from '
|
|
3
|
+
import Point from '@mapbox/point-geometry';
|
|
4
4
|
import MercatorCoordinate from '../geo/mercator_coordinate';
|
|
5
5
|
|
|
6
6
|
import assert from 'assert';
|
|
@@ -28,7 +28,7 @@ export class CanonicalTileID {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// given a list of urls, choose a url template and return a tile URL
|
|
31
|
-
url(urls: Array<string>, scheme?: string | null) {
|
|
31
|
+
url(urls: Array<string>, pixelRatio: number, scheme?: string | null) {
|
|
32
32
|
const bbox = getTileBBox(this.x, this.y, this.z);
|
|
33
33
|
const quadkey = getQuadkey(this.z, this.x, this.y);
|
|
34
34
|
|
|
@@ -37,7 +37,7 @@ export class CanonicalTileID {
|
|
|
37
37
|
.replace(/{z}/g, String(this.z))
|
|
38
38
|
.replace(/{x}/g, String(this.x))
|
|
39
39
|
.replace(/{y}/g, String(scheme === 'tms' ? (Math.pow(2, this.z) - this.y - 1) : this.y))
|
|
40
|
-
.replace(/{ratio}/g,
|
|
40
|
+
.replace(/{ratio}/g, pixelRatio > 1 ? '@2x' : '')
|
|
41
41
|
.replace(/{quadkey}/g, quadkey)
|
|
42
42
|
.replace(/{bbox-epsg-3857}/g, bbox);
|
|
43
43
|
}
|
|
@@ -15,7 +15,8 @@ function createSource(options, transformCallback?) {
|
|
|
15
15
|
transform: {showCollisionBoxes: false},
|
|
16
16
|
_getMapId: () => 1,
|
|
17
17
|
_requestManager: new RequestManager(transformCallback),
|
|
18
|
-
style: {sourceCaches: {id: {clearTiles: () => {}}}}
|
|
18
|
+
style: {sourceCaches: {id: {clearTiles: () => {}}}},
|
|
19
|
+
getPixelRatio() { return 1; }
|
|
19
20
|
} as any as Map);
|
|
20
21
|
|
|
21
22
|
source.on('error', (e) => {
|
|
@@ -178,7 +178,7 @@ class VectorTileSource extends Evented implements Source {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
loadTile(tile: Tile, callback: Callback<void>) {
|
|
181
|
-
const url = tile.tileID.canonical.url(this.tiles, this.scheme);
|
|
181
|
+
const url = tile.tileID.canonical.url(this.tiles, this.map.getPixelRatio(), this.scheme);
|
|
182
182
|
const params = {
|
|
183
183
|
request: this.map._requestManager.transformRequest(url, ResourceType.Tile),
|
|
184
184
|
uid: tile.uid,
|
|
@@ -187,7 +187,7 @@ class VectorTileSource extends Evented implements Source {
|
|
|
187
187
|
tileSize: this.tileSize * tile.tileID.overscaleFactor(),
|
|
188
188
|
type: this.type,
|
|
189
189
|
source: this.id,
|
|
190
|
-
pixelRatio:
|
|
190
|
+
pixelRatio: this.map.getPixelRatio(),
|
|
191
191
|
showCollisionBoxes: this.map.showCollisionBoxes,
|
|
192
192
|
promoteId: this.promoteId
|
|
193
193
|
};
|