@mapwhit/tilerenderer 0.52.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +7 -0
  2. package/build/min/package.json +2 -1
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +2 -2
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +2 -2
  5. package/build/min/src/shaders/background.fragment.glsl.js +2 -2
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -1
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +2 -2
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -1
  9. package/build/min/src/shaders/circle.fragment.glsl.js +2 -2
  10. package/build/min/src/shaders/circle.vertex.glsl.js +2 -2
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -1
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -1
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -1
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -1
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -1
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -1
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -1
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -1
  19. package/build/min/src/shaders/fill.fragment.glsl.js +2 -2
  20. package/build/min/src/shaders/fill.vertex.glsl.js +2 -2
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +2 -2
  22. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +2 -2
  23. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +2 -2
  24. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +2 -2
  25. package/build/min/src/shaders/fill_outline.fragment.glsl.js +2 -2
  26. package/build/min/src/shaders/fill_outline.vertex.glsl.js +2 -2
  27. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +2 -2
  28. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +2 -2
  29. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +2 -2
  30. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +2 -2
  31. package/build/min/src/shaders/heatmap.fragment.glsl.js +2 -2
  32. package/build/min/src/shaders/heatmap.vertex.glsl.js +2 -2
  33. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +2 -2
  34. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -1
  35. package/build/min/src/shaders/hillshade.fragment.glsl.js +2 -2
  36. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -1
  37. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +2 -2
  38. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -1
  39. package/build/min/src/shaders/line.fragment.glsl.js +2 -2
  40. package/build/min/src/shaders/line.vertex.glsl.js +2 -2
  41. package/build/min/src/shaders/line_gradient.fragment.glsl.js +2 -2
  42. package/build/min/src/shaders/line_gradient.vertex.glsl.js +2 -2
  43. package/build/min/src/shaders/line_pattern.fragment.glsl.js +2 -2
  44. package/build/min/src/shaders/line_pattern.vertex.glsl.js +2 -2
  45. package/build/min/src/shaders/line_sdf.fragment.glsl.js +2 -2
  46. package/build/min/src/shaders/line_sdf.vertex.glsl.js +2 -2
  47. package/build/min/src/shaders/raster.fragment.glsl.js +2 -2
  48. package/build/min/src/shaders/raster.vertex.glsl.js +1 -1
  49. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +2 -2
  50. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +2 -2
  51. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +2 -2
  52. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +2 -2
  53. package/package.json +5 -4
  54. package/src/data/array_types.js +55 -117
  55. package/src/data/bucket/circle_attributes.js +2 -4
  56. package/src/data/bucket/circle_bucket.js +19 -16
  57. package/src/data/bucket/fill_attributes.js +2 -4
  58. package/src/data/bucket/fill_bucket.js +38 -27
  59. package/src/data/bucket/fill_extrusion_attributes.js +2 -4
  60. package/src/data/bucket/fill_extrusion_bucket.js +56 -37
  61. package/src/data/bucket/heatmap_bucket.js +2 -11
  62. package/src/data/bucket/line_attributes.js +2 -4
  63. package/src/data/bucket/line_bucket.js +208 -163
  64. package/src/data/bucket/pattern_attributes.js +2 -4
  65. package/src/data/bucket/pattern_bucket_features.js +7 -9
  66. package/src/data/bucket/symbol_attributes.js +12 -26
  67. package/src/data/bucket/symbol_bucket.js +174 -323
  68. package/src/data/bucket/symbol_buffers.js +62 -0
  69. package/src/data/bucket/symbol_collision_buffers.js +33 -0
  70. package/src/data/bucket.js +26 -25
  71. package/src/data/dem_data.js +11 -10
  72. package/src/data/extent.js +1 -1
  73. package/src/data/feature_index.js +38 -28
  74. package/src/data/index_array_type.js +1 -6
  75. package/src/data/load_geometry.js +6 -9
  76. package/src/data/pos_attributes.js +2 -3
  77. package/src/data/program_configuration.js +47 -38
  78. package/src/data/raster_bounds_attributes.js +2 -2
  79. package/src/data/segment.js +4 -7
  80. package/src/geo/coordinate.js +1 -1
  81. package/src/geo/lng_lat.js +3 -3
  82. package/src/geo/lng_lat_bounds.js +8 -4
  83. package/src/geo/transform.js +69 -30
  84. package/src/gl/color_mode.js +2 -2
  85. package/src/gl/context.js +28 -29
  86. package/src/gl/cull_face_mode.js +1 -1
  87. package/src/gl/depth_mode.js +1 -1
  88. package/src/gl/framebuffer.js +8 -4
  89. package/src/gl/index_buffer.js +2 -2
  90. package/src/gl/stencil_mode.js +1 -1
  91. package/src/gl/value.js +33 -68
  92. package/src/gl/vertex_buffer.js +2 -2
  93. package/src/index.js +49 -25
  94. package/src/render/draw_background.js +17 -12
  95. package/src/render/draw_circle.js +15 -12
  96. package/src/render/draw_collision_debug.js +11 -8
  97. package/src/render/draw_debug.js +16 -14
  98. package/src/render/draw_fill.js +27 -20
  99. package/src/render/draw_fill_extrusion.js +20 -17
  100. package/src/render/draw_heatmap.js +21 -16
  101. package/src/render/draw_hillshade.js +12 -9
  102. package/src/render/draw_line.js +36 -22
  103. package/src/render/draw_raster.js +22 -18
  104. package/src/render/draw_symbol.js +38 -33
  105. package/src/render/glyph_atlas.js +9 -8
  106. package/src/render/glyph_manager.js +2 -3
  107. package/src/render/image_atlas.js +4 -11
  108. package/src/render/image_manager.js +39 -28
  109. package/src/render/line_atlas.js +2 -2
  110. package/src/render/painter.js +78 -61
  111. package/src/render/program/background_program.js +6 -13
  112. package/src/render/program/circle_program.js +8 -10
  113. package/src/render/program/clipping_mask_program.js +3 -5
  114. package/src/render/program/collision_program.js +4 -6
  115. package/src/render/program/debug_program.js +3 -5
  116. package/src/render/program/fill_extrusion_program.js +9 -15
  117. package/src/render/program/fill_program.js +10 -21
  118. package/src/render/program/heatmap_program.js +9 -15
  119. package/src/render/program/hillshade_program.js +16 -22
  120. package/src/render/program/line_program.js +14 -25
  121. package/src/render/program/pattern.js +5 -7
  122. package/src/render/program/program_uniforms.js +13 -20
  123. package/src/render/program/raster_program.js +9 -11
  124. package/src/render/program/symbol_program.js +5 -7
  125. package/src/render/program.js +5 -6
  126. package/src/render/texture.js +1 -1
  127. package/src/render/tile_mask.js +6 -4
  128. package/src/render/uniform_binding.js +9 -20
  129. package/src/render/vertex_array_object.js +5 -3
  130. package/src/shaders/encode_attribute.js +2 -6
  131. package/src/shaders/index.js +103 -51
  132. package/src/source/geojson_source.js +25 -30
  133. package/src/source/geojson_worker_source.js +46 -74
  134. package/src/source/geojson_wrapper.js +13 -5
  135. package/src/source/image_source.js +17 -28
  136. package/src/source/load_tilejson.js +3 -3
  137. package/src/source/pixels_to_tile_units.js +3 -3
  138. package/src/source/query_features.js +17 -15
  139. package/src/source/raster_dem_tile_source.js +54 -71
  140. package/src/source/raster_tile_source.js +14 -15
  141. package/src/source/resources/glyphs.js +4 -5
  142. package/src/source/resources/index.js +4 -12
  143. package/src/source/rtl_text_plugin.js +62 -35
  144. package/src/source/source.js +14 -22
  145. package/src/source/source_cache.js +221 -179
  146. package/src/source/source_state.js +125 -13
  147. package/src/source/tile.js +67 -66
  148. package/src/source/tile_bounds.js +36 -29
  149. package/src/source/tile_cache.js +2 -2
  150. package/src/source/tile_id.js +30 -26
  151. package/src/source/vector_tile_source.js +23 -21
  152. package/src/source/vector_tile_worker_source.js +22 -26
  153. package/src/source/worker_tile.js +139 -134
  154. package/src/style/create_style_layer.js +11 -11
  155. package/src/style/evaluation_parameters.js +4 -6
  156. package/src/style/light.js +5 -5
  157. package/src/style/load_sprite.js +6 -6
  158. package/src/style/parse_glyph_pbf.js +21 -17
  159. package/src/style/pauseable_placement.js +7 -9
  160. package/src/style/properties.js +21 -51
  161. package/src/style/query_utils.js +7 -13
  162. package/src/style/style.js +314 -221
  163. package/src/style/style_layer/background_style_layer.js +3 -4
  164. package/src/style/style_layer/background_style_layer_properties.js +2 -2
  165. package/src/style/style_layer/circle_style_layer.js +25 -20
  166. package/src/style/style_layer/circle_style_layer_properties.js +2 -2
  167. package/src/style/style_layer/fill_extrusion_style_layer.js +55 -37
  168. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +2 -2
  169. package/src/style/style_layer/fill_style_layer.js +11 -12
  170. package/src/style/style_layer/fill_style_layer_properties.js +2 -2
  171. package/src/style/style_layer/heatmap_style_layer.js +6 -7
  172. package/src/style/style_layer/heatmap_style_layer_properties.js +2 -2
  173. package/src/style/style_layer/hillshade_style_layer.js +4 -5
  174. package/src/style/style_layer/hillshade_style_layer_properties.js +2 -2
  175. package/src/style/style_layer/line_style_layer.js +33 -30
  176. package/src/style/style_layer/line_style_layer_properties.js +5 -5
  177. package/src/style/style_layer/raster_style_layer.js +3 -4
  178. package/src/style/style_layer/raster_style_layer_properties.js +2 -2
  179. package/src/style/style_layer/symbol_style_layer.js +20 -21
  180. package/src/style/style_layer/symbol_style_layer_properties.js +2 -2
  181. package/src/style/style_layer.js +66 -47
  182. package/src/style/style_layer_index.js +17 -42
  183. package/src/style/zoom_history.js +1 -1
  184. package/src/style-spec/error/parsing_error.js +1 -1
  185. package/src/style-spec/error/validation_error.js +5 -3
  186. package/src/style-spec/feature_filter/convert.js +17 -9
  187. package/src/style-spec/feature_filter/index.js +13 -9
  188. package/src/style-spec/util/eval_support.js +2 -2
  189. package/src/style-spec/util/ref_properties.js +1 -1
  190. package/src/symbol/anchor.js +2 -6
  191. package/src/symbol/check_max_angle.js +13 -5
  192. package/src/symbol/clip_line.js +2 -3
  193. package/src/symbol/collision_feature.js +8 -4
  194. package/src/symbol/collision_index.js +5 -7
  195. package/src/symbol/cross_tile_symbol_index.js +7 -10
  196. package/src/symbol/get_anchors.js +15 -8
  197. package/src/symbol/grid_index.js +5 -3
  198. package/src/symbol/mergelines.js +2 -2
  199. package/src/symbol/opacity_state.js +1 -5
  200. package/src/symbol/placement.js +28 -23
  201. package/src/symbol/projection.js +29 -28
  202. package/src/symbol/quads.js +14 -16
  203. package/src/symbol/shaping.js +27 -19
  204. package/src/symbol/symbol_layout.js +24 -28
  205. package/src/symbol/symbol_size.js +13 -12
  206. package/src/symbol/transform_text.js +4 -4
  207. package/src/ui/camera.js +34 -18
  208. package/src/ui/map.js +102 -44
  209. package/src/util/async.js +11 -5
  210. package/src/util/browser.js +1 -1
  211. package/src/util/callback.js +3 -9
  212. package/src/util/classify_rings.js +13 -8
  213. package/src/util/color_ramp.js +3 -3
  214. package/src/util/config.js +4 -4
  215. package/src/util/dictionary_coder.js +2 -3
  216. package/src/util/dom.js +7 -3
  217. package/src/util/find_pole_of_inaccessibility.js +29 -14
  218. package/src/util/group_layers.js +41 -0
  219. package/src/util/image.js +3 -13
  220. package/src/util/interpolate.js +1 -1
  221. package/src/util/intersection_tests.js +80 -42
  222. package/src/util/is_char_in_unicode_block.js +1 -1
  223. package/src/util/key.js +25 -0
  224. package/src/util/loader/image.js +1 -1
  225. package/src/util/object.js +33 -76
  226. package/src/util/script_detection.js +212 -91
  227. package/src/util/struct_array.js +8 -40
  228. package/src/util/task_queue.js +11 -7
  229. package/src/util/throttle.js +2 -2
  230. package/src/util/tile_cover.js +8 -5
  231. package/src/util/token.js +1 -1
  232. package/src/util/unique_id.js +2 -2
  233. package/src/util/util.js +21 -29
  234. package/src/util/vectortile_to_geojson.js +4 -2
  235. package/src/util/verticalize_punctuation.js +3 -7
  236. package/src/util/warn.js +4 -4
  237. package/src/util/web_worker.js +3 -3
  238. package/src/worker.js +1 -4
  239. package/src/source/resources/images.js +0 -68
  240. package/src/source/worker.js +0 -110
  241. package/src/source/worker_source.js +0 -14
  242. package/src/style-spec/deref.js +0 -51
  243. package/src/style-spec/group_by_layout.js +0 -46
  244. package/src/util/actor.js +0 -108
  245. package/src/util/dispatcher.js +0 -65
  246. package/src/util/global_worker_pool.js +0 -15
  247. package/src/util/transfer_registry.js +0 -168
  248. package/src/util/web_worker_transfer.js +0 -43
  249. package/src/util/worker_pool.js +0 -41
@@ -1,7 +1,6 @@
1
- const { default: Queue } = require('tinyqueue');
2
-
3
- const { default: Point } = require('@mapbox/point-geometry');
4
- const { distToSegmentSquared } = require('./intersection_tests');
1
+ import Point from '@mapbox/point-geometry';
2
+ import Queue from 'tinyqueue';
3
+ import { distToSegmentSquared } from './intersection_tests.js';
5
4
 
6
5
  /**
7
6
  * Finds an approximation of a polygon's Pole Of Inaccessibiliy https://en.wikipedia.org/wiki/Pole_of_inaccessibility
@@ -13,7 +12,7 @@ const { distToSegmentSquared } = require('./intersection_tests');
13
12
  * @returns Pole of Inaccessibiliy.
14
13
  * @private
15
14
  */
16
- module.exports = function (polygonRings, precision = 1, debug = false) {
15
+ export default function (polygonRings, precision = 1, debug = false) {
17
16
  // find the bounding box of the outer ring
18
17
  let minX = Number.POSITIVE_INFINITY;
19
18
  let minY = Number.POSITIVE_INFINITY;
@@ -22,10 +21,18 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
22
21
  const outerRing = polygonRings[0];
23
22
  for (let i = 0; i < outerRing.length; i++) {
24
23
  const p = outerRing[i];
25
- if (!i || p.x < minX) minX = p.x;
26
- if (!i || p.y < minY) minY = p.y;
27
- if (!i || p.x > maxX) maxX = p.x;
28
- if (!i || p.y > maxY) maxY = p.y;
24
+ if (!i || p.x < minX) {
25
+ minX = p.x;
26
+ }
27
+ if (!i || p.y < minY) {
28
+ minY = p.y;
29
+ }
30
+ if (!i || p.x > maxX) {
31
+ maxX = p.x;
32
+ }
33
+ if (!i || p.y > maxY) {
34
+ maxY = p.y;
35
+ }
29
36
  }
30
37
 
31
38
  const width = maxX - minX;
@@ -36,7 +43,9 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
36
43
  // a priority queue of cells in order of their "potential" (max distance to polygon)
37
44
  const cellQueue = new Queue(undefined, compareMax);
38
45
 
39
- if (cellSize === 0) return new Point(minX, minY);
46
+ if (cellSize === 0) {
47
+ return new Point(minX, minY);
48
+ }
40
49
 
41
50
  // cover polygon with initial cells
42
51
  for (let x = minX; x < maxX; x += cellSize) {
@@ -56,11 +65,15 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
56
65
  // update the best cell if we found a better one
57
66
  if (cell.d > bestCell.d || !bestCell.d) {
58
67
  bestCell = cell;
59
- if (debug) console.log('found best %d after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
68
+ if (debug) {
69
+ console.log('found best %d after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
70
+ }
60
71
  }
61
72
 
62
73
  // do not drill down further if there's no chance of a better solution
63
- if (cell.max - bestCell.d <= precision) continue;
74
+ if (cell.max - bestCell.d <= precision) {
75
+ continue;
76
+ }
64
77
 
65
78
  // split the cell into four cells
66
79
  h = cell.h / 2;
@@ -77,7 +90,7 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
77
90
  }
78
91
 
79
92
  return bestCell.p;
80
- };
93
+ }
81
94
 
82
95
  function compareMax(a, b) {
83
96
  return b.max - a.max;
@@ -102,7 +115,9 @@ function pointToPolygonDist(p, polygon) {
102
115
  const a = ring[i];
103
116
  const b = ring[j];
104
117
 
105
- if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x) inside = !inside;
118
+ if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x) {
119
+ inside = !inside;
120
+ }
106
121
 
107
122
  minDistSq = Math.min(minDistSq, distToSegmentSquared(p, a, b));
108
123
  }
@@ -0,0 +1,41 @@
1
+ export default groupBySource;
2
+
3
+ /**
4
+ * Given an collection of layers, divide them by property 'source', then by 'source-layer',
5
+ * and then by layout-affecting properties: 'type', , 'minzoom', 'maxzoom', 'filter', and 'layout'.
6
+ *
7
+ * The input is not modified. The output layers are references to the
8
+ * input layers.
9
+ *
10
+ * @param layers iterable collection of layers
11
+ * @returns Map source to {Map source-layer to {Map layout key to Array of layers}}
12
+ */
13
+ function groupBySource(layers) {
14
+ const groups = new Map();
15
+
16
+ // Iterate through each layer and group them by source, source-layer, and layout properties
17
+ for (const layer of layers) {
18
+ if (layer.visibility === 'none') {
19
+ continue;
20
+ }
21
+
22
+ const { source = '', sourceLayer = '_geojsonTileLayer' } = layer;
23
+ let sourceGroup = groups.get(source);
24
+ if (!sourceGroup) {
25
+ sourceGroup = new Map();
26
+ groups.set(source, sourceGroup);
27
+ }
28
+ let sourceLayerGroup = sourceGroup.get(sourceLayer);
29
+ if (!sourceLayerGroup) {
30
+ sourceLayerGroup = new Map();
31
+ sourceGroup.set(sourceLayer, sourceLayerGroup);
32
+ }
33
+ let layoutGroup = sourceLayerGroup.get(layer.key);
34
+ if (!layoutGroup) {
35
+ layoutGroup = [];
36
+ sourceLayerGroup.set(layer.key, layoutGroup);
37
+ }
38
+ layoutGroup.push(layer);
39
+ }
40
+ return groups;
41
+ }
package/src/util/image.js CHANGED
@@ -1,6 +1,4 @@
1
- const assert = require('assert');
2
-
3
- const { register } = require('./transfer_registry');
1
+ import assert from 'assert';
4
2
 
5
3
  function createImage(image, { width, height }, channels, data) {
6
4
  if (!data) {
@@ -77,7 +75,7 @@ function copyImage(srcImg, dstImg, srcPt, dstPt, size, channels) {
77
75
  return dstImg;
78
76
  }
79
77
 
80
- class AlphaImage {
78
+ export class AlphaImage {
81
79
  constructor(size, data) {
82
80
  createImage(this, size, 1, data);
83
81
  }
@@ -97,7 +95,7 @@ class AlphaImage {
97
95
 
98
96
  // Not premultiplied, because ImageData is not premultiplied.
99
97
  // UNPACK_PREMULTIPLY_ALPHA_WEBGL must be used when uploading to a texture.
100
- class RGBAImage {
98
+ export class RGBAImage {
101
99
  constructor(size, data) {
102
100
  createImage(this, size, 4, data);
103
101
  }
@@ -114,11 +112,3 @@ class RGBAImage {
114
112
  copyImage(srcImg, dstImg, srcPt, dstPt, size, 4);
115
113
  }
116
114
  }
117
-
118
- register('AlphaImage', AlphaImage);
119
- register('RGBAImage', RGBAImage);
120
-
121
- module.exports = {
122
- AlphaImage,
123
- RGBAImage
124
- };
@@ -1,4 +1,4 @@
1
- module.exports = interpolate;
1
+ export default interpolate;
2
2
 
3
3
  function interpolate(a, b, t) {
4
4
  return a * (1 - t) + b * t;
@@ -1,36 +1,37 @@
1
- const { isCounterClockwise } = require('./util');
2
- const { default: Point } = require('@mapbox/point-geometry');
3
-
4
- module.exports = {
5
- polygonIntersectsBufferedPoint,
6
- polygonIntersectsMultiPolygon,
7
- polygonIntersectsBufferedMultiLine,
8
- polygonIntersectsPolygon,
9
- distToSegmentSquared,
10
- polygonIntersectsBox
11
- };
12
-
13
- function polygonIntersectsPolygon(polygonA, polygonB) {
1
+ import Point from '@mapbox/point-geometry';
2
+ import { isCounterClockwise } from './util.js';
3
+
4
+ export function polygonIntersectsPolygon(polygonA, polygonB) {
14
5
  for (let i = 0; i < polygonA.length; i++) {
15
- if (polygonContainsPoint(polygonB, polygonA[i])) return true;
6
+ if (polygonContainsPoint(polygonB, polygonA[i])) {
7
+ return true;
8
+ }
16
9
  }
17
10
 
18
11
  for (let i = 0; i < polygonB.length; i++) {
19
- if (polygonContainsPoint(polygonA, polygonB[i])) return true;
12
+ if (polygonContainsPoint(polygonA, polygonB[i])) {
13
+ return true;
14
+ }
20
15
  }
21
16
 
22
- if (lineIntersectsLine(polygonA, polygonB)) return true;
17
+ if (lineIntersectsLine(polygonA, polygonB)) {
18
+ return true;
19
+ }
23
20
 
24
21
  return false;
25
22
  }
26
23
 
27
- function polygonIntersectsBufferedPoint(polygon, point, radius) {
28
- if (polygonContainsPoint(polygon, point)) return true;
29
- if (pointIntersectsBufferedLine(point, polygon, radius)) return true;
24
+ export function polygonIntersectsBufferedPoint(polygon, point, radius) {
25
+ if (polygonContainsPoint(polygon, point)) {
26
+ return true;
27
+ }
28
+ if (pointIntersectsBufferedLine(point, polygon, radius)) {
29
+ return true;
30
+ }
30
31
  return false;
31
32
  }
32
33
 
33
- function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
34
+ export function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
34
35
  if (polygon.length === 1) {
35
36
  return multiPolygonContainsPoint(multiPolygon, polygon[0]);
36
37
  }
@@ -38,62 +39,82 @@ function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
38
39
  for (let m = 0; m < multiPolygon.length; m++) {
39
40
  const ring = multiPolygon[m];
40
41
  for (let n = 0; n < ring.length; n++) {
41
- if (polygonContainsPoint(polygon, ring[n])) return true;
42
+ if (polygonContainsPoint(polygon, ring[n])) {
43
+ return true;
44
+ }
42
45
  }
43
46
  }
44
47
 
45
48
  for (let i = 0; i < polygon.length; i++) {
46
- if (multiPolygonContainsPoint(multiPolygon, polygon[i])) return true;
49
+ if (multiPolygonContainsPoint(multiPolygon, polygon[i])) {
50
+ return true;
51
+ }
47
52
  }
48
53
 
49
54
  for (let k = 0; k < multiPolygon.length; k++) {
50
- if (lineIntersectsLine(polygon, multiPolygon[k])) return true;
55
+ if (lineIntersectsLine(polygon, multiPolygon[k])) {
56
+ return true;
57
+ }
51
58
  }
52
59
 
53
60
  return false;
54
61
  }
55
62
 
56
- function polygonIntersectsBufferedMultiLine(polygon, multiLine, radius) {
63
+ export function polygonIntersectsBufferedMultiLine(polygon, multiLine, radius) {
57
64
  for (let i = 0; i < multiLine.length; i++) {
58
65
  const line = multiLine[i];
59
66
 
60
67
  if (polygon.length >= 3) {
61
68
  for (let k = 0; k < line.length; k++) {
62
- if (polygonContainsPoint(polygon, line[k])) return true;
69
+ if (polygonContainsPoint(polygon, line[k])) {
70
+ return true;
71
+ }
63
72
  }
64
73
  }
65
74
 
66
- if (lineIntersectsBufferedLine(polygon, line, radius)) return true;
75
+ if (lineIntersectsBufferedLine(polygon, line, radius)) {
76
+ return true;
77
+ }
67
78
  }
68
79
  return false;
69
80
  }
70
81
 
71
82
  function lineIntersectsBufferedLine(lineA, lineB, radius) {
72
83
  if (lineA.length > 1) {
73
- if (lineIntersectsLine(lineA, lineB)) return true;
84
+ if (lineIntersectsLine(lineA, lineB)) {
85
+ return true;
86
+ }
74
87
 
75
88
  // Check whether any point in either line is within radius of the other line
76
89
  for (let j = 0; j < lineB.length; j++) {
77
- if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) return true;
90
+ if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) {
91
+ return true;
92
+ }
78
93
  }
79
94
  }
80
95
 
81
96
  for (let k = 0; k < lineA.length; k++) {
82
- if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) return true;
97
+ if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) {
98
+ return true;
99
+ }
83
100
  }
84
101
 
85
102
  return false;
86
103
  }
87
104
 
88
105
  function lineIntersectsLine(lineA, lineB) {
89
- if (lineA.length === 0 || lineB.length === 0) return false;
106
+ if (lineA.length === 0 || lineB.length === 0) {
107
+ return false;
108
+ }
90
109
  for (let i = 0; i < lineA.length - 1; i++) {
91
110
  const a0 = lineA[i];
92
111
  const a1 = lineA[i + 1];
93
112
  for (let j = 0; j < lineB.length - 1; j++) {
94
113
  const b0 = lineB[j];
95
114
  const b1 = lineB[j + 1];
96
- if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) return true;
115
+ if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) {
116
+ return true;
117
+ }
97
118
  }
98
119
  }
99
120
  return false;
@@ -109,25 +130,35 @@ function lineSegmentIntersectsLineSegment(a0, a1, b0, b1) {
109
130
  function pointIntersectsBufferedLine(p, line, radius) {
110
131
  const radiusSquared = radius * radius;
111
132
 
112
- if (line.length === 1) return p.distSqr(line[0]) < radiusSquared;
133
+ if (line.length === 1) {
134
+ return p.distSqr(line[0]) < radiusSquared;
135
+ }
113
136
 
114
137
  for (let i = 1; i < line.length; i++) {
115
138
  // Find line segments that have a distance <= radius^2 to p
116
139
  // In that case, we treat the line as "containing point p".
117
140
  const v = line[i - 1];
118
141
  const w = line[i];
119
- if (distToSegmentSquared(p, v, w) < radiusSquared) return true;
142
+ if (distToSegmentSquared(p, v, w) < radiusSquared) {
143
+ return true;
144
+ }
120
145
  }
121
146
  return false;
122
147
  }
123
148
 
124
149
  // Code from http://stackoverflow.com/a/1501725/331379.
125
- function distToSegmentSquared(p, v, w) {
150
+ export function distToSegmentSquared(p, v, w) {
126
151
  const l2 = v.distSqr(w);
127
- if (l2 === 0) return p.distSqr(v);
152
+ if (l2 === 0) {
153
+ return p.distSqr(v);
154
+ }
128
155
  const t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
129
- if (t < 0) return p.distSqr(v);
130
- if (t > 1) return p.distSqr(w);
156
+ if (t < 0) {
157
+ return p.distSqr(v);
158
+ }
159
+ if (t > 1) {
160
+ return p.distSqr(w);
161
+ }
131
162
  return p.distSqr(w.sub(v)._mult(t)._add(v));
132
163
  }
133
164
 
@@ -163,23 +194,29 @@ function polygonContainsPoint(ring, p) {
163
194
  return c;
164
195
  }
165
196
 
166
- function polygonIntersectsBox(ring, boxX1, boxY1, boxX2, boxY2) {
197
+ export function polygonIntersectsBox(ring, boxX1, boxY1, boxX2, boxY2) {
167
198
  for (const p of ring) {
168
- if (boxX1 <= p.x && boxY1 <= p.y && boxX2 >= p.x && boxY2 >= p.y) return true;
199
+ if (boxX1 <= p.x && boxY1 <= p.y && boxX2 >= p.x && boxY2 >= p.y) {
200
+ return true;
201
+ }
169
202
  }
170
203
 
171
204
  const corners = [new Point(boxX1, boxY1), new Point(boxX1, boxY2), new Point(boxX2, boxY2), new Point(boxX2, boxY1)];
172
205
 
173
206
  if (ring.length > 2) {
174
207
  for (const corner of corners) {
175
- if (polygonContainsPoint(ring, corner)) return true;
208
+ if (polygonContainsPoint(ring, corner)) {
209
+ return true;
210
+ }
176
211
  }
177
212
  }
178
213
 
179
214
  for (let i = 0; i < ring.length - 1; i++) {
180
215
  const p1 = ring[i];
181
216
  const p2 = ring[i + 1];
182
- if (edgeIntersectsBox(p1, p2, corners)) return true;
217
+ if (edgeIntersectsBox(p1, p2, corners)) {
218
+ return true;
219
+ }
183
220
  }
184
221
 
185
222
  return false;
@@ -194,8 +231,9 @@ function edgeIntersectsBox(e1, e2, corners) {
194
231
  (e1.x > br.x && e2.x > br.x) ||
195
232
  (e1.y < tl.y && e2.y < tl.y) ||
196
233
  (e1.y > br.y && e2.y > br.y)
197
- )
234
+ ) {
198
235
  return false;
236
+ }
199
237
 
200
238
  // check if all corners of the box are on the same side of the edge
201
239
  const dir = isCounterClockwise(e1, e2, corners[0]);
@@ -284,4 +284,4 @@ const unicodeBlockLookup = {
284
284
  // 'Supplementary Private Use Area-B': (char) => char >= 0x100000 && char <= 0x10FFFF,
285
285
  };
286
286
 
287
- module.exports = unicodeBlockLookup;
287
+ export default unicodeBlockLookup;
@@ -0,0 +1,25 @@
1
+ export default createKey;
2
+
3
+ function stringify(obj) {
4
+ if (obj == null) {
5
+ return 'null';
6
+ }
7
+ const type = typeof obj;
8
+ if (type === 'number' || type === 'boolean' || type === 'string') {
9
+ return obj;
10
+ }
11
+
12
+ if (Array.isArray(obj)) {
13
+ return '[' + obj.map(val => stringify(val)).join(',') + ']';
14
+ }
15
+
16
+ const keys = Object.keys(obj).sort();
17
+ return '{' + keys.map(key => `${key}:${stringify(obj[key])}`).join(',') + '}';
18
+ }
19
+
20
+ /**
21
+ * Create a unique key for an based on its properties.
22
+ */
23
+ function createKey(properties, object) {
24
+ return properties.map(k => stringify(object[k])).join('/');
25
+ }
@@ -1,4 +1,4 @@
1
- module.exports = image;
1
+ export default image;
2
2
 
3
3
  function image(data) {
4
4
  if (!data) {
@@ -1,34 +1,3 @@
1
- /*
2
- * Polyfill for Object.values. Not fully spec compliant, but we don't
3
- * need it to be.
4
- *
5
- * @private
6
- */
7
- function values(obj) {
8
- const result = [];
9
- for (const k in obj) {
10
- result.push(obj[k]);
11
- }
12
- return result;
13
- }
14
-
15
- /*
16
- * Compute the difference between the keys in one object and the keys
17
- * in another object.
18
- *
19
- * @returns keys difference
20
- * @private
21
- */
22
- function keysDifference(obj, other) {
23
- const difference = [];
24
- for (const i in obj) {
25
- if (!(i in other)) {
26
- difference.push(i);
27
- }
28
- }
29
- return difference;
30
- }
31
-
32
1
  /**
33
2
  * Given an object and a number of properties as strings, return version
34
3
  * of that object with only those properties.
@@ -43,15 +12,9 @@ function keysDifference(obj, other) {
43
12
  * // justName = { name: 'Charlie' }
44
13
  * @private
45
14
  */
46
- function pick(src, properties) {
47
- const result = {};
48
- for (let i = 0; i < properties.length; i++) {
49
- const k = properties[i];
50
- if (k in src) {
51
- result[k] = src[k];
52
- }
53
- }
54
- return result;
15
+ export function pick(src, properties) {
16
+ const entries = properties.filter(p => p in src).map(p => [p, src[p]]);
17
+ return Object.fromEntries(entries);
55
18
  }
56
19
 
57
20
  /**
@@ -75,7 +38,7 @@ function pick(src, properties) {
75
38
  * setTimeout(myClass.ontimer, 100);
76
39
  * @private
77
40
  */
78
- function bindAll(fns, context) {
41
+ export function bindAll(fns, context) {
79
42
  fns.forEach(fn => {
80
43
  if (!context[fn]) {
81
44
  return;
@@ -90,12 +53,10 @@ function bindAll(fns, context) {
90
53
  *
91
54
  * @private
92
55
  */
93
- function mapObject(input, iterator, context) {
94
- const output = {};
95
- for (const key in input) {
96
- output[key] = iterator.call(context || this, input[key], key, input);
97
- }
98
- return output;
56
+ export function mapObject(input, iterator, context) {
57
+ context ??= this;
58
+ const entries = Object.entries(input).map(([k, v]) => [k, iterator.call(context, v, k, input)]);
59
+ return Object.fromEntries(entries);
99
60
  }
100
61
 
101
62
  /**
@@ -103,14 +64,10 @@ function mapObject(input, iterator, context) {
103
64
  *
104
65
  * @private
105
66
  */
106
- function filterObject(input, iterator, context) {
107
- const output = {};
108
- for (const key in input) {
109
- if (iterator.call(context || this, input[key], key, input)) {
110
- output[key] = input[key];
111
- }
112
- }
113
- return output;
67
+ export function filterObject(input, iterator, context) {
68
+ context ??= this;
69
+ const entries = Object.entries(input).filter(([k, v]) => iterator.call(context, v, k, input));
70
+ return Object.fromEntries(entries);
114
71
  }
115
72
 
116
73
  /**
@@ -118,20 +75,30 @@ function filterObject(input, iterator, context) {
118
75
  *
119
76
  * @private
120
77
  */
121
- function deepEqual(a, b) {
78
+ export function deepEqual(a, b) {
122
79
  if (Array.isArray(a)) {
123
- if (!Array.isArray(b) || a.length !== b.length) return false;
80
+ if (!Array.isArray(b) || a.length !== b.length) {
81
+ return false;
82
+ }
124
83
  for (let i = 0; i < a.length; i++) {
125
- if (!deepEqual(a[i], b[i])) return false;
84
+ if (!deepEqual(a[i], b[i])) {
85
+ return false;
86
+ }
126
87
  }
127
88
  return true;
128
89
  }
129
90
  if (typeof a === 'object' && a !== null && b !== null) {
130
- if (!(typeof b === 'object')) return false;
91
+ if (!(typeof b === 'object')) {
92
+ return false;
93
+ }
131
94
  const keys = Object.keys(a);
132
- if (keys.length !== Object.keys(b).length) return false;
95
+ if (keys.length !== Object.keys(b).length) {
96
+ return false;
97
+ }
133
98
  for (const key in a) {
134
- if (!deepEqual(a[key], b[key])) return false;
99
+ if (!deepEqual(a[key], b[key])) {
100
+ return false;
101
+ }
135
102
  }
136
103
  return true;
137
104
  }
@@ -143,7 +110,7 @@ function deepEqual(a, b) {
143
110
  *
144
111
  * @private
145
112
  */
146
- function clone(input) {
113
+ export function clone(input) {
147
114
  if (Array.isArray(input)) {
148
115
  return input.map(clone);
149
116
  }
@@ -158,21 +125,11 @@ function clone(input) {
158
125
  *
159
126
  * @private
160
127
  */
161
- function arraysIntersect(a, b) {
128
+ export function arraysIntersect(a, b) {
162
129
  for (let l = 0; l < a.length; l++) {
163
- if (b.indexOf(a[l]) >= 0) return true;
130
+ if (b.indexOf(a[l]) >= 0) {
131
+ return true;
132
+ }
164
133
  }
165
134
  return false;
166
135
  }
167
-
168
- module.exports = {
169
- values,
170
- keysDifference,
171
- pick,
172
- bindAll,
173
- mapObject,
174
- filterObject,
175
- deepEqual,
176
- clone,
177
- arraysIntersect
178
- };