maplibre-gl 6.0.0 → 6.2.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/readme.md +0 -2
- package/dist/maplibre-gl-dev.mjs +433 -573
- package/dist/maplibre-gl-dev.mjs.map +1 -1
- package/dist/maplibre-gl-shared-dev.mjs +984 -850
- package/dist/maplibre-gl-shared-dev.mjs.map +1 -1
- package/dist/maplibre-gl-shared.mjs +2 -2
- package/dist/maplibre-gl-shared.mjs.map +1 -1
- package/dist/maplibre-gl-worker-dev.mjs +14 -12
- package/dist/maplibre-gl-worker-dev.mjs.map +1 -1
- package/dist/maplibre-gl-worker.mjs +2 -2
- package/dist/maplibre-gl-worker.mjs.map +1 -1
- package/dist/maplibre-gl.css +1 -1
- package/dist/maplibre-gl.d.ts +119 -42
- package/dist/maplibre-gl.mjs +22 -22
- package/dist/maplibre-gl.mjs.map +1 -1
- package/package.json +20 -22
- package/src/css/maplibre-gl.css +4 -0
- package/src/data/bucket/circle_bucket.ts +3 -2
- package/src/data/bucket/fill_bucket.ts +3 -2
- package/src/data/bucket/fill_extrusion_bucket.test.ts +22 -0
- package/src/data/bucket/fill_extrusion_bucket.ts +17 -4
- package/src/data/bucket/line_bucket.test.ts +5 -5
- package/src/data/bucket/line_bucket.ts +3 -2
- package/src/data/bucket/round_polygon_corners.test.ts +159 -0
- package/src/data/bucket/round_polygon_corners.ts +121 -0
- package/src/data/bucket/symbol_bucket.test.ts +7 -7
- package/src/data/dem_data.test.ts +23 -23
- package/src/data/feature_position_map.test.ts +1 -1
- package/src/data/segment.test.ts +14 -14
- package/src/geo/bounds.test.ts +4 -4
- package/src/geo/lng_lat_bounds.test.ts +1 -1
- package/src/geo/projection/covering_tiles.bench.ts +39 -0
- package/src/geo/projection/covering_tiles.test.ts +3 -7
- package/src/geo/projection/covering_tiles.ts +37 -2
- package/src/geo/projection/globe_covering_tiles_details_provider.ts +4 -4
- package/src/geo/projection/globe_projection.test.ts +2 -2
- package/src/geo/projection/globe_projection.ts +6 -15
- package/src/geo/projection/globe_transform.test.ts +3 -6
- package/src/geo/projection/globe_transform.ts +4 -7
- package/src/geo/projection/mercator_covering_tiles_details_provider.ts +4 -4
- package/src/geo/projection/mercator_projection.ts +1 -13
- package/src/geo/projection/mercator_transform.test.ts +1 -1
- package/src/geo/projection/mercator_transform.ts +2 -1
- package/src/geo/projection/mercator_utils.test.ts +8 -8
- package/src/geo/projection/projection.ts +0 -27
- package/src/geo/projection/projection_data.ts +8 -0
- package/src/geo/projection/projection_factory.ts +3 -3
- package/src/geo/projection/vertical_perspective_projection.ts +3 -60
- package/src/geo/projection/vertical_perspective_transform.ts +16 -23
- package/src/geo/transform_interface.ts +1 -2
- package/src/index.test.ts +7 -12
- package/src/index.ts +4 -2
- package/src/render/glyph_manager.test.ts +7 -22
- package/src/render/painter.test.ts +2 -0
- package/src/render/painter.ts +8 -11
- package/src/render/subdivision.bench.ts +39 -0
- package/src/render/subdivision.test.ts +22 -23
- package/src/render/subdivision.ts +46 -0
- package/src/render/terrain.test.ts +68 -34
- package/src/render/terrain.ts +69 -26
- package/src/shaders/glsl/_projection_globe.fragment.glsl +12 -0
- package/src/shaders/glsl/_projection_globe.fragment.glsl.g.ts +2 -0
- package/src/shaders/glsl/_projection_globe.vertex.glsl +29 -10
- package/src/shaders/glsl/_projection_globe.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/_projection_mercator.fragment.glsl +4 -0
- package/src/shaders/glsl/_projection_mercator.fragment.glsl.g.ts +2 -0
- package/src/shaders/glsl/line.fragment.glsl +2 -0
- package/src/shaders/glsl/line.fragment.glsl.g.ts +1 -1
- package/src/shaders/glsl/line_gradient.fragment.glsl +2 -0
- package/src/shaders/glsl/line_gradient.fragment.glsl.g.ts +1 -1
- package/src/shaders/glsl/line_gradient_sdf.fragment.glsl +2 -0
- package/src/shaders/glsl/line_gradient_sdf.fragment.glsl.g.ts +1 -1
- package/src/shaders/glsl/line_pattern.fragment.glsl +2 -0
- package/src/shaders/glsl/line_pattern.fragment.glsl.g.ts +1 -1
- package/src/shaders/glsl/line_sdf.fragment.glsl +2 -0
- package/src/shaders/glsl/line_sdf.fragment.glsl.g.ts +1 -1
- package/src/shaders/shaders.ts +4 -6
- package/src/source/canvas_source.test.ts +1 -1
- package/src/source/geojson_source.test.ts +32 -4
- package/src/source/geojson_source.ts +41 -0
- package/src/source/geojson_source_diff.test.ts +2 -2
- package/src/source/geojson_worker_source.test.ts +9 -5
- package/src/source/image_source.test.ts +137 -62
- package/src/source/image_source.ts +49 -12
- package/src/source/raster_dem_tile_source.test.ts +2 -2
- package/src/source/raster_tile_source.test.ts +64 -9
- package/src/source/raster_tile_source.ts +2 -1
- package/src/source/rtl_text_plugin_main_thread.test.ts +14 -14
- package/src/source/source.test.ts +8 -8
- package/src/source/vector_tile_source.test.ts +1 -1
- package/src/source/vector_tile_worker_source.test.ts +7 -5
- package/src/source/video_source.test.ts +1 -1
- package/src/source/worker.test.ts +1 -1
- package/src/source/worker_tile.test.ts +10 -8
- package/src/style/light.test.ts +9 -9
- package/src/style/light.ts +3 -3
- package/src/style/load_glyph_range.test.ts +8 -8
- package/src/style/load_sprite.test.ts +1 -1
- package/src/style/properties.test.ts +94 -2
- package/src/style/properties.ts +30 -1
- package/src/style/sky.test.ts +9 -9
- package/src/style/sky.ts +2 -2
- package/src/style/style.test.ts +38 -36
- package/src/style/style.ts +3 -3
- package/src/style/style_layer/color_relief_style_layer.test.ts +1 -1
- package/src/style/style_layer/fill_extrusion_style_layer.ts +6 -3
- package/src/style/style_layer/fill_extrusion_style_layer_properties.g.ts +14 -1
- package/src/style/style_layer/raster_style_layer.test.ts +2 -2
- package/src/style/style_layer.test.ts +5 -51
- package/src/style/validate_style.test.ts +1 -1
- package/src/symbol/collision_index.test.ts +1 -1
- package/src/symbol/grid_index.test.ts +1 -1
- package/src/tile/terrain_tile_manager.test.ts +2 -2
- package/src/tile/tile_id.test.ts +5 -5
- package/src/tile/tile_manager.test.ts +113 -72
- package/src/tile/tile_manager.ts +2 -2
- package/src/tile/tile_manager_in_view_tiles.test.ts +2 -2
- package/src/ui/camera.test.ts +138 -135
- package/src/ui/control/geolocate_control.test.ts +7 -30
- package/src/ui/handler/dblclick_zoom.test.ts +2 -2
- package/src/ui/handler/mouse.ts +15 -7
- package/src/ui/handler/mouse_handler_interface.test.ts +21 -1
- package/src/ui/handler/scroll_zoom.test.ts +2 -0
- package/src/ui/handler_manager.test.ts +7 -7
- package/src/ui/hash.test.ts +1 -0
- package/src/ui/map.ts +45 -20
- package/src/ui/map_tests/map_basic.test.ts +11 -23
- package/src/ui/map_tests/map_calculate_camera_options.test.ts +6 -6
- package/src/ui/map_tests/map_events.test.ts +5 -7
- package/src/ui/map_tests/map_global_state.test.ts +3 -3
- package/src/ui/map_tests/map_images.test.ts +4 -3
- package/src/ui/map_tests/map_is_moving.test.ts +1 -1
- package/src/ui/map_tests/map_is_rotating.test.ts +1 -1
- package/src/ui/map_tests/map_layer.test.ts +2 -1
- package/src/ui/map_tests/map_options.test.ts +1 -5
- package/src/ui/map_tests/map_pitch.test.ts +6 -6
- package/src/ui/map_tests/map_refresh_tiles.test.ts +2 -2
- package/src/ui/map_tests/map_render.test.ts +1 -1
- package/src/ui/map_tests/map_set_lod_params.test.ts +1 -1
- package/src/ui/map_tests/map_style.test.ts +9 -1
- package/src/ui/map_tests/map_terrain.test.ts +41 -1
- package/src/ui/map_tests/map_zoom.test.ts +15 -15
- package/src/ui/marker.test.ts +71 -14
- package/src/ui/marker.ts +30 -6
- package/src/ui/popup.test.ts +3 -3
- package/src/util/actor.test.ts +6 -6
- package/src/util/ajax.test.ts +27 -39
- package/src/util/browser.test.ts +7 -9
- package/src/util/create_tile_mesh.test.ts +2 -2
- package/src/util/dispatcher.test.ts +1 -1
- package/src/util/evented.test.ts +4 -1
- package/src/util/fast_maths.test.ts +4 -4
- package/src/util/image_request.test.ts +6 -4
- package/src/util/primitives/bounding_volume_cache.ts +3 -1
- package/src/util/struct_array.test.ts +2 -2
- package/src/util/task_queue.test.ts +1 -1
- package/src/util/test/util.ts +1 -0
- package/src/util/time_control.test.ts +2 -2
- package/src/util/transferable_grid_index.test.ts +1 -1
- package/src/util/util.test.ts +27 -13
- package/src/util/verticalize_punctuation.test.ts +4 -4
- package/src/util/web_worker_transfer.test.ts +5 -5
- package/src/webgl/draw/draw_custom.test.ts +13 -13
- package/src/webgl/draw/draw_debug.test.ts +1 -1
- package/src/webgl/draw/draw_fill.test.ts +13 -12
- package/src/webgl/draw/draw_symbol.test.ts +17 -16
- package/src/webgl/program/program_uniforms.ts +0 -3
- package/src/webgl/program/projection_program.ts +12 -10
- package/src/webgl/program/terrain_program.test.ts +2 -2
- package/src/webgl/program.ts +6 -4
- package/src/webgl/render_to_texture.test.ts +5 -5
- package/src/webgl/state.test.ts +1 -1
- package/src/webgl/texture.test.ts +3 -3
- package/src/webgl/vertex_buffer.test.ts +1 -1
- package/build/rolldown_plugins.ts +0 -18
- package/src/geo/projection/globe_projection_error_measurement.ts +0 -229
- package/src/shaders/glsl/projection_error_measurement.fragment.glsl +0 -5
- package/src/shaders/glsl/projection_error_measurement.fragment.glsl.g.ts +0 -2
- package/src/shaders/glsl/projection_error_measurement.vertex.glsl +0 -22
- package/src/shaders/glsl/projection_error_measurement.vertex.glsl.g.ts +0 -2
- package/src/webgl/program/projection_error_measurement_program.ts +0 -23
|
@@ -5,6 +5,9 @@ uniform highp vec4 u_projection_clipping_plane;
|
|
|
5
5
|
uniform highp float u_projection_transition;
|
|
6
6
|
uniform mat4 u_projection_fallback_matrix;
|
|
7
7
|
|
|
8
|
+
// The in-tile X coordinate of the projected vertex, used by clipAntimeridian() in the fragment shader (see _projection_globe.fragment.glsl).
|
|
9
|
+
out highp float v_projection_tile_x;
|
|
10
|
+
|
|
8
11
|
vec3 globeRotateVector(vec3 vec, vec2 angles) {
|
|
9
12
|
vec3 axisRight = vec3(vec.z, 0.0, -vec.x); // Equivalent to cross(vec3(0.0, 1.0, 0.0), vec)
|
|
10
13
|
vec3 axisUp = cross(axisRight, vec);
|
|
@@ -30,12 +33,13 @@ mat3 globeGetRotationMatrix(vec3 spherePos) {
|
|
|
30
33
|
// Use `projectLineThickness` or `projectCircleRadius` instead.
|
|
31
34
|
float circumferenceRatioAtTileY(float tileY) {
|
|
32
35
|
float mercator_pos_y = u_projection_tile_mercator_coords.y + u_projection_tile_mercator_coords.w * tileY;
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
// cos(spherical_y) derived algebraically from exp(), see projectToSphere below.
|
|
37
|
+
float t = exp(PI - (mercator_pos_y * PI * 2.0));
|
|
38
|
+
return (2.0 * t) / (t * t + 1.0);
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
float projectLineThickness(float tileY) {
|
|
38
|
-
float thickness = 1.0 / circumferenceRatioAtTileY(tileY);
|
|
42
|
+
float thickness = 1.0 / circumferenceRatioAtTileY(tileY);
|
|
39
43
|
if (u_projection_transition < 0.999) {
|
|
40
44
|
return mix(1.0, thickness, u_projection_transition);
|
|
41
45
|
} else {
|
|
@@ -52,15 +56,28 @@ vec3 projectToSphere(vec2 translatedPos, vec2 rawPos) {
|
|
|
52
56
|
vec2 mercator_pos = u_projection_tile_mercator_coords.xy + u_projection_tile_mercator_coords.zw * translatedPos;
|
|
53
57
|
|
|
54
58
|
// Now compute angular coordinates on the surface of a perfect sphere
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
float spherical_x = mercator_pos.x * PI * 2.0 + PI;
|
|
60
|
+
|
|
61
|
+
// sin_sy/cos_sy are sin(spherical_y)/cos(spherical_y), where
|
|
62
|
+
// spherical_y = 2*atan(exp(PI - mercator_pos.y*2*PI)) - PI/2 (the Gudermannian
|
|
63
|
+
// function, converting mercator Y to latitude). The direct formula subtracts
|
|
64
|
+
// PI/2 from a value near PI/2, destroying most float32 mantissa bits near the
|
|
65
|
+
// equator, and some GPUs (e.g. Mali) have imprecise atan/sin/cos besides.
|
|
66
|
+
// Substituting t = exp(PI - mercator_pos.y*2*PI) and expanding via the
|
|
67
|
+
// tangent half-angle (Weierstrass) identities eliminates atan, sin and cos
|
|
68
|
+
// entirely, leaving only exp() and rational arithmetic:
|
|
69
|
+
// sin(2*atan(t) - PI/2) = (t^2 - 1) / (t^2 + 1)
|
|
70
|
+
// cos(2*atan(t) - PI/2) = 2*t / (t^2 + 1)
|
|
71
|
+
float t = exp(PI - (mercator_pos.y * PI * 2.0));
|
|
72
|
+
float t2 = t * t;
|
|
73
|
+
float denom = t2 + 1.0;
|
|
74
|
+
float sin_sy = (t2 - 1.0) / denom;
|
|
75
|
+
float cos_sy = (2.0 * t) / denom;
|
|
58
76
|
|
|
59
|
-
float len = cos(spherical.y);
|
|
60
77
|
vec3 pos = vec3(
|
|
61
|
-
sin(
|
|
62
|
-
|
|
63
|
-
cos(
|
|
78
|
+
sin(spherical_x) * cos_sy,
|
|
79
|
+
sin_sy,
|
|
80
|
+
cos(spherical_x) * cos_sy
|
|
64
81
|
);
|
|
65
82
|
|
|
66
83
|
// North pole
|
|
@@ -84,6 +101,7 @@ float globeComputeClippingZ(vec3 spherePos) {
|
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
vec4 interpolateProjection(vec2 posInTile, vec3 spherePos, float elevation) {
|
|
104
|
+
v_projection_tile_x = posInTile.x;
|
|
87
105
|
vec3 elevatedPos = spherePos * (1.0 + elevation / GLOBE_RADIUS);
|
|
88
106
|
vec4 globePosition = u_projection_matrix * vec4(elevatedPos, 1.0);
|
|
89
107
|
// Z is overwritten by glDepthRange anyway - use a custom z value to clip geometry on the invisible side of the sphere.
|
|
@@ -113,6 +131,7 @@ vec4 interpolateProjection(vec2 posInTile, vec3 spherePos, float elevation) {
|
|
|
113
131
|
|
|
114
132
|
// Unlike interpolateProjection, this variant of the function preserves the Z value of the final vector.
|
|
115
133
|
vec4 interpolateProjectionFor3D(vec2 posInTile, vec3 spherePos, float elevation) {
|
|
134
|
+
v_projection_tile_x = posInTile.x;
|
|
116
135
|
vec3 elevatedPos = spherePos * (1.0 + elevation / GLOBE_RADIUS);
|
|
117
136
|
vec4 globePosition = u_projection_matrix * vec4(elevatedPos, 1.0);
|
|
118
137
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default '#define GLOBE_RADIUS 6371008.8\nuniform highp vec4 u_projection_tile_mercator_coords;uniform highp vec4 u_projection_clipping_plane;uniform highp float u_projection_transition;uniform mat4 u_projection_fallback_matrix;vec3 globeRotateVector(vec3 vec,vec2 angles) {vec3 axisRight=vec3(vec.z,0.0,-vec.x);vec3 axisUp=cross(axisRight,vec);axisRight=normalize(axisRight);axisUp=normalize(axisUp);vec2 t=tan(angles);return normalize(vec+axisRight*t.x+axisUp*t.y);}mat3 globeGetRotationMatrix(vec3 spherePos) {vec3 axisRight=vec3(spherePos.z,0.0,-spherePos.x);vec3 axisDown=cross(axisRight,spherePos);axisRight=normalize(axisRight);axisDown=normalize(axisDown);return mat3(axisRight,axisDown,spherePos\n);}float circumferenceRatioAtTileY(float tileY) {float mercator_pos_y=u_projection_tile_mercator_coords.y+u_projection_tile_mercator_coords.w*tileY;float
|
|
2
|
+
export default '#define GLOBE_RADIUS 6371008.8\nuniform highp vec4 u_projection_tile_mercator_coords;uniform highp vec4 u_projection_clipping_plane;uniform highp float u_projection_transition;uniform mat4 u_projection_fallback_matrix;out highp float v_projection_tile_x;vec3 globeRotateVector(vec3 vec,vec2 angles) {vec3 axisRight=vec3(vec.z,0.0,-vec.x);vec3 axisUp=cross(axisRight,vec);axisRight=normalize(axisRight);axisUp=normalize(axisUp);vec2 t=tan(angles);return normalize(vec+axisRight*t.x+axisUp*t.y);}mat3 globeGetRotationMatrix(vec3 spherePos) {vec3 axisRight=vec3(spherePos.z,0.0,-spherePos.x);vec3 axisDown=cross(axisRight,spherePos);axisRight=normalize(axisRight);axisDown=normalize(axisDown);return mat3(axisRight,axisDown,spherePos\n);}float circumferenceRatioAtTileY(float tileY) {float mercator_pos_y=u_projection_tile_mercator_coords.y+u_projection_tile_mercator_coords.w*tileY;float t=exp(PI-(mercator_pos_y*PI*2.0));return (2.0*t)/(t*t+1.0);}float projectLineThickness(float tileY) {float thickness=1.0/circumferenceRatioAtTileY(tileY);if (u_projection_transition < 0.999) {return mix(1.0,thickness,u_projection_transition);} else {return thickness;}}vec3 projectToSphere(vec2 translatedPos,vec2 rawPos) {vec2 mercator_pos=u_projection_tile_mercator_coords.xy+u_projection_tile_mercator_coords.zw*translatedPos;float spherical_x=mercator_pos.x*PI*2.0+PI;float t=exp(PI-(mercator_pos.y*PI*2.0));float t2=t*t;float denom=t2+1.0;float sin_sy=(t2-1.0)/denom;float cos_sy=(2.0*t)/denom;vec3 pos=vec3(sin(spherical_x)*cos_sy,sin_sy,cos(spherical_x)*cos_sy\n);if (rawPos.y <-32767.5) {pos=vec3(0.0,1.0,0.0);}if (rawPos.y > 32766.5) {pos=vec3(0.0,-1.0,0.0);}return pos;}vec3 projectToSphere(vec2 posInTile) {return projectToSphere(posInTile,vec2(0.0,0.0));}float globeComputeClippingZ(vec3 spherePos) {return (1.0-(dot(spherePos,u_projection_clipping_plane.xyz)+u_projection_clipping_plane.w));}vec4 interpolateProjection(vec2 posInTile,vec3 spherePos,float elevation) {v_projection_tile_x=posInTile.x;vec3 elevatedPos=spherePos*(1.0+elevation/GLOBE_RADIUS);vec4 globePosition=u_projection_matrix*vec4(elevatedPos,1.0);globePosition.z=globeComputeClippingZ(elevatedPos)*globePosition.w;if (u_projection_transition > 0.999) {return globePosition;}vec4 flatPosition=u_projection_fallback_matrix*vec4(posInTile,elevation,1.0);const float z_globeness_threshold=0.2;vec4 result=globePosition;result.z=mix(0.0,globePosition.z,clamp((u_projection_transition-z_globeness_threshold)/(1.0-z_globeness_threshold),0.0,1.0));result.xyw=mix(flatPosition.xyw,globePosition.xyw,u_projection_transition);if ((posInTile.y <-32767.5) || (posInTile.y > 32766.5)) {result=globePosition;const float poles_hidden_anim_percentage=0.02;result.z=mix(globePosition.z,100.0,pow(max((1.0-u_projection_transition)/poles_hidden_anim_percentage,0.0),8.0));}return result;}vec4 interpolateProjectionFor3D(vec2 posInTile,vec3 spherePos,float elevation) {v_projection_tile_x=posInTile.x;vec3 elevatedPos=spherePos*(1.0+elevation/GLOBE_RADIUS);vec4 globePosition=u_projection_matrix*vec4(elevatedPos,1.0);if (u_projection_transition > 0.999) {return globePosition;}vec4 fallbackPosition=u_projection_fallback_matrix*vec4(posInTile,elevation,1.0);return mix(fallbackPosition,globePosition,u_projection_transition);}vec4 projectTile(vec2 posInTile) {return interpolateProjection(posInTile,projectToSphere(posInTile),0.0);}vec4 projectTile(vec2 posInTile,vec2 rawPos) {return interpolateProjection(posInTile,projectToSphere(posInTile,rawPos),0.0);}vec4 projectTileWithElevation(vec2 posInTile,float elevation) {return interpolateProjection(posInTile,projectToSphere(posInTile),elevation);}vec4 projectTileFor3D(vec2 posInTile,float elevation) {vec3 spherePos=projectToSphere(posInTile,posInTile);return interpolateProjectionFor3D(posInTile,spherePos,elevation);}';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default 'uniform lowp float u_device_pixel_ratio;flat in vec2 v_width2;in vec2 v_normal;in float v_gamma_scale;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\
|
|
2
|
+
export default 'uniform lowp float u_device_pixel_ratio;flat in vec2 v_width2;in vec2 v_normal;in float v_gamma_scale;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nclipAntimeridian();float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;flat in vec2 v_width2;in vec2 v_normal;in float v_gamma_scale;in highp vec2 v_uv;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\
|
|
2
|
+
export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;flat in vec2 v_width2;in vec2 v_normal;in float v_gamma_scale;in highp vec2 v_uv;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nclipAntimeridian();float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture(u_image,v_uv);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -29,6 +29,8 @@ void main() {
|
|
|
29
29
|
#pragma maplibre: initialize mediump vec4 dasharray_from
|
|
30
30
|
#pragma maplibre: initialize mediump vec4 dasharray_to
|
|
31
31
|
|
|
32
|
+
clipAntimeridian();
|
|
33
|
+
|
|
32
34
|
// Calculate the distance of the pixel from the line in pixels.
|
|
33
35
|
float dist = length(v_normal) * v_width2.s;
|
|
34
36
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;uniform sampler2D u_image_dash;uniform float u_mix;uniform lowp float u_lineatlas_width;in vec2 v_normal;flat in vec2 v_width2;in vec2 v_tex_a;in vec2 v_tex_b;in float v_gamma_scale;in highp vec2 v_uv;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\
|
|
2
|
+
export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;uniform sampler2D u_image_dash;uniform float u_mix;uniform lowp float u_lineatlas_width;in vec2 v_normal;flat in vec2 v_width2;in vec2 v_tex_a;in vec2 v_tex_b;in float v_gamma_scale;in highp vec2 v_uv;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\nclipAntimeridian();float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture(u_image,v_uv);float sdfdist_a=texture(u_image_dash,v_tex_a).a;float sdfdist_b=texture(u_image_dash,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);float sdfgamma=(u_lineatlas_width/256.0)/min(dasharray_from.w,dasharray_to.w);float dash_alpha=smoothstep(0.5-sdfgamma/floorwidth,0.5+sdfgamma/floorwidth,sdfdist);fragColor=color*(alpha*dash_alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default '#ifdef GL_ES\nprecision highp float;\n#endif\nuniform lowp float u_device_pixel_ratio;uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec3 u_scale;uniform sampler2D u_image;in vec2 v_normal;flat in vec2 v_width2;in float v_linesofar;in float v_gamma_scale;flat in float v_width;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp vec4 pattern_from\n#pragma maplibre: define lowp vec4 pattern_to\n#pragma maplibre: define lowp float pixel_ratio_from\n#pragma maplibre: define lowp float pixel_ratio_to\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize mediump vec4 pattern_from\n#pragma maplibre: initialize mediump vec4 pattern_to\n#pragma maplibre: initialize lowp float pixel_ratio_from\n#pragma maplibre: initialize lowp float pixel_ratio_to\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\
|
|
2
|
+
export default '#ifdef GL_ES\nprecision highp float;\n#endif\nuniform lowp float u_device_pixel_ratio;uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec3 u_scale;uniform sampler2D u_image;in vec2 v_normal;flat in vec2 v_width2;in float v_linesofar;in float v_gamma_scale;flat in float v_width;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp vec4 pattern_from\n#pragma maplibre: define lowp vec4 pattern_to\n#pragma maplibre: define lowp float pixel_ratio_from\n#pragma maplibre: define lowp float pixel_ratio_to\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize mediump vec4 pattern_from\n#pragma maplibre: initialize mediump vec4 pattern_to\n#pragma maplibre: initialize lowp float pixel_ratio_from\n#pragma maplibre: initialize lowp float pixel_ratio_to\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nclipAntimeridian();vec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileZoomRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;vec2 pattern_size_a=vec2(display_size_a.x*fromScale/tileZoomRatio,display_size_a.y);vec2 pattern_size_b=vec2(display_size_b.x*toScale/tileZoomRatio,display_size_b.y);float aspect_a=display_size_a.y/v_width;float aspect_b=display_size_b.y/v_width;float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float x_a=mod(v_linesofar/pattern_size_a.x*aspect_a,1.0);float x_b=mod(v_linesofar/pattern_size_b.x*aspect_b,1.0);float y=0.5*v_normal.y+0.5;vec2 texel_size=1.0/u_texsize;vec2 pos_a=mix(pattern_tl_a*texel_size-texel_size,pattern_br_a*texel_size+texel_size,vec2(x_a,y));vec2 pos_b=mix(pattern_tl_b*texel_size-texel_size,pattern_br_b*texel_size+texel_size,vec2(x_b,y));vec4 color=mix(texture(u_image,pos_a),texture(u_image,pos_b),u_fade);fragColor=color*alpha*opacity;\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -30,6 +30,8 @@ void main() {
|
|
|
30
30
|
#pragma maplibre: initialize mediump vec4 dasharray_from
|
|
31
31
|
#pragma maplibre: initialize mediump vec4 dasharray_to
|
|
32
32
|
|
|
33
|
+
clipAntimeridian();
|
|
34
|
+
|
|
33
35
|
// Calculate the distance of the pixel from the line in pixels.
|
|
34
36
|
float dist = length(v_normal) * v_width2.s;
|
|
35
37
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default 'uniform lowp float u_device_pixel_ratio;uniform lowp float u_lineatlas_width;uniform sampler2D u_image;uniform float u_mix;in vec2 v_normal;flat in vec2 v_width2;in vec2 v_tex_a;in vec2 v_tex_b;in float v_gamma_scale;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\
|
|
2
|
+
export default 'uniform lowp float u_device_pixel_ratio;uniform lowp float u_lineatlas_width;uniform sampler2D u_image;uniform float u_mix;in vec2 v_normal;flat in vec2 v_width2;in vec2 v_tex_a;in vec2 v_tex_b;in float v_gamma_scale;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\nclipAntimeridian();float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float sdfdist_a=texture(u_image,v_tex_a).a;float sdfdist_b=texture(u_image,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);float sdfgamma=(u_lineatlas_width/256.0/u_device_pixel_ratio)/min(dasharray_from.w,dasharray_to.w);alpha*=smoothstep(0.5-sdfgamma/floorwidth,0.5+sdfgamma/floorwidth,sdfdist);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
|
package/src/shaders/shaders.ts
CHANGED
|
@@ -65,10 +65,10 @@ import terrainFrag from './glsl/terrain.fragment.glsl.g.ts';
|
|
|
65
65
|
import terrainVert from './glsl/terrain.vertex.glsl.g.ts';
|
|
66
66
|
import terrainVertDepth from './glsl/terrain_depth.vertex.glsl.g.ts';
|
|
67
67
|
import terrainVertCoords from './glsl/terrain_coords.vertex.glsl.g.ts';
|
|
68
|
-
import projectionErrorMeasurementVert from './glsl/projection_error_measurement.vertex.glsl.g.ts';
|
|
69
|
-
import projectionErrorMeasurementFrag from './glsl/projection_error_measurement.fragment.glsl.g.ts';
|
|
70
68
|
import projectionMercatorVert from './glsl/_projection_mercator.vertex.glsl.g.ts';
|
|
69
|
+
import projectionMercatorFrag from './glsl/_projection_mercator.fragment.glsl.g.ts';
|
|
71
70
|
import projectionGlobeVert from './glsl/_projection_globe.vertex.glsl.g.ts';
|
|
71
|
+
import projectionGlobeFrag from './glsl/_projection_globe.fragment.glsl.g.ts';
|
|
72
72
|
import atmosphereFrag from './glsl/atmosphere.fragment.glsl.g.ts';
|
|
73
73
|
import atmosphereVert from './glsl/atmosphere.vertex.glsl.g.ts';
|
|
74
74
|
import skyFrag from './glsl/sky.fragment.glsl.g.ts';
|
|
@@ -117,13 +117,12 @@ export const shaders: {
|
|
|
117
117
|
terrain: PreparedShader;
|
|
118
118
|
terrainDepth: PreparedShader;
|
|
119
119
|
terrainCoords: PreparedShader;
|
|
120
|
-
projectionErrorMeasurement: PreparedShader;
|
|
121
120
|
atmosphere: PreparedShader;
|
|
122
121
|
sky: PreparedShader;
|
|
123
122
|
} = {
|
|
124
123
|
prelude: prepare(preludeFrag, preludeVert),
|
|
125
|
-
projectionMercator: prepare(
|
|
126
|
-
projectionGlobe: prepare(
|
|
124
|
+
projectionMercator: prepare(projectionMercatorFrag, projectionMercatorVert),
|
|
125
|
+
projectionGlobe: prepare(projectionGlobeFrag, projectionGlobeVert),
|
|
127
126
|
background: prepare(backgroundFrag, backgroundVert),
|
|
128
127
|
backgroundPattern: prepare(backgroundPatternFrag, backgroundPatternVert),
|
|
129
128
|
circle: prepare(circleFrag, circleVert),
|
|
@@ -156,7 +155,6 @@ export const shaders: {
|
|
|
156
155
|
terrain: prepare(terrainFrag, terrainVert),
|
|
157
156
|
terrainDepth: prepare(terrainDepthFrag, terrainVertDepth),
|
|
158
157
|
terrainCoords: prepare(terrainCoordsFrag, terrainVertCoords),
|
|
159
|
-
projectionErrorMeasurement: prepare(projectionErrorMeasurementFrag, projectionErrorMeasurementVert),
|
|
160
158
|
atmosphere: prepare(atmosphereFrag, atmosphereVert),
|
|
161
159
|
sky: prepare(skyFrag, skyVert),
|
|
162
160
|
};
|
|
@@ -102,10 +102,11 @@ describe('GeoJSONSource.setData', () => {
|
|
|
102
102
|
const source = createSource();
|
|
103
103
|
const loadPromise = source.once('data');
|
|
104
104
|
source.load();
|
|
105
|
-
await loadPromise;
|
|
105
|
+
await expect(loadPromise).resolves.toBeDefined();
|
|
106
|
+
|
|
106
107
|
const setDataPromise = source.once('data');
|
|
107
108
|
source.setData({} as GeoJSON.GeoJSON);
|
|
108
|
-
await setDataPromise;
|
|
109
|
+
await expect(setDataPromise).resolves.toBeDefined();
|
|
109
110
|
});
|
|
110
111
|
|
|
111
112
|
test('fires "dataloading" event', async () => {
|
|
@@ -545,8 +546,8 @@ describe('GeoJSONSource.update', () => {
|
|
|
545
546
|
expect(spy.mock.calls[0][0].data.geojsonVtOptions.cluster).toBe(false);
|
|
546
547
|
expect(spy.mock.calls[0][0].data.dataDiff).toEqual(diff);
|
|
547
548
|
expect(spy.mock.calls[1][0].data.geojsonVtOptions.cluster).toBe(true);
|
|
548
|
-
expect(spy.mock.calls[1][0].data.data).
|
|
549
|
-
expect(spy.mock.calls[1][0].data.dataDiff).
|
|
549
|
+
expect(spy.mock.calls[1][0].data.data).toBeUndefined();
|
|
550
|
+
expect(spy.mock.calls[1][0].data.dataDiff).toBeUndefined();
|
|
550
551
|
});
|
|
551
552
|
|
|
552
553
|
test('forwards Supercluster options with worker request, ignore max zoom of source', async () => {
|
|
@@ -1312,3 +1313,30 @@ describe('GeoJSONSource.getClusterLeaves', () => {
|
|
|
1312
1313
|
vi.resetAllMocks();
|
|
1313
1314
|
});
|
|
1314
1315
|
});
|
|
1316
|
+
|
|
1317
|
+
describe('GeoJSONSource.getClusterOptions', () => {
|
|
1318
|
+
test('returns the cluster options configured on the source', () => {
|
|
1319
|
+
const source = new GeoJSONSource('id', {
|
|
1320
|
+
type: 'geojson',
|
|
1321
|
+
data: {} as GeoJSON.GeoJSON,
|
|
1322
|
+
cluster: true,
|
|
1323
|
+
clusterMaxZoom: 12,
|
|
1324
|
+
clusterRadius: 80
|
|
1325
|
+
}, mockDispatcher, undefined);
|
|
1326
|
+
|
|
1327
|
+
expect(source.getClusterOptions()).toEqual({cluster: true, clusterMaxZoom: 12, clusterRadius: 80});
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1330
|
+
test('reflects options updated via setClusterOptions', async () => {
|
|
1331
|
+
const source = new GeoJSONSource('id', {
|
|
1332
|
+
type: 'geojson',
|
|
1333
|
+
data: {} as GeoJSON.GeoJSON,
|
|
1334
|
+
cluster: false
|
|
1335
|
+
}, mockDispatcher, undefined);
|
|
1336
|
+
|
|
1337
|
+
const options = {cluster: true, clusterMaxZoom: 9, clusterRadius: 40};
|
|
1338
|
+
await source.setClusterOptions(options);
|
|
1339
|
+
|
|
1340
|
+
expect(source.getClusterOptions()).toEqual(options);
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
@@ -69,6 +69,24 @@ export type SetClusterOptions = {
|
|
|
69
69
|
clusterRadius?: number;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The cluster options currently configured on a source, as returned by `getClusterOptions`
|
|
74
|
+
*/
|
|
75
|
+
export type GetClusterOptions = {
|
|
76
|
+
/**
|
|
77
|
+
* Whether or not the source is clustered
|
|
78
|
+
*/
|
|
79
|
+
cluster: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The cluster's max zoom
|
|
82
|
+
*/
|
|
83
|
+
clusterMaxZoom: number;
|
|
84
|
+
/**
|
|
85
|
+
* The cluster's radius, in pixels
|
|
86
|
+
*/
|
|
87
|
+
clusterRadius: number;
|
|
88
|
+
};
|
|
89
|
+
|
|
72
90
|
/**
|
|
73
91
|
* A source containing GeoJSON.
|
|
74
92
|
* (See the [Style Specification](https://maplibre.org/maplibre-style-spec/#sources-geojson) for detailed documentation of options.)
|
|
@@ -226,6 +244,10 @@ export class GeoJSONSource extends Evented<SourceEventType> implements Source {
|
|
|
226
244
|
return pixelValue * (EXTENT / this.tileSize);
|
|
227
245
|
}
|
|
228
246
|
|
|
247
|
+
private _tileUnitsToPixels(tileUnitValue: number): number {
|
|
248
|
+
return tileUnitValue / (EXTENT / this.tileSize);
|
|
249
|
+
}
|
|
250
|
+
|
|
229
251
|
private _getClusterMaxZoom(clusterMaxZoom: number): number {
|
|
230
252
|
const effectiveClusterMaxZoom = clusterMaxZoom ? Math.round(clusterMaxZoom) : this.maxzoom - 1;
|
|
231
253
|
if (!(Number.isInteger(clusterMaxZoom) || clusterMaxZoom === undefined)) {
|
|
@@ -321,6 +343,25 @@ export class GeoJSONSource extends Evented<SourceEventType> implements Source {
|
|
|
321
343
|
return this._updateWorkerData();
|
|
322
344
|
}
|
|
323
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Gets the cluster options currently configured on the source.
|
|
348
|
+
* The returned values mirror the options accepted by `setClusterOptions`.
|
|
349
|
+
*
|
|
350
|
+
* @returns the source's current cluster options
|
|
351
|
+
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* const {cluster, clusterMaxZoom, clusterRadius} = map.getSource('some id').getClusterOptions();
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
getClusterOptions(): GetClusterOptions {
|
|
357
|
+
const {cluster, clusterOptions} = this.workerOptions.geojsonVtOptions;
|
|
358
|
+
return {
|
|
359
|
+
cluster,
|
|
360
|
+
clusterMaxZoom: clusterOptions.maxZoom,
|
|
361
|
+
clusterRadius: this._tileUnitsToPixels(clusterOptions.radius)
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
324
365
|
/**
|
|
325
366
|
* For clustered sources, fetches the zoom at which the given cluster expands.
|
|
326
367
|
*
|
|
@@ -562,7 +562,7 @@ describe('mergeSourceDiffs', () => {
|
|
|
562
562
|
} satisfies GeoJSONSourceDiff;
|
|
563
563
|
|
|
564
564
|
const merged = mergeSourceDiffs(diff1, diff2);
|
|
565
|
-
expect(merged.update
|
|
565
|
+
expect(merged.update).toHaveLength(1);
|
|
566
566
|
expect(merged.update[0].removeAllProperties).toBe(true);
|
|
567
567
|
expect(merged.update[0].removeProperties).toBeUndefined();
|
|
568
568
|
expect(merged.update[0].addOrUpdateProperties).toEqual([{key: 'fresh', value: 2}]);
|
|
@@ -604,7 +604,7 @@ describe('mergeSourceDiffs', () => {
|
|
|
604
604
|
|
|
605
605
|
const merged = mergeSourceDiffs(diff1, diff2, 'promoted');
|
|
606
606
|
expect(merged.add).toBeDefined();
|
|
607
|
-
expect(merged.add
|
|
607
|
+
expect(merged.add).toHaveLength(2);
|
|
608
608
|
});
|
|
609
609
|
|
|
610
610
|
test('merges two diffs update feature then remove', () => {
|
|
@@ -118,12 +118,13 @@ describe('geojson tile worker source', () => {
|
|
|
118
118
|
|
|
119
119
|
await source.loadData({source: 'source', data: geoJson, geojsonVtOptions: {}} as LoadGeoJSONParameters);
|
|
120
120
|
|
|
121
|
+
const onSettled = vi.fn();
|
|
121
122
|
source.loadTile({
|
|
122
123
|
source: 'source',
|
|
123
124
|
uid: 0,
|
|
124
125
|
tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
|
|
125
126
|
subdivisionGranularity: SubdivisionGranularitySetting.noSubdivision,
|
|
126
|
-
} as any as WorkerTileParameters).then(
|
|
127
|
+
} as any as WorkerTileParameters).then(onSettled, onSettled);
|
|
127
128
|
|
|
128
129
|
// allow promise to run
|
|
129
130
|
await sleep(0);
|
|
@@ -135,6 +136,7 @@ describe('geojson tile worker source', () => {
|
|
|
135
136
|
subdivisionGranularity: SubdivisionGranularitySetting.noSubdivision,
|
|
136
137
|
} as any as WorkerTileParameters) as WorkerTileWithData;
|
|
137
138
|
|
|
139
|
+
expect(onSettled).not.toHaveBeenCalled();
|
|
138
140
|
expect(res).toBeDefined();
|
|
139
141
|
expect(res.rawTileData).toBeDefined();
|
|
140
142
|
});
|
|
@@ -187,12 +189,13 @@ describe('geojson tile worker source', () => {
|
|
|
187
189
|
|
|
188
190
|
await source.loadData({source: 'source', data: geoJson, geojsonVtOptions: {}} as LoadGeoJSONParameters);
|
|
189
191
|
|
|
192
|
+
const onSettled = vi.fn();
|
|
190
193
|
source.loadTile({
|
|
191
194
|
source: 'source',
|
|
192
195
|
uid: 0,
|
|
193
196
|
tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
|
|
194
197
|
subdivisionGranularity: SubdivisionGranularitySetting.noSubdivision,
|
|
195
|
-
} as any as WorkerTileParameters).then(
|
|
198
|
+
} as any as WorkerTileParameters).then(onSettled, onSettled);
|
|
196
199
|
|
|
197
200
|
// allow promise to run
|
|
198
201
|
await sleep(0);
|
|
@@ -211,6 +214,7 @@ describe('geojson tile worker source', () => {
|
|
|
211
214
|
subdivisionGranularity: SubdivisionGranularitySetting.noSubdivision,
|
|
212
215
|
} as any as WorkerTileParameters) as WorkerTileWithData;
|
|
213
216
|
|
|
217
|
+
expect(onSettled).not.toHaveBeenCalled();
|
|
214
218
|
expect(res).toBeDefined();
|
|
215
219
|
expect(res.rawTileData).toBeDefined();
|
|
216
220
|
});
|
|
@@ -235,7 +239,7 @@ describe('geojson tile worker source', () => {
|
|
|
235
239
|
source: 'source',
|
|
236
240
|
uid: 0,
|
|
237
241
|
tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
|
|
238
|
-
} as any as WorkerTileParameters)).rejects.
|
|
242
|
+
} as any as WorkerTileParameters)).rejects.toThrow(/Unable to parse the data into a cluster or geojson/);
|
|
239
243
|
});
|
|
240
244
|
|
|
241
245
|
test('GeoJSONWorkerSource.abortTile aborts tile state', async () => {
|
|
@@ -434,8 +438,8 @@ describe('resourceTiming', () => {
|
|
|
434
438
|
});
|
|
435
439
|
return null;
|
|
436
440
|
});
|
|
437
|
-
vi.spyOn(performance, 'clearMarks').
|
|
438
|
-
vi.spyOn(performance, 'clearMeasures').
|
|
441
|
+
vi.spyOn(performance, 'clearMarks').mockReturnValue(null);
|
|
442
|
+
vi.spyOn(performance, 'clearMeasures').mockReturnValue(null);
|
|
439
443
|
|
|
440
444
|
const layerIndex = new StyleLayerIndex(layers);
|
|
441
445
|
const source = new GeoJSONWorkerSource(actor, layerIndex, []);
|