@mapwhit/tilerenderer 0.50.0 → 0.51.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 (142) hide show
  1. package/build/min/package.json +1 -1
  2. package/build/min/src/shaders/.dir +0 -0
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +14 -0
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +14 -0
  5. package/build/min/src/shaders/background.fragment.glsl.js +5 -0
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -0
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +5 -0
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -0
  9. package/build/min/src/shaders/circle.fragment.glsl.js +20 -0
  10. package/build/min/src/shaders/circle.vertex.glsl.js +17 -0
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -0
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -0
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -0
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -0
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -0
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -0
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -0
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -0
  19. package/build/min/src/shaders/fill.fragment.glsl.js +10 -0
  20. package/build/min/src/shaders/fill.vertex.glsl.js +7 -0
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +5 -0
  22. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +9 -0
  23. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +15 -0
  24. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +11 -0
  25. package/build/min/src/shaders/fill_outline.fragment.glsl.js +10 -0
  26. package/build/min/src/shaders/fill_outline.vertex.glsl.js +7 -0
  27. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +13 -0
  28. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +9 -0
  29. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +13 -0
  30. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +9 -0
  31. package/build/min/src/shaders/heatmap.fragment.glsl.js +10 -0
  32. package/build/min/src/shaders/heatmap.vertex.glsl.js +8 -0
  33. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +5 -0
  34. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -0
  35. package/build/min/src/shaders/hillshade.fragment.glsl.js +7 -0
  36. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -0
  37. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +8 -0
  38. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -0
  39. package/build/min/src/shaders/line.fragment.glsl.js +12 -0
  40. package/build/min/src/shaders/line.vertex.glsl.js +17 -0
  41. package/build/min/src/shaders/line_gradient.fragment.glsl.js +10 -0
  42. package/build/min/src/shaders/line_gradient.vertex.glsl.js +16 -0
  43. package/build/min/src/shaders/line_pattern.fragment.glsl.js +15 -0
  44. package/build/min/src/shaders/line_pattern.vertex.glsl.js +20 -0
  45. package/build/min/src/shaders/line_sdf.fragment.glsl.js +17 -0
  46. package/build/min/src/shaders/line_sdf.vertex.glsl.js +20 -0
  47. package/build/min/src/shaders/raster.fragment.glsl.js +5 -0
  48. package/build/min/src/shaders/raster.vertex.glsl.js +1 -0
  49. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +9 -0
  50. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +5 -0
  51. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +19 -0
  52. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +13 -0
  53. package/package.json +7 -7
  54. package/src/data/bucket/fill_bucket.js +1 -1
  55. package/src/data/bucket/fill_extrusion_bucket.js +2 -2
  56. package/src/data/bucket/line_bucket.js +1 -1
  57. package/src/data/bucket/symbol_bucket.js +2 -2
  58. package/src/data/feature_index.js +1 -1
  59. package/src/data/program_configuration.js +1 -1
  60. package/src/gl/color_mode.js +1 -1
  61. package/src/gl/value.js +1 -1
  62. package/src/render/draw_debug.js +1 -1
  63. package/src/render/draw_fill.js +1 -1
  64. package/src/render/draw_heatmap.js +1 -1
  65. package/src/render/glyph_manager.js +6 -130
  66. package/src/render/painter.js +1 -1
  67. package/src/render/uniform_binding.js +1 -1
  68. package/src/shaders/index.js +50 -50
  69. package/src/source/geojson_worker_source.js +4 -4
  70. package/src/source/geojson_wrapper.js +34 -26
  71. package/src/source/resources/glyphs.js +73 -0
  72. package/src/source/resources/images.js +68 -0
  73. package/src/source/resources/index.js +22 -0
  74. package/src/source/vector_tile_worker_source.js +5 -5
  75. package/src/source/worker.js +6 -5
  76. package/src/source/worker_tile.js +4 -4
  77. package/src/style/properties.js +1 -2
  78. package/src/style/style.js +3 -3
  79. package/src/style/style_layer/symbol_style_layer.js +1 -1
  80. package/src/style/style_layer.js +1 -1
  81. package/src/style-spec/feature_filter/index.js +43 -34
  82. package/src/style-spec/group_by_layout.js +10 -32
  83. package/src/symbol/mergelines.js +0 -2
  84. package/src/symbol/symbol_layout.js +0 -1
  85. package/src/symbol/symbol_size.js +1 -1
  86. package/src/symbol/transform_text.js +0 -1
  87. package/src/ui/map.js +11 -39
  88. package/src/util/browser.js +3 -18
  89. package/src/util/classify_rings.js +1 -1
  90. package/src/util/dom.js +0 -88
  91. package/src/util/find_pole_of_inaccessibility.js +2 -2
  92. package/src/util/web_worker_transfer.js +4 -4
  93. package/src/style/load_glyph_range.js +0 -17
  94. package/src/style-spec/expression/compound_expression.js +0 -132
  95. package/src/style-spec/expression/definitions/assertion.js +0 -116
  96. package/src/style-spec/expression/definitions/at.js +0 -57
  97. package/src/style-spec/expression/definitions/case.js +0 -73
  98. package/src/style-spec/expression/definitions/coalesce.js +0 -66
  99. package/src/style-spec/expression/definitions/coercion.js +0 -120
  100. package/src/style-spec/expression/definitions/collator.js +0 -80
  101. package/src/style-spec/expression/definitions/comparison.js +0 -193
  102. package/src/style-spec/expression/definitions/format.js +0 -97
  103. package/src/style-spec/expression/definitions/index.js +0 -339
  104. package/src/style-spec/expression/definitions/interpolate.js +0 -245
  105. package/src/style-spec/expression/definitions/length.js +0 -54
  106. package/src/style-spec/expression/definitions/let.js +0 -60
  107. package/src/style-spec/expression/definitions/literal.js +0 -69
  108. package/src/style-spec/expression/definitions/match.js +0 -142
  109. package/src/style-spec/expression/definitions/step.js +0 -116
  110. package/src/style-spec/expression/definitions/var.js +0 -38
  111. package/src/style-spec/expression/evaluation_context.js +0 -38
  112. package/src/style-spec/expression/index.js +0 -330
  113. package/src/style-spec/expression/is_constant.js +0 -63
  114. package/src/style-spec/expression/parsing_context.js +0 -221
  115. package/src/style-spec/expression/parsing_error.js +0 -9
  116. package/src/style-spec/expression/runtime_error.js +0 -12
  117. package/src/style-spec/expression/scope.js +0 -34
  118. package/src/style-spec/expression/stops.js +0 -37
  119. package/src/style-spec/expression/types/collator.js +0 -24
  120. package/src/style-spec/expression/types/formatted.js +0 -39
  121. package/src/style-spec/expression/types.js +0 -88
  122. package/src/style-spec/expression/values.js +0 -149
  123. package/src/style-spec/function/convert.js +0 -240
  124. package/src/style-spec/function/index.js +0 -303
  125. package/src/style-spec/util/color.js +0 -73
  126. package/src/style-spec/util/color_spaces.js +0 -128
  127. package/src/style-spec/util/get_type.js +0 -18
  128. package/src/style-spec/util/interpolate.js +0 -21
  129. package/src/style-spec/util/properties.js +0 -17
  130. package/src/style-spec/util/result.js +0 -19
  131. package/src/ui/anchor.js +0 -24
  132. package/src/ui/bind_handlers.js +0 -199
  133. package/src/ui/events.js +0 -210
  134. package/src/ui/handler/box_zoom.js +0 -151
  135. package/src/ui/handler/dblclick_zoom.js +0 -91
  136. package/src/ui/handler/drag_pan.js +0 -285
  137. package/src/ui/handler/drag_rotate.js +0 -290
  138. package/src/ui/handler/frame.js +0 -28
  139. package/src/ui/handler/inertia.js +0 -45
  140. package/src/ui/handler/keyboard.js +0 -148
  141. package/src/ui/handler/scroll_zoom.js +0 -284
  142. package/src/ui/handler/touch_zoom_rotate.js +0 -263
@@ -0,0 +1,68 @@
1
+ module.exports = images;
2
+
3
+ function images({ actor, mapId }) {
4
+ const cache = new Map(); // id -> image
5
+ const inProgress = new Map(); // id -> promise
6
+
7
+ return {
8
+ getImages
9
+ };
10
+
11
+ async function getImages({ icons }) {
12
+ const missing = new Set();
13
+ const result = {};
14
+ for (const id of icons) {
15
+ if (cache.has(id)) {
16
+ const image = cache.get(id);
17
+ if (image) {
18
+ result[id] = image;
19
+ }
20
+ } else {
21
+ missing.add(id);
22
+ }
23
+ }
24
+ if (missing.size === 0) {
25
+ // All images are already in the cache
26
+ return result;
27
+ }
28
+ const active = new Set();
29
+ const needed = [...missing];
30
+ // Check if any of the missing images are already being fetched
31
+ for (const id of missing) {
32
+ if (inProgress.has(id)) {
33
+ active.add(inProgress.get(id));
34
+ missing.delete(id);
35
+ }
36
+ }
37
+ if (missing.size > 0) {
38
+ // Fetch the remaining images
39
+ await fetchMissing([...missing]);
40
+ }
41
+ if (active.size > 0) {
42
+ await Promise.all(active);
43
+ }
44
+ for (const id of needed) {
45
+ const image = cache.get(id);
46
+ if (image) {
47
+ result[id] = image;
48
+ }
49
+ }
50
+ return result;
51
+ }
52
+
53
+ async function fetchMissing(icons) {
54
+ const promise = actor.send('getImages', { icons }, mapId);
55
+ for (const id of icons) {
56
+ inProgress.set(id, promise);
57
+ }
58
+ const result = await promise;
59
+ // Add the fetched images to the cache
60
+ for (const id of icons) {
61
+ cache.set(id, result[id]);
62
+ }
63
+ // Remove the fetched images from the inProgress set
64
+ for (const id of icons) {
65
+ inProgress.delete(id);
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,22 @@
1
+ const makeGlyphs = require('./glyphs');
2
+ const makeImages = require('./images');
3
+
4
+ module.exports = { resources };
5
+
6
+ function resources(actor, mapId) {
7
+ const glyphs = makeGlyphs({ actor, mapId });
8
+ const images = makeImages({ actor, mapId });
9
+
10
+ return {
11
+ getGlyphs,
12
+ getImages
13
+ };
14
+
15
+ function getGlyphs(params) {
16
+ return glyphs.getGlyphs(params);
17
+ }
18
+
19
+ function getImages(params) {
20
+ return images.getImages(params);
21
+ }
22
+ }
@@ -1,4 +1,4 @@
1
- const { VectorTile } = require('@mapbox/vector-tile');
1
+ const { VectorTile } = require('@mapwhit/vector-tile');
2
2
  const Protobuf = require('@mapwhit/pbf');
3
3
  const WorkerTile = require('./worker_tile');
4
4
 
@@ -20,7 +20,7 @@ function loadVectorTile(params) {
20
20
  * This class is designed to be easily reused to support custom source types
21
21
  * for data formats that can be parsed/converted into an in-memory VectorTile
22
22
  * representation. To do so, create it with
23
- * `new VectorTileWorkerSource(actor, styleLayers, customLoadVectorDataFunction)`.
23
+ * `new VectorTileWorkerSource(resources, styleLayers, customLoadVectorDataFunction)`.
24
24
  *
25
25
  * @private
26
26
  */
@@ -31,8 +31,8 @@ class VectorTileWorkerSource {
31
31
  * {@link VectorTileWorkerSource#loadTile}. The default implementation simply
32
32
  * loads the pbf at `params.url`.
33
33
  */
34
- constructor(actor, layerIndex, loadVectorData = loadVectorTile) {
35
- this.actor = actor;
34
+ constructor(resources, layerIndex, loadVectorData = loadVectorTile) {
35
+ this.resources = resources;
36
36
  this.layerIndex = layerIndex;
37
37
  this.loadVectorData = loadVectorData;
38
38
  }
@@ -50,7 +50,7 @@ class VectorTileWorkerSource {
50
50
  const { vectorTile, rawData } = response;
51
51
  const workerTile = new WorkerTile(params);
52
52
  workerTile.vectorTile = vectorTile;
53
- const result = await workerTile.parse(vectorTile, this.layerIndex, this.actor);
53
+ const result = await workerTile.parse(vectorTile, this.layerIndex, this.resources);
54
54
  if (rawData) {
55
55
  result.rawTileData = rawData;
56
56
  }
@@ -8,8 +8,11 @@ const GeoJSONWorkerSource = require('./geojson_worker_source');
8
8
  const assert = require('assert');
9
9
  const { plugin: globalRTLTextPlugin } = require('./rtl_text_plugin');
10
10
  const DEMData = require('../data/dem_data');
11
+ const { resources } = require('./resources');
11
12
 
12
13
  class Worker {
14
+ #resources = {};
15
+
13
16
  constructor(self) {
14
17
  this.self = self;
15
18
  this.actor = new Actor(self, this);
@@ -85,10 +88,8 @@ class Worker {
85
88
  return (this.layerIndexes[mapId] ??= new StyleLayerIndex());
86
89
  }
87
90
 
88
- getActor(mapId) {
89
- return (this.actors[mapId] ??= {
90
- send: (type, data) => this.actor.send(type, data, mapId)
91
- });
91
+ getResources(mapId) {
92
+ return (this.#resources[mapId] ??= resources(this.actor, mapId));
92
93
  }
93
94
 
94
95
  getWorkerSource(mapId, type, source) {
@@ -100,7 +101,7 @@ class Worker {
100
101
 
101
102
  createWorkerSource(type, mapId) {
102
103
  const WorkerSource = this.workerSourceTypes[type];
103
- return new WorkerSource(this.getActor(mapId), this.getLayerIndex(mapId));
104
+ return new WorkerSource(this.getResources(mapId), this.getLayerIndex(mapId));
104
105
  }
105
106
  }
106
107
 
@@ -33,7 +33,7 @@ class WorkerTile {
33
33
  this.showCollisionBoxes = params.showCollisionBoxes;
34
34
  }
35
35
 
36
- async parse(data, layerIndex, actor) {
36
+ async parse(data, layerIndex, resources) {
37
37
  this.status = 'parsing';
38
38
  this.data = data;
39
39
 
@@ -103,9 +103,9 @@ class WorkerTile {
103
103
  const icons = Object.keys(options.iconDependencies);
104
104
  const patterns = Object.keys(options.patternDependencies);
105
105
  const tasks = [
106
- Object.keys(stacks).length ? actor.send('getGlyphs', { uid: this.uid, stacks }) : {},
107
- icons.length ? actor.send('getImages', { icons }) : {},
108
- patterns.length ? actor.send('getImages', { icons: patterns }) : {}
106
+ Object.keys(stacks).length ? resources.getGlyphs({ uid: this.uid, stacks }) : {},
107
+ icons.length ? resources.getImages({ icons }) : {},
108
+ patterns.length ? resources.getImages({ icons: patterns }) : {}
109
109
  ];
110
110
  const [glyphMap, iconMap, patternMap] = await Promise.all(tasks);
111
111
  const glyphAtlas = new GlyphAtlas(glyphMap);
@@ -2,8 +2,7 @@ const assert = require('assert');
2
2
 
3
3
  const { clone } = require('../util/object');
4
4
  const { easeCubicInOut } = require('../util/util');
5
- const interpolate = require('../style-spec/util/interpolate');
6
- const { normalizePropertyExpression } = require('../style-spec/expression');
5
+ const { interpolate, normalizePropertyExpression } = require('@mapwhit/style-expressions');
7
6
  const { register } = require('../util/transfer_registry');
8
7
  const EvaluationParameters = require('./evaluation_parameters');
9
8
 
@@ -32,7 +32,7 @@ class Style extends Evented {
32
32
  this.map = map;
33
33
  this.dispatcher = dispatcher(getWorkerPool(), this);
34
34
  this.imageManager = new ImageManager();
35
- this.glyphManager = new GlyphManager(options.localIdeographFontFamily);
35
+ this.glyphManager = new GlyphManager();
36
36
  this.lineAtlas = new LineAtlas(256, 512);
37
37
  this.crossTileSymbolIndex = new CrossTileSymbolIndex();
38
38
 
@@ -928,8 +928,8 @@ class Style extends Evented {
928
928
  return this.imageManager.getImages(icons);
929
929
  }
930
930
 
931
- getGlyphs(_mapId, { stacks }) {
932
- return this.glyphManager.getGlyphs(stacks);
931
+ loadGlyphRange(_mapId, { stack, range }) {
932
+ return this.glyphManager.loadGlyphRange(stack, range);
933
933
  }
934
934
  }
935
935
 
@@ -2,7 +2,7 @@ const StyleLayer = require('../style_layer');
2
2
 
3
3
  const SymbolBucket = require('../../data/bucket/symbol_bucket');
4
4
  const resolveTokens = require('../../util/token');
5
- const { isExpression } = require('../../style-spec/expression');
5
+ const { isExpression } = require('@mapwhit/style-expressions');
6
6
  const assert = require('assert');
7
7
  const properties = require('./symbol_style_layer_properties');
8
8
 
@@ -2,7 +2,7 @@ const { filterObject } = require('../util/object');
2
2
 
3
3
  const { Evented } = require('../util/evented');
4
4
  const { Layout, Transitionable, PossiblyEvaluatedPropertyValue } = require('./properties');
5
- const { supportsPropertyExpression } = require('../style-spec/util/properties');
5
+ const { supportsPropertyExpression } = require('@mapwhit/style-expressions');
6
6
 
7
7
  const TRANSITION_SUFFIX = '-transition';
8
8
 
@@ -1,4 +1,4 @@
1
- const { createExpression } = require('../expression');
1
+ const { createExpression } = require('@mapwhit/style-expressions');
2
2
 
3
3
  module.exports = createFilter;
4
4
 
@@ -31,8 +31,9 @@ function isExpressionFilter(filter) {
31
31
 
32
32
  case 'any':
33
33
  case 'all':
34
- for (const f of filter.slice(1)) {
35
- if (!isExpressionFilter(f) && typeof f !== 'boolean') {
34
+ for (let i = 1; i < filter.length; i++) {
35
+ const f = filter[i];
36
+ if (typeof f !== 'boolean' && !isExpressionFilter(f)) {
36
37
  return false;
37
38
  }
38
39
  }
@@ -86,34 +87,37 @@ function compare(a, b) {
86
87
 
87
88
  function convertFilter(filter) {
88
89
  if (!filter) return true;
89
- const op = filter[0];
90
+ const [op, ...args] = filter;
90
91
  if (filter.length <= 1) return op !== 'any';
91
- const converted =
92
- op === '=='
93
- ? convertComparisonOp(filter[1], filter[2], '==')
94
- : op === '!='
95
- ? convertNegation(convertComparisonOp(filter[1], filter[2], '=='))
96
- : op === '<' || op === '>' || op === '<=' || op === '>='
97
- ? convertComparisonOp(filter[1], filter[2], op)
98
- : op === 'any'
99
- ? convertDisjunctionOp(filter.slice(1))
100
- : op === 'all'
101
- ? ['all'].concat(filter.slice(1).map(convertFilter))
102
- : op === 'none'
103
- ? ['all'].concat(filter.slice(1).map(convertFilter).map(convertNegation))
104
- : op === 'in'
105
- ? convertInOp(filter[1], filter.slice(2))
106
- : op === '!in'
107
- ? convertNegation(convertInOp(filter[1], filter.slice(2)))
108
- : op === 'has'
109
- ? convertHasOp(filter[1])
110
- : op === '!has'
111
- ? convertNegation(convertHasOp(filter[1]))
112
- : true;
113
- return converted;
92
+ switch (op) {
93
+ case '!=':
94
+ return convertNegation(convertComparisonOp('==', ...args));
95
+ case '==':
96
+ case '<':
97
+ case '>':
98
+ case '<=':
99
+ case '>=':
100
+ return convertComparisonOp(op, ...args);
101
+ case 'any':
102
+ return convertDisjunctionOp(args);
103
+ case 'all':
104
+ return ['all', ...args.map(convertFilter)];
105
+ case 'none':
106
+ return ['all', ...args.map(convertFilter).map(convertNegation)];
107
+ case 'in':
108
+ return convertInOp(args);
109
+ case '!in':
110
+ return convertNegation(convertInOp(args));
111
+ case 'has':
112
+ return convertHasOp(args[0]);
113
+ case '!has':
114
+ return convertNegation(convertHasOp(args[0]));
115
+ default:
116
+ return true;
117
+ }
114
118
  }
115
119
 
116
- function convertComparisonOp(property, value, op) {
120
+ function convertComparisonOp(op, property, value) {
117
121
  switch (property) {
118
122
  case '$type':
119
123
  return [`filter-type-${op}`, value];
@@ -125,10 +129,10 @@ function convertComparisonOp(property, value, op) {
125
129
  }
126
130
 
127
131
  function convertDisjunctionOp(filters) {
128
- return ['any'].concat(filters.map(convertFilter));
132
+ return ['any', ...filters.map(convertFilter)];
129
133
  }
130
134
 
131
- function convertInOp(property, values) {
135
+ function convertInOp([property, ...values]) {
132
136
  if (values.length === 0) {
133
137
  return false;
134
138
  }
@@ -138,13 +142,18 @@ function convertInOp(property, values) {
138
142
  case '$id':
139
143
  return ['filter-id-in', ['literal', values]];
140
144
  default:
141
- if (values.length > 200 && !values.some(v => typeof v !== typeof values[0])) {
142
- return ['filter-in-large', property, ['literal', values.sort(compare)]];
143
- }
144
- return ['filter-in-small', property, ['literal', values]];
145
+ return isUniformLarge(values)
146
+ ? ['filter-in-large', property, ['literal', values.sort(compare)]]
147
+ : ['filter-in-small', property, ['literal', values]];
145
148
  }
146
149
  }
147
150
 
151
+ function isUniformLarge(values) {
152
+ if (values.length < 200) return false;
153
+ const type = typeof values[0];
154
+ return values.every(v => typeof v === type);
155
+ }
156
+
148
157
  function convertHasOp(property) {
149
158
  switch (property) {
150
159
  case '$type':
@@ -1,33 +1,20 @@
1
1
  const refProperties = require('./util/ref_properties');
2
2
 
3
3
  function stringify(obj) {
4
+ if (obj == null) return 'null';
4
5
  const type = typeof obj;
5
- if (type === 'number' || type === 'boolean' || type === 'string' || obj === undefined || obj === null)
6
- return JSON.stringify(obj);
6
+ if (type === 'number' || type === 'boolean' || type === 'string') return obj;
7
7
 
8
8
  if (Array.isArray(obj)) {
9
- let str = '[';
10
- for (const val of obj) {
11
- str += `${stringify(val)},`;
12
- }
13
- return `${str}]`;
9
+ return '[' + obj.map(val => stringify(val)).join(',') + ']';
14
10
  }
15
11
 
16
12
  const keys = Object.keys(obj).sort();
17
-
18
- let str = '{';
19
- for (let i = 0; i < keys.length; i++) {
20
- str += `${JSON.stringify(keys[i])}:${stringify(obj[keys[i]])},`;
21
- }
22
- return `${str}}`;
13
+ return '{' + keys.map(key => `${key}:${stringify(obj[key])}`).join(',') + '}';
23
14
  }
24
15
 
25
16
  function getKey(layer) {
26
- let key = '';
27
- for (const k of refProperties) {
28
- key += `/${stringify(layer[k])}`;
29
- }
30
- return key;
17
+ return refProperties.map(k => stringify(layer[k])).join('/');
31
18
  }
32
19
 
33
20
  module.exports = groupByLayout;
@@ -49,20 +36,11 @@ module.exports = groupByLayout;
49
36
  function groupByLayout(layers) {
50
37
  const groups = {};
51
38
 
52
- for (let i = 0; i < layers.length; i++) {
53
- const k = getKey(layers[i]);
54
- let group = groups[k];
55
- if (!group) {
56
- group = groups[k] = [];
57
- }
58
- group.push(layers[i]);
59
- }
60
-
61
- const result = [];
62
-
63
- for (const k in groups) {
64
- result.push(groups[k]);
39
+ for (const l of layers) {
40
+ const k = getKey(l);
41
+ const group = (groups[k] ??= []);
42
+ group.push(l);
65
43
  }
66
44
 
67
- return result;
45
+ return Object.values(groups);
68
46
  }
@@ -1,5 +1,3 @@
1
- const { Formatted } = require('../style-spec/expression/types/formatted');
2
-
3
1
  module.exports = function (features) {
4
2
  const leftIndex = new Map();
5
3
  const rightIndex = new Map();
@@ -12,7 +12,6 @@ const classifyRings = require('../util/classify_rings');
12
12
  const EXTENT = require('../data/extent');
13
13
  const SymbolBucket = require('../data/bucket/symbol_bucket');
14
14
  const EvaluationParameters = require('../style/evaluation_parameters');
15
- const { Formatted } = require('../style-spec/expression/types/formatted');
16
15
  const murmur3 = require('murmurhash-js');
17
16
 
18
17
  // The symbol layout process needs `text-size` evaluated at up to five different zoom levels, and
@@ -1,4 +1,4 @@
1
- const { normalizePropertyExpression } = require('../style-spec/expression');
1
+ const { normalizePropertyExpression } = require('@mapwhit/style-expressions');
2
2
 
3
3
  const interpolate = require('../util/interpolate');
4
4
  const { clamp } = require('../util/util');
@@ -1,5 +1,4 @@
1
1
  const { plugin: rtlTextPlugin } = require('../source/rtl_text_plugin');
2
- const { Formatted } = require('../style-spec/expression/types/formatted');
3
2
 
4
3
  function transformText(text, layer, feature) {
5
4
  const transform = layer.layout.get('text-transform').evaluate(feature, {});
package/src/ui/map.js CHANGED
@@ -9,7 +9,6 @@ const Style = require('../style/style');
9
9
  const EvaluationParameters = require('../style/evaluation_parameters');
10
10
  const Painter = require('../render/painter');
11
11
  const Transform = require('../geo/transform');
12
- const bindHandlers = require('./bind_handlers');
13
12
  const Camera = require('./camera');
14
13
  const LngLat = require('../geo/lng_lat');
15
14
  const LngLatBounds = require('../geo/lng_lat_bounds');
@@ -31,18 +30,8 @@ const defaultOptions = {
31
30
 
32
31
  interactive: true,
33
32
 
34
- scrollZoom: true,
35
- boxZoom: true,
36
- dragRotate: true,
37
- dragPan: true,
38
- keyboard: true,
39
- doubleClickZoom: true,
40
- touchZoomRotate: true,
41
-
42
33
  bearingSnap: 7,
43
34
 
44
- clickTolerance: 3,
45
-
46
35
  attributionControl: true,
47
36
 
48
37
  failIfMajorPerformanceCaveat: false,
@@ -98,19 +87,11 @@ const defaultOptions = {
98
87
  * bearing will snap to north. For example, with a `bearingSnap` of 7, if the user rotates
99
88
  * the map within 7 degrees of north, the map will automatically snap to exact north.
100
89
  * @param {boolean} [options.pitchWithRotate=true] If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled.
101
- * @param {number} [options.clickTolerance=3] The max number of pixels a user can shift the mouse pointer during a click for it to be considered a valid click (as opposed to a mouse drag).
102
90
  * @param {string} [options.logoPosition='bottom-left'] A string representing the position of the Mapbox wordmark on the map. Valid options are `top-left`,`top-right`, `bottom-left`, `bottom-right`.
103
91
  * @param {boolean} [options.failIfMajorPerformanceCaveat=false] If `true`, map creation will fail if the performance of Mapbox
104
92
  * GL JS would be dramatically worse than expected (i.e. a software renderer would be used).
105
93
  * @param {boolean} [options.preserveDrawingBuffer=false] If `true`, the map's canvas can be exported to a PNG using `map.getCanvas().toDataURL()`. This is `false` by default as a performance optimization.
106
94
  * @param {LngLatBoundsLike} [options.maxBounds] If set, the map will be constrained to the given bounds.
107
- * @param {boolean|Object} [options.scrollZoom=true] If `true`, the "scroll to zoom" interaction is enabled. An `Object` value is passed as options to {@link ScrollZoomHandler#enable}.
108
- * @param {boolean} [options.boxZoom=true] If `true`, the "box zoom" interaction is enabled (see {@link BoxZoomHandler}).
109
- * @param {boolean} [options.dragRotate=true] If `true`, the "drag to rotate" interaction is enabled (see {@link DragRotateHandler}).
110
- * @param {boolean} [options.dragPan=true] If `true`, the "drag to pan" interaction is enabled (see {@link DragPanHandler}).
111
- * @param {boolean} [options.keyboard=true] If `true`, keyboard shortcuts are enabled (see {@link KeyboardHandler}).
112
- * @param {boolean} [options.doubleClickZoom=true] If `true`, the "double click to zoom" interaction is enabled (see {@link DoubleClickZoomHandler}).
113
- * @param {boolean|Object} [options.touchZoomRotate=true] If `true`, the "pinch to rotate and zoom" interaction is enabled. An `Object` value is passed as options to {@link TouchZoomRotateHandler#enable}.
114
95
  * @param {boolean} [options.trackResize=true] If `true`, the map will automatically resize when the browser window resizes.
115
96
  * @param {LngLatLike} [options.center=[0, 0]] The inital geographical centerpoint of the map. If `center` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `[0, 0]` Note: Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
116
97
  * @param {number} [options.zoom=0] The initial zoom level of the map. If `zoom` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
@@ -118,10 +99,6 @@ const defaultOptions = {
118
99
  * @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-60). If `pitch` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
119
100
  * @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered, when zoomed out.
120
101
  * @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
121
- * @param {string} [options.localIdeographFontFamily=null] If specified, defines a CSS font-family
122
- * for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables' ranges.
123
- * In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
124
- * The purpose of this option is to avoid bandwidth-intensive glyph server requests. (see [Use locally generated ideographs](https://www.mapbox.com/mapbox-gl-js/example/local-ideographs))
125
102
  * @param {number} [options.fadeDuration=300] Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
126
103
  * @param {boolean} [options.crossSourceCollisions=true] If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
127
104
  * @example
@@ -134,6 +111,8 @@ const defaultOptions = {
134
111
  * @see [Display a map](https://www.mapbox.com/mapbox-gl-js/examples/)
135
112
  */
136
113
  class Map extends Camera {
114
+ #mapGestures;
115
+
137
116
  constructor(options) {
138
117
  options = Object.assign({}, defaultOptions, options);
139
118
 
@@ -203,8 +182,6 @@ class Map extends Camera {
203
182
  window.addEventListener('resize', this._onWindowResize, false);
204
183
  }
205
184
 
206
- bindHandlers(this, options);
207
-
208
185
  this.jumpTo({
209
186
  center: options.center,
210
187
  zoom: options.zoom,
@@ -214,7 +191,7 @@ class Map extends Camera {
214
191
 
215
192
  this.resize();
216
193
 
217
- if (options.style) this.setStyle(options.style, { localIdeographFontFamily: options.localIdeographFontFamily });
194
+ if (options.style) this.setStyle(options.style);
218
195
 
219
196
  this.on('style.load', function () {
220
197
  if (this.transform.unmodified) {
@@ -465,27 +442,21 @@ class Map extends Camera {
465
442
  * Returns true if the map is panning, zooming, rotating, or pitching due to a camera animation or user gesture.
466
443
  */
467
444
  isMoving() {
468
- return (
469
- this._moving ||
470
- this.dragPan.isActive() ||
471
- this.dragRotate.isActive() ||
472
- this.touchZoomRotate.isActive() ||
473
- this.scrollZoom.isActive()
474
- );
445
+ return !!(this._moving || this._mapGestures?.isMoving());
475
446
  }
476
447
 
477
448
  /**
478
449
  * Returns true if the map is zooming due to a camera animation or user gesture.
479
450
  */
480
451
  isZooming() {
481
- return this._zooming || this.touchZoomRotate.isActive() || this.scrollZoom.isZooming();
452
+ return !!(this._zooming || this._mapGestures?.isZooming());
482
453
  }
483
454
 
484
455
  /**
485
456
  * Returns true if the map is rotating due to a camera animation or user gesture.
486
457
  */
487
458
  isRotating() {
488
- return this._rotating || this.touchZoomRotate.isActive() || this.dragRotate.isActive();
459
+ return !!(this._rotating || this._mapGestures?.isRotating());
489
460
  }
490
461
 
491
462
  /**
@@ -666,9 +637,6 @@ class Map extends Camera {
666
637
  * @param {Object} [options]
667
638
  * @param {boolean} [options.diff=true] If false, force a 'full' update, removing the current style
668
639
  * and adding building the given one instead of attempting a diff-based update.
669
- * @param {string} [options.localIdeographFontFamily=null] If non-null, defines a css font-family
670
- * for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables'
671
- * ranges. Forces a full update.
672
640
  * @returns {Map} `this`
673
641
  * @see [Change a map's style](https://www.mapbox.com/mapbox-gl-js/example/setstyle/)
674
642
  */
@@ -823,7 +791,11 @@ class Map extends Camera {
823
791
  );
824
792
  } else {
825
793
  const { width, height, data } = image;
826
- this.style.addImage(id, { data: new RGBAImage({ width, height }, new Uint8Array(data)), pixelRatio, sdf });
794
+ this.style.addImage(id, {
795
+ data: new RGBAImage({ width, height }, new Uint8Array(data)),
796
+ pixelRatio,
797
+ sdf
798
+ });
827
799
  }
828
800
  }
829
801
 
@@ -1,25 +1,10 @@
1
1
  // TODO move code that assumes that `window` may not be set to relevant tests
2
2
 
3
- const now =
4
- typeof window === 'object' && window.performance?.now
5
- ? window.performance.now.bind(window.performance)
6
- : Date.now.bind(Date);
3
+ const now = () => performance.now();
7
4
 
8
- const raf =
9
- typeof window === 'object'
10
- ? window.requestAnimationFrame ||
11
- window.mozRequestAnimationFrame ||
12
- window.webkitRequestAnimationFrame ||
13
- window.msRequestAnimationFrame
14
- : fn => setTimeout(fn, 0);
5
+ const raf = typeof window === 'object' ? window.requestAnimationFrame : fn => setTimeout(fn, 0);
15
6
 
16
- const cancel =
17
- typeof window === 'object'
18
- ? window.cancelAnimationFrame ||
19
- window.mozCancelAnimationFrame ||
20
- window.webkitCancelAnimationFrame ||
21
- window.msCancelAnimationFrame
22
- : id => clearTimeout(id);
7
+ const cancel = typeof window === 'object' ? window.cancelAnimationFrame : id => clearTimeout(id);
23
8
 
24
9
  /**
25
10
  * @private
@@ -1,4 +1,4 @@
1
- const quickselect = require('quickselect');
1
+ const { default: quickselect } = require('quickselect');
2
2
 
3
3
  const { calculateSignedArea } = require('./util');
4
4