maplibre-gl 6.1.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.
Files changed (112) hide show
  1. package/build/readme.md +0 -2
  2. package/dist/maplibre-gl-dev.mjs +179 -190
  3. package/dist/maplibre-gl-dev.mjs.map +1 -1
  4. package/dist/maplibre-gl-shared-dev.mjs +869 -825
  5. package/dist/maplibre-gl-shared-dev.mjs.map +1 -1
  6. package/dist/maplibre-gl-shared.mjs +2 -2
  7. package/dist/maplibre-gl-shared.mjs.map +1 -1
  8. package/dist/maplibre-gl-worker-dev.mjs +14 -12
  9. package/dist/maplibre-gl-worker-dev.mjs.map +1 -1
  10. package/dist/maplibre-gl-worker.mjs +2 -2
  11. package/dist/maplibre-gl-worker.mjs.map +1 -1
  12. package/dist/maplibre-gl.css +1 -1
  13. package/dist/maplibre-gl.d.ts +24 -6
  14. package/dist/maplibre-gl.mjs +13 -13
  15. package/dist/maplibre-gl.mjs.map +1 -1
  16. package/package.json +10 -13
  17. package/src/data/bucket/fill_extrusion_bucket.test.ts +22 -0
  18. package/src/data/bucket/fill_extrusion_bucket.ts +16 -4
  19. package/src/data/bucket/round_polygon_corners.test.ts +159 -0
  20. package/src/data/bucket/round_polygon_corners.ts +121 -0
  21. package/src/data/bucket/symbol_bucket.test.ts +1 -1
  22. package/src/data/dem_data.test.ts +23 -23
  23. package/src/data/feature_position_map.test.ts +1 -1
  24. package/src/data/segment.test.ts +14 -14
  25. package/src/geo/bounds.test.ts +4 -4
  26. package/src/geo/lng_lat_bounds.test.ts +1 -1
  27. package/src/geo/projection/mercator_transform.test.ts +1 -1
  28. package/src/geo/projection/mercator_utils.test.ts +8 -8
  29. package/src/index.test.ts +7 -12
  30. package/src/render/glyph_manager.test.ts +6 -22
  31. package/src/render/painter.test.ts +2 -0
  32. package/src/render/painter.ts +7 -5
  33. package/src/render/subdivision.test.ts +22 -22
  34. package/src/render/terrain.test.ts +68 -34
  35. package/src/render/terrain.ts +69 -26
  36. package/src/source/canvas_source.test.ts +1 -1
  37. package/src/source/geojson_source.test.ts +5 -4
  38. package/src/source/geojson_source_diff.test.ts +2 -2
  39. package/src/source/geojson_worker_source.test.ts +9 -5
  40. package/src/source/image_source.test.ts +0 -3
  41. package/src/source/raster_dem_tile_source.test.ts +2 -2
  42. package/src/source/raster_tile_source.test.ts +15 -9
  43. package/src/source/rtl_text_plugin_main_thread.test.ts +14 -14
  44. package/src/source/source.test.ts +8 -8
  45. package/src/source/vector_tile_source.test.ts +1 -1
  46. package/src/source/vector_tile_worker_source.test.ts +7 -5
  47. package/src/source/worker.test.ts +1 -1
  48. package/src/source/worker_tile.test.ts +4 -2
  49. package/src/style/load_glyph_range.test.ts +8 -8
  50. package/src/style/load_sprite.test.ts +1 -1
  51. package/src/style/style.test.ts +36 -34
  52. package/src/style/style_layer/color_relief_style_layer.test.ts +1 -1
  53. package/src/style/style_layer/fill_extrusion_style_layer.ts +6 -3
  54. package/src/style/style_layer/raster_style_layer.test.ts +2 -2
  55. package/src/style/style_layer.test.ts +3 -50
  56. package/src/symbol/collision_index.test.ts +1 -1
  57. package/src/symbol/grid_index.test.ts +1 -1
  58. package/src/tile/terrain_tile_manager.test.ts +2 -2
  59. package/src/tile/tile_id.test.ts +5 -5
  60. package/src/tile/tile_manager.test.ts +85 -72
  61. package/src/tile/tile_manager_in_view_tiles.test.ts +2 -2
  62. package/src/ui/camera.test.ts +137 -134
  63. package/src/ui/control/geolocate_control.test.ts +6 -29
  64. package/src/ui/handler/dblclick_zoom.test.ts +2 -2
  65. package/src/ui/handler/scroll_zoom.test.ts +2 -0
  66. package/src/ui/handler_manager.test.ts +7 -7
  67. package/src/ui/hash.test.ts +1 -0
  68. package/src/ui/map.ts +28 -18
  69. package/src/ui/map_tests/map_basic.test.ts +11 -23
  70. package/src/ui/map_tests/map_calculate_camera_options.test.ts +6 -6
  71. package/src/ui/map_tests/map_events.test.ts +5 -5
  72. package/src/ui/map_tests/map_global_state.test.ts +3 -3
  73. package/src/ui/map_tests/map_images.test.ts +3 -3
  74. package/src/ui/map_tests/map_is_moving.test.ts +1 -1
  75. package/src/ui/map_tests/map_is_rotating.test.ts +1 -1
  76. package/src/ui/map_tests/map_layer.test.ts +2 -1
  77. package/src/ui/map_tests/map_options.test.ts +1 -5
  78. package/src/ui/map_tests/map_pitch.test.ts +6 -6
  79. package/src/ui/map_tests/map_refresh_tiles.test.ts +2 -2
  80. package/src/ui/map_tests/map_render.test.ts +1 -1
  81. package/src/ui/map_tests/map_set_lod_params.test.ts +1 -1
  82. package/src/ui/map_tests/map_style.test.ts +9 -1
  83. package/src/ui/map_tests/map_terrain.test.ts +20 -0
  84. package/src/ui/map_tests/map_zoom.test.ts +15 -15
  85. package/src/ui/marker.test.ts +7 -13
  86. package/src/ui/popup.test.ts +3 -3
  87. package/src/util/actor.test.ts +6 -6
  88. package/src/util/ajax.test.ts +27 -39
  89. package/src/util/browser.test.ts +7 -9
  90. package/src/util/create_tile_mesh.test.ts +2 -2
  91. package/src/util/dispatcher.test.ts +1 -1
  92. package/src/util/evented.test.ts +4 -1
  93. package/src/util/fast_maths.test.ts +4 -4
  94. package/src/util/image_request.test.ts +6 -4
  95. package/src/util/struct_array.test.ts +2 -2
  96. package/src/util/task_queue.test.ts +1 -1
  97. package/src/util/test/util.ts +1 -0
  98. package/src/util/time_control.test.ts +2 -2
  99. package/src/util/transferable_grid_index.test.ts +1 -1
  100. package/src/util/util.test.ts +27 -13
  101. package/src/util/verticalize_punctuation.test.ts +4 -4
  102. package/src/util/web_worker_transfer.test.ts +5 -5
  103. package/src/webgl/draw/draw_custom.test.ts +13 -13
  104. package/src/webgl/draw/draw_debug.test.ts +1 -1
  105. package/src/webgl/draw/draw_fill.test.ts +12 -12
  106. package/src/webgl/draw/draw_symbol.test.ts +16 -16
  107. package/src/webgl/program.ts +2 -0
  108. package/src/webgl/render_to_texture.test.ts +5 -5
  109. package/src/webgl/state.test.ts +1 -1
  110. package/src/webgl/texture.test.ts +3 -3
  111. package/src/webgl/vertex_buffer.test.ts +1 -1
  112. package/build/rolldown_plugins.ts +0 -18
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "maplibre-gl",
3
3
  "description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library",
4
- "version": "6.1.0",
4
+ "version": "6.2.0",
5
5
  "module": "dist/maplibre-gl.mjs",
6
6
  "style": "dist/maplibre-gl.css",
7
7
  "license": "BSD-3-Clause",
@@ -60,12 +60,12 @@
60
60
  "@types/minimist": "^1.2.5",
61
61
  "@types/murmurhash-js": "^1.0.7",
62
62
  "@types/nise": "^1.4.5",
63
- "@types/node": "^26.1.1",
63
+ "@types/node": "^26.1.2",
64
64
  "@types/offscreencanvas": "^2019.7.3",
65
65
  "@types/pixelmatch": "^5.2.6",
66
66
  "@types/pngjs": "^6.0.5",
67
- "@types/react": "^19.2.17",
68
- "@types/react-dom": "^19.2.3",
67
+ "@types/react": "^19.2.18",
68
+ "@types/react-dom": "^19.2.4",
69
69
  "@types/request": "^2.48.13",
70
70
  "@types/shuffle-seed": "^1.1.3",
71
71
  "@types/window-or-global": "^1.0.6",
@@ -85,7 +85,7 @@
85
85
  "cssnano": "^8.0.2",
86
86
  "d3": "^7.9.0",
87
87
  "d3-queue": "^3.0.7",
88
- "devtools-protocol": "^0.0.1666840",
88
+ "devtools-protocol": "^0.0.1672245",
89
89
  "diff": "^9.0.0",
90
90
  "eslint": "^10.8.0",
91
91
  "eslint-plugin-html": "^8.1.4",
@@ -94,7 +94,7 @@
94
94
  "glob": "^13.0.6",
95
95
  "globals": "^17.8.0",
96
96
  "is-builtin-module": "^5.0.0",
97
- "jsdom": "^29.1.1",
97
+ "jsdom": "^30.0.1",
98
98
  "minimist": "^1.2.8",
99
99
  "mock-geolocation": "^1.0.11",
100
100
  "monocart-coverage-reports": "^2.12.12",
@@ -104,18 +104,16 @@
104
104
  "pdf-merger-js": "^5.1.2",
105
105
  "pixelmatch": "^7.2.0",
106
106
  "pngjs": "^7.0.0",
107
- "postcss": "^8.5.23",
107
+ "postcss": "^8.5.25",
108
108
  "postcss-cli": "^11.0.1",
109
109
  "postcss-inline-svg": "^6.0.0",
110
110
  "pretty-bytes": "^7.1.1",
111
- "puppeteer": "^25.3.0",
111
+ "puppeteer": "^25.4.0",
112
112
  "react": "^19.2.8",
113
113
  "react-dom": "^19.2.8",
114
114
  "regenerate": "^1.4.2",
115
- "rolldown": "^1.2.0",
115
+ "rolldown": "^1.2.1",
116
116
  "rolldown-plugin-dts": "^0.27.8",
117
- "rollup": "^4.62.3",
118
- "rollup-plugin-visualizer": "^7.0.1",
119
117
  "rw": "^1.3.3",
120
118
  "semver": "^7.8.5",
121
119
  "sharp": "^0.35.3",
@@ -127,7 +125,7 @@
127
125
  "typedoc": "^0.28.20",
128
126
  "typedoc-plugin-markdown": "^4.11.0",
129
127
  "typescript": "^6.0.3",
130
- "vite": "^8.1.5",
128
+ "vite": "^8.2.0",
131
129
  "vitest": "^4.1.5",
132
130
  "vitest-webgl-canvas-mock": "^1.1.0"
133
131
  },
@@ -147,7 +145,6 @@
147
145
  "watch-css": "postcss --watch -o dist/maplibre-gl.css src/css/maplibre-gl.css",
148
146
  "build-benchmarks": "npm run build-dev && rolldown -c test/bench/rolldown_config_benchmarks.ts",
149
147
  "watch-benchmarks": "rolldown -c test/bench/rolldown_config_benchmarks.ts --watch",
150
- "bundle-stats": "cross-env BUILD=production BUNDLE=stats rolldown -c rolldown.config.ts",
151
148
  "spellcheck": "cspell",
152
149
  "docs": "npm run generate-docs && docker compose run --rm docs",
153
150
  "start-server": "st --no-cache -H localhost --port 9966 .",
@@ -43,4 +43,26 @@ describe('FillExtrusionBucket', () => {
43
43
  test: {min: 'test-pattern', mid: 'test-pattern', max: 'test-pattern'}
44
44
  });
45
45
  });
46
+
47
+ test('FillExtrusionBucket populates vertices with fill-extrusion-rounded-corner-distance layout property', () => {
48
+ const bucketWithoutRounding = createFillExtrusionBucket({
49
+ id: 'test-no-rounding',
50
+ layout: {'fill-extrusion-rounded-corner-distance': 0},
51
+ paint: {'fill-extrusion-height': 10}
52
+ });
53
+ const bucketWithRounding = createFillExtrusionBucket({
54
+ id: 'test-rounding',
55
+ layout: {'fill-extrusion-rounded-corner-distance': 5},
56
+ paint: {'fill-extrusion-height': 10}
57
+ });
58
+
59
+ const features = getFeaturesFromLayer(sourceLayer);
60
+ const populateOptions = createPopulateOptions([]);
61
+
62
+ bucketWithoutRounding.populate(features, populateOptions, {x: 0, y: 0, z: 14} as any);
63
+ bucketWithRounding.populate(features, populateOptions, {x: 0, y: 0, z: 14} as any);
64
+
65
+ expect(bucketWithoutRounding.layoutVertexArray.length).toBeGreaterThan(0);
66
+ expect(bucketWithRounding.layoutVertexArray.length).toBeGreaterThan(bucketWithoutRounding.layoutVertexArray.length);
67
+ });
46
68
  });
@@ -35,6 +35,8 @@ import type {SubdivisionGranularitySetting} from '../../render/subdivision_granu
35
35
  import {fillLargeMeshArrays} from '../../render/fill_large_mesh_arrays.ts';
36
36
  import type {VectorTileLayerLike} from '@maplibre/vt-pbf';
37
37
 
38
+ import {roundPolygonCorners} from './round_polygon_corners.ts';
39
+
38
40
  const FACTOR = Math.pow(2, 13);
39
41
 
40
42
  function addVertex(vertexArray, x, y, nx, ny, nz, t, e) {
@@ -102,17 +104,23 @@ export class FillExtrusionBucket implements Bucket {
102
104
  this.hasDependencies = hasPattern('fill-extrusion', this.layers, options);
103
105
 
104
106
  const globalProperties = new EvaluationParameters(this.zoom);
105
- const needGeometry = this.layers[0]._featureFilter.needGeometry;
107
+ const layer = this.layers[0];
108
+ const roundedCornerDistance = layer.layout.get('fill-extrusion-rounded-corner-distance');
109
+ const needGeometry = layer._featureFilter.needGeometry;
110
+
106
111
  for (const {feature, id, index, sourceLayerIndex} of features) {
107
112
  const evaluationFeature = toEvaluationFeature(feature, needGeometry);
108
113
 
109
- if (!this.layers[0]._featureFilter.filter(globalProperties, evaluationFeature, canonical)) continue;
114
+ if (!layer._featureFilter.filter(globalProperties, evaluationFeature, canonical)) continue;
115
+
116
+ const rawGeometry = needGeometry ? evaluationFeature.geometry : loadGeometry(feature);
117
+ const geometry = roundedCornerDistance > 0 ? roundPolygonCorners(rawGeometry, roundedCornerDistance, canonical) : rawGeometry;
110
118
 
111
119
  const bucketFeature: BucketFeature = {
112
120
  id,
113
121
  sourceLayerIndex,
114
122
  index,
115
- geometry: needGeometry ? evaluationFeature.geometry : loadGeometry(feature),
123
+ geometry,
116
124
  properties: feature.properties,
117
125
  type: feature.type,
118
126
  patterns: {}
@@ -170,7 +178,11 @@ export class FillExtrusionBucket implements Bucket {
170
178
  }
171
179
 
172
180
  addFeature(feature: BucketFeature, geometry: Point[][], index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}, subdivisionGranularity: SubdivisionGranularitySetting): void {
173
- for (const polygon of classifyRings(geometry, EARCUT_MAX_RINGS)) {
181
+ const layer = this.layers[0];
182
+ const roundedCornerDistance = layer.layout ? layer.layout.get('fill-extrusion-rounded-corner-distance') : 0;
183
+ const processedGeometry = roundedCornerDistance > 0 ? roundPolygonCorners(geometry, roundedCornerDistance, canonical) : geometry;
184
+
185
+ for (const polygon of classifyRings(processedGeometry, EARCUT_MAX_RINGS)) {
174
186
  // Compute polygon centroid to calculate elevation in GPU
175
187
  const centroid: CentroidAccumulator = {x: 0, y: 0, sampleCount: 0};
176
188
  const oldVertexCount = this.layoutVertexArray.length;
@@ -0,0 +1,159 @@
1
+ import {describe, test, expect} from 'vitest';
2
+ import Point from '@mapbox/point-geometry';
3
+ import {roundPolygonCorners} from './round_polygon_corners.ts';
4
+ import {CanonicalTileID} from '../../tile/tile_id.ts';
5
+
6
+ function round(p: Point):GeoJSON.Position {
7
+ // add 0 to normalize -0 into 0
8
+ const x = Math.round(p.x * 100) / 100 + 0;
9
+ const y = Math.round(p.y * 100) / 100 + 0;
10
+ return [x, y];
11
+ }
12
+
13
+ describe('roundPolygonCorners', () => {
14
+ const canonical = new CanonicalTileID(10, 500, 300);
15
+
16
+ test('returns original polygon reference when distance is zero', () => {
17
+ const input = [[
18
+ new Point(0, 0),
19
+ new Point(100, 0),
20
+ new Point(100, 100),
21
+ new Point(0, 100),
22
+ new Point(0, 0)
23
+ ]];
24
+
25
+ const output = roundPolygonCorners(input, 0, canonical);
26
+ expect(output).toBe(input);
27
+ });
28
+
29
+ test('returns original polygon reference when distance is negative', () => {
30
+ const input = [[
31
+ new Point(0, 0),
32
+ new Point(100, 0),
33
+ new Point(100, 100),
34
+ new Point(0, 100),
35
+ new Point(0, 0)
36
+ ]];
37
+
38
+ const output = roundPolygonCorners(input, -1, canonical);
39
+ expect(output).toBe(input);
40
+ });
41
+
42
+ test('returns unchanged ring for degenerate line rings', () => {
43
+ const input = [[
44
+ new Point(0, 0),
45
+ new Point(50, 50),
46
+ new Point(0, 0)
47
+ ]];
48
+
49
+ const output = roundPolygonCorners(input, 10, canonical);
50
+ expect(output).toStrictEqual(input);
51
+ });
52
+
53
+ test('still rounds very small rounding', () => {
54
+ const input = [[
55
+ new Point(0, 0),
56
+ new Point(10, 0),
57
+ new Point(10, 10),
58
+ new Point(0, 10),
59
+ new Point(0, 0)
60
+ ]];
61
+
62
+ const output = roundPolygonCorners(input, 0.1, canonical);
63
+ const points = output[0].map(round);
64
+
65
+ expect(points).toEqual([
66
+ [0, 0.04], [0.01, 0.02], [0.02, 0.01], [0.04, 0], [9.96, 0], [9.98, 0.01], [9.99, 0.02], [10, 0.04],
67
+ [10, 9.96], [9.99, 9.98], [9.98, 9.99], [9.96, 10], [0.04, 10], [0.02, 9.99], [0.01, 9.98], [0, 9.96], [0, 0.04]
68
+ ]);
69
+ });
70
+
71
+ test('rounds corners of a square polygon into arc vertices', () => {
72
+ const input = [[
73
+ new Point(0, 0),
74
+ new Point(10, 0),
75
+ new Point(10, 10),
76
+ new Point(0, 10),
77
+ new Point(0, 0)
78
+ ]];
79
+
80
+ const output = roundPolygonCorners(input, 2, canonical);
81
+ const points = output[0].map(round);
82
+
83
+ expect(points).toEqual([
84
+ [0, 0.82], [0.11, 0.41], [0.41, 0.11], [0.82, 0], [9.18, 0], [9.59, 0.11], [9.89, 0.41], [10, 0.82],
85
+ [10, 9.18], [9.89, 9.59], [9.59, 9.89], [9.18, 10], [0.82, 10], [0.41, 9.89], [0.11, 9.59], [0, 9.18], [0, 0.82]
86
+ ]);
87
+ });
88
+
89
+ test('clamps corner rounding distance to 20% of edge length when requested distance is large', () => {
90
+ const input = [[
91
+ new Point(0, 0),
92
+ new Point(10, 0),
93
+ new Point(10, 10),
94
+ new Point(0, 10),
95
+ new Point(0, 0)
96
+ ]];
97
+
98
+ const output = roundPolygonCorners(input, 1000, canonical);
99
+ const points = output[0].map(round);
100
+
101
+ expect(points).toEqual([
102
+ [0, 2], [0.27, 1], [1, 0.27], [2, 0], [8, 0], [9, 0.27], [9.73, 1], [10, 2],
103
+ [10, 8], [9.73, 9], [9, 9.73], [8, 10], [2, 10], [1, 9.73], [0.27, 9], [0, 8], [0, 2]
104
+ ]);
105
+ });
106
+
107
+ test('preserves near-zero-degree spike vertex without adding arc points', () => {
108
+ const input = [[
109
+ new Point(0, 0),
110
+ new Point(100, 0),
111
+ new Point(0, 0.4),
112
+ new Point(0, 0)
113
+ ]];
114
+
115
+ const output = roundPolygonCorners(input, 5, canonical);
116
+ const points = output[0].map(round);
117
+
118
+ expect(points).toEqual([
119
+ [0, 0.08], [0.01, 0.04], [0.04, 0.01], [0.08, 0], [100, 0], [0.08, 0.4],
120
+ [0.05, 0.39], [0.02, 0.38], [0.01, 0.35], [0, 0.32], [0, 0.08]
121
+ ]);
122
+ });
123
+
124
+ test('preserves collinear 180-degree vertices without adding arc points', () => {
125
+ const input = [[
126
+ new Point(0, 0),
127
+ new Point(5, 0),
128
+ new Point(10, 0),
129
+ new Point(10, 10),
130
+ new Point(0, 10),
131
+ new Point(0, 0)
132
+ ]];
133
+
134
+ const output = roundPolygonCorners(input, 5, canonical);
135
+ const points = output[0].map(round);
136
+
137
+ expect(points).toEqual([
138
+ [0, 1], [0.13, 0.5], [0.5, 0.13], [1, 0], [5, 0], [9, 0], [9.5, 0.13], [9.87, 0.5], [10, 1],
139
+ [10, 8], [9.73, 9], [9, 9.73], [8, 10], [2, 10], [1, 9.73], [0.27, 9], [0, 8], [0, 1]
140
+ ]);
141
+ });
142
+
143
+ test('scales arc points with corner sharpness up to the segment maximum', () => {
144
+ const input = [[
145
+ new Point(0, 0),
146
+ new Point(100, 0),
147
+ new Point(50, 20),
148
+ new Point(0, 0)
149
+ ]];
150
+
151
+ const output = roundPolygonCorners(input, 5, canonical);
152
+ const points = output[0].map(round);
153
+
154
+ expect(points).toEqual([
155
+ [1.91, 0.77], [1.77, 0.66], [1.68, 0.5], [1.67, 0.32], [1.75, 0.16], [1.88, 0.04], [2.06, 0], [97.94, 0], [98.12, 0.04],
156
+ [98.25, 0.16], [98.33, 0.32], [98.32, 0.5], [98.23, 0.66], [98.09, 0.77], [51.91, 19.23], [50, 19.6], [48.09, 19.23], [1.91, 0.77]
157
+ ]);
158
+ });
159
+ });
@@ -0,0 +1,121 @@
1
+ import Point from '@mapbox/point-geometry';
2
+ import {vec2} from 'gl-matrix';
3
+ import {EXTENT} from '../extent.ts';
4
+ import {MercatorCoordinate} from '../../geo/mercator_coordinate.ts';
5
+ import {tileCoordinatesToLocation} from '../../geo/projection/mercator_utils.ts';
6
+ import type {CanonicalTileID} from '../../tile/tile_id.ts';
7
+
8
+ /**
9
+ * Rounds polygon corners by calculating arc points at each corner vertex.
10
+ * @param polygon - Collection of polygon rings (outer ring and hole rings)
11
+ * @param distanceInMeters - Desired corner rounding distance in meters
12
+ * @param canonical - Canonical tile ID used for meter to tile unit conversion
13
+ */
14
+ export function roundPolygonCorners(
15
+ polygon: Point[][],
16
+ distanceInMeters: number,
17
+ canonical: CanonicalTileID
18
+ ): Point[][] {
19
+ if (distanceInMeters <= 0 || !polygon || polygon.length === 0) {
20
+ return polygon;
21
+ }
22
+
23
+ const distanceInTileUnits = getTileUnitsForMeters(distanceInMeters, canonical);
24
+ return polygon.map(ring => roundRing(ring, distanceInTileUnits));
25
+ }
26
+
27
+ function getTileUnitsForMeters(distanceInMeters: number, canonical: CanonicalTileID): number {
28
+ const centerLocation = tileCoordinatesToLocation(EXTENT / 2, EXTENT / 2, canonical);
29
+ const mercatorCoord = MercatorCoordinate.fromLngLat(centerLocation);
30
+ const meterInMercator = mercatorCoord.meterInMercatorCoordinateUnits();
31
+ const tileUnitsPerMercator = (1 << canonical.z) * EXTENT;
32
+ return distanceInMeters * meterInMercator * tileUnitsPerMercator;
33
+ }
34
+
35
+ function roundRing(ring: Point[], distanceInTileUnits: number): Point[] {
36
+ if (!ring || ring.length < 3) {
37
+ return ring;
38
+ }
39
+
40
+ const isClosed = ring[0].x === ring[ring.length - 1].x && ring[0].y === ring[ring.length - 1].y;
41
+ const vertexCount = isClosed ? ring.length - 1 : ring.length;
42
+
43
+ if (vertexCount < 3) {
44
+ return ring;
45
+ }
46
+
47
+ const vertices: vec2[] = ring.map(p => vec2.fromValues(p.x,p.y));
48
+ const newRing: vec2[] = [];
49
+
50
+ for (let i = 0; i < vertexCount; i++) {
51
+ const prev = vertices[(i - 1 + vertexCount) % vertexCount];
52
+ const current = vertices[i];
53
+ const next = vertices[(i + 1) % vertexCount];
54
+
55
+ appendRoundCorner(newRing, prev, current, next, distanceInTileUnits);
56
+ }
57
+
58
+ if (isClosed && newRing.length > 0) {
59
+ newRing.push(vec2.clone(newRing[0]));
60
+ }
61
+
62
+ return newRing.map(p => new Point(p[0], p[1]));
63
+ }
64
+
65
+ function appendRoundCorner(
66
+ newRing: vec2[],
67
+ prev: vec2,
68
+ current: vec2,
69
+ next: vec2,
70
+ distanceInTileUnits: number
71
+ ): void {
72
+ // Unit edge vectors from the current vertex towards its neighbours
73
+ const ua = vec2.sub(vec2.create(), prev, current);
74
+ const ub = vec2.sub(vec2.create(), next, current);
75
+ const lenA = vec2.length(ua);
76
+ const lenB = vec2.length(ub);
77
+
78
+ if (lenA < 1e-6 || lenB < 1e-6) {
79
+ newRing.push(vec2.clone(current));
80
+ return;
81
+ }
82
+
83
+ vec2.scale(ua, ua, 1 / lenA);
84
+ vec2.scale(ub, ub, 1 / lenB);
85
+
86
+ // Straight lines or zero-degree turns
87
+ const dot = vec2.dot(ua, ub);
88
+ if (Math.abs(dot) > Math.cos(5 * Math.PI / 180)) {
89
+ newRing.push(vec2.clone(current));
90
+ return;
91
+ }
92
+
93
+ // we clamp to not have circles in the extremes
94
+ const maxEdgeLenPercent = 0.2;
95
+ const r = Math.min(distanceInTileUnits, lenA * maxEdgeLenPercent, lenB * maxEdgeLenPercent);
96
+
97
+ // Tangent points on edges to prevPoint and nextPoint
98
+ const tangentA = vec2.scaleAndAdd(vec2.create(), current, ua, r);
99
+ const tangentB = vec2.scaleAndAdd(vec2.create(), current, ub, r);
100
+
101
+ const bisector = vec2.add(vec2.create(), ua, ub);
102
+ vec2.normalize(bisector, bisector);
103
+
104
+ // Center of the rounding arc, at r / cos(theta/2) along the bisector
105
+ const cosHalfTheta = Math.sqrt((1 + dot) / 2);
106
+ const center = vec2.scaleAndAdd(vec2.create(), current, bisector, r / cosHalfTheta);
107
+
108
+ // Both tangent points lie on the arc circle.
109
+ // Rotating tangent A around the center traces the fillet onto tangent B along the shortest arc.
110
+ const radiusA = vec2.sub(vec2.create(), tangentA, center);
111
+ const radiusB = vec2.sub(vec2.create(), tangentB, center);
112
+ const sweepAngle = vec2.angle(radiusA, radiusB);
113
+ const direction = Math.sign(radiusA[0] * radiusB[1] - radiusA[1] * radiusB[0]); // 2D cross product -> winding direction
114
+
115
+ // ~30 deg per segment; epsilon keeps fp noise from adding one at exact multiples.
116
+ const numSegments = Math.max(2, Math.ceil(sweepAngle / (Math.PI / 6) - 1e-6));
117
+ for (let s = 0; s <= numSegments; s++) {
118
+ const angle = direction * sweepAngle * (s / numSegments);
119
+ newRing.push(vec2.rotate(vec2.create(), tangentA, center, angle));
120
+ }
121
+ }
@@ -126,7 +126,7 @@ describe('SymbolBucket', () => {
126
126
  } as any);
127
127
 
128
128
  expect(spy).toHaveBeenCalledTimes(1);
129
- expect(spy.mock.calls[0][0].includes('Too many glyphs being rendered in a tile.')).toBeTruthy();
129
+ expect(spy.mock.calls[0][0]).toContain('Too many glyphs being rendered in a tile.');
130
130
  });
131
131
 
132
132
  test('SymbolBucket image undefined sdf', () => {
@@ -53,7 +53,7 @@ describe('DEMData', () => {
53
53
  });
54
54
  });
55
55
 
56
- function testDEMBorderRegion(dem: DEMData) {
56
+ function expectDEMBorderRegion(dem: DEMData) {
57
57
  return () => {
58
58
  let nonempty = true;
59
59
  for (let x = -1; x < 5; x++) {
@@ -96,7 +96,7 @@ function testDEMBorderRegion(dem: DEMData) {
96
96
  };
97
97
  }
98
98
 
99
- function testDEMBackfill(dem0: DEMData, dem1: DEMData) {
99
+ function expectDEMBackfill(dem0: DEMData, dem1: DEMData) {
100
100
  return () => {
101
101
  dem0.backfillBorder(dem1, -1, 0);
102
102
  for (let y = 0; y < 4; y++) {
@@ -138,16 +138,16 @@ describe('DEMData.backfillBorder with encoding', () => {
138
138
  const dem0 = new DEMData('0', createMockImage(4, 4), 'mapbox');
139
139
  const dem1 = new DEMData('1', createMockImage(4, 4), 'mapbox');
140
140
 
141
- test('border region is initially populated with neighboring data', testDEMBorderRegion(dem0));
142
- test('backfillBorder correctly populates borders with neighboring data', testDEMBackfill(dem0, dem1));
141
+ test('border region is initially populated with neighboring data', expectDEMBorderRegion(dem0));
142
+ test('backfillBorder correctly populates borders with neighboring data', expectDEMBackfill(dem0, dem1));
143
143
  });
144
144
 
145
145
  describe('terrarium encoding', () => {
146
146
  const dem0 = new DEMData('0', createMockImage(4, 4), 'terrarium');
147
147
  const dem1 = new DEMData('1', createMockImage(4, 4), 'terrarium');
148
148
 
149
- test('border region is initially populated with neighboring data', testDEMBorderRegion(dem0));
150
- test('backfillBorder correctly populates borders with neighboring data', testDEMBackfill(dem0, dem1));
149
+ test('border region is initially populated with neighboring data', expectDEMBorderRegion(dem0));
150
+ test('backfillBorder correctly populates borders with neighboring data', expectDEMBackfill(dem0, dem1));
151
151
  });
152
152
  });
153
153
 
@@ -175,7 +175,7 @@ describe('DEMData.sampleBilinear', () => {
175
175
  });
176
176
  });
177
177
 
178
- function testSerialization(dem0: DEMData, redFactor: number, greenFactor: number, blueFactor: number, baseShift: number) {
178
+ function expectSerialization(dem0: DEMData, redFactor: number, greenFactor: number, blueFactor: number, baseShift: number) {
179
179
  return () => {
180
180
  const serialized = serialize(dem0);
181
181
 
@@ -210,7 +210,7 @@ function testSerialization(dem0: DEMData, redFactor: number, greenFactor: number
210
210
  };
211
211
  }
212
212
 
213
- function testDeserialization(dem0: DEMData) {
213
+ function expectDeserialization(dem0: DEMData) {
214
214
  return () => {
215
215
  const serialized = serialize(dem0);
216
216
 
@@ -223,13 +223,13 @@ describe('DEMData is correctly serialized and deserialized', () => {
223
223
  const mapboxDEM = new DEMData('0', createMockImage(4, 4), 'mapbox');
224
224
  const terrariumDEM = new DEMData('0', createMockImage(4, 4), 'terrarium');
225
225
  const customDEM = new DEMData('0', createMockImage(4, 4), 'custom', 1.0, 2.0, 3.0, 4.0);
226
- test('serialized - mapbox', testSerialization(mapboxDEM, 6553.6, 25.6, 0.1, 10000));
227
- test('serialized - terrarium', testSerialization(terrariumDEM, 256.0, 1.0, 1.0 / 256.0, 32768.0));
228
- test('serialized - custom', testSerialization(customDEM, 1.0, 2.0, 3.0, 4.0));
226
+ test('serialized - mapbox', expectSerialization(mapboxDEM, 6553.6, 25.6, 0.1, 10000));
227
+ test('serialized - terrarium', expectSerialization(terrariumDEM, 256.0, 1.0, 1.0 / 256.0, 32768.0));
228
+ test('serialized - custom', expectSerialization(customDEM, 1.0, 2.0, 3.0, 4.0));
229
229
 
230
- test('deserialized - mapbox', testDeserialization(mapboxDEM));
231
- test('deserialized - terrarium', testDeserialization(terrariumDEM));
232
- test('deserialized - custom', testDeserialization(customDEM));
230
+ test('deserialized - mapbox', expectDeserialization(mapboxDEM));
231
+ test('deserialized - terrarium', expectDeserialization(terrariumDEM));
232
+ test('deserialized - custom', expectDeserialization(customDEM));
233
233
  });
234
234
 
235
235
  describe('UnpackVector is correctly returned', () => {
@@ -244,7 +244,7 @@ describe('UnpackVector is correctly returned', () => {
244
244
  });
245
245
  });
246
246
 
247
- function testGetPixels(dem: DEMData, imageData: RGBAImage) {
247
+ function expectGetPixels(dem: DEMData, imageData: RGBAImage) {
248
248
  return () => {
249
249
  expect(dem.getPixels()).toEqual(imageData);
250
250
  };
@@ -256,9 +256,9 @@ describe('DEMData.getImage', () => {
256
256
  const terrariumDEM = new DEMData('0', imageData, 'terrarium');
257
257
  const customDEM = new DEMData('0', imageData, 'terrarium');
258
258
 
259
- test('Image is correctly returned - mapbox', testGetPixels(mapboxDEM, imageData));
260
- test('Image is correctly returned - terrarium', testGetPixels(terrariumDEM, imageData));
261
- test('Image is correctly returned - custom', testGetPixels(customDEM, imageData));
259
+ test('Image is correctly returned - mapbox', expectGetPixels(mapboxDEM, imageData));
260
+ test('Image is correctly returned - terrarium', expectGetPixels(terrariumDEM, imageData));
261
+ test('Image is correctly returned - custom', expectGetPixels(customDEM, imageData));
262
262
  });
263
263
 
264
264
  describe('DEMData pack and unpack', () => {
@@ -268,7 +268,7 @@ describe('DEMData pack and unpack', () => {
268
268
  expect(dem.unpack(123, 177, 215)).toEqual(800645.5);
269
269
  expect(dem.pack(800645.5)).toEqual({r: 123, g: 177, b: 215});
270
270
 
271
- expect(dem.unpack(0, 0, 0)).toEqual(-10000);
271
+ expect(dem.unpack(0, 0, 0)).toBe(-10000);
272
272
  expect(dem.pack(-10000)).toEqual({r: 0, g: 0, b: 0});
273
273
 
274
274
  expect(dem.unpack(1, 1, 1)).toBeCloseTo(-3420.7);
@@ -283,13 +283,13 @@ describe('DEMData pack and unpack', () => {
283
283
 
284
284
  test('terrarium', () => {
285
285
  const dem = new DEMData('0', imageData, 'terrarium');
286
- expect(dem.unpack(123, 177, 215)).toEqual(-1102.16015625);
286
+ expect(dem.unpack(123, 177, 215)).toBe(-1102.16015625);
287
287
  expect(dem.pack(-1102.16015625)).toEqual({r: 123, g: 177, b: 215});
288
288
 
289
- expect(dem.unpack(0, 0, 0)).toEqual(-32768);
289
+ expect(dem.unpack(0, 0, 0)).toBe(-32768);
290
290
  expect(dem.pack(-32768)).toEqual({r: 0, g: 0, b: 0});
291
291
 
292
- expect(dem.unpack(1, 1, 1)).toEqual(-32510.99609375);
292
+ expect(dem.unpack(1, 1, 1)).toBe(-32510.99609375);
293
293
  expect(dem.pack(-32510.99609375)).toEqual({r: 1, g: 1, b: 1});
294
294
 
295
295
  expect(dem.unpack(255, 255, 255)).toEqual(32767.99609375);
@@ -304,7 +304,7 @@ describe('DEMData pack and unpack', () => {
304
304
  expect(dem.unpack(123, 177, 215)).toEqual(3526918.75);
305
305
  expect(dem.pack(3526918.75)).toEqual({r: 123, g: 177, b: 215});
306
306
 
307
- expect(dem.unpack(0, 0, 0)).toEqual(-7000);
307
+ expect(dem.unpack(0, 0, 0)).toBe(-7000);
308
308
  expect(dem.pack(-7000)).toEqual({r: 0, g: 0, b: 0});
309
309
 
310
310
  expect(dem.unpack(1, 1, 1)).toEqual(9448.25);
@@ -29,6 +29,6 @@ describe('FeaturePositionMap', () => {
29
29
 
30
30
  expect(() => {
31
31
  featureMap.getPositions(0);
32
- }).toThrow();
32
+ }).toThrow('Trying to get index, but feature positions are not indexed');
33
33
  });
34
34
  });