@indiscale/linkahead-webui-ext-map 0.5.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 (76) hide show
  1. package/.eslintrc.json +45 -0
  2. package/.gitlab-ci.yml +44 -0
  3. package/CHANGELOG.md +78 -0
  4. package/README.md +97 -0
  5. package/RELEASE_GUIDELINES.md +45 -0
  6. package/__mocks__/fileMock.js +3 -0
  7. package/__mocks__/styleMock.js +1 -0
  8. package/babel.config.js +22 -0
  9. package/cypress/e2e/standalone-map.cy.js +55 -0
  10. package/cypress/support/commands.js +25 -0
  11. package/cypress/support/e2e.js +17 -0
  12. package/cypress.config.js +10 -0
  13. package/dist/2b3e1faf89f94a483539.png +0 -0
  14. package/dist/416d91365b44e4b4f477.png +0 -0
  15. package/dist/8f2c4d11474275fbc161.png +0 -0
  16. package/dist/index.html +1 -0
  17. package/dist/linkahead-webui-ext-map.js +3 -0
  18. package/dist/linkahead-webui-ext-map.js.LICENSE.txt +45 -0
  19. package/dist/linkahead-webui-ext-map.js.map +1 -0
  20. package/iframe/index.html +6 -0
  21. package/indiscale-linkahead-webui-ext-map-0.4.1.tgz +0 -0
  22. package/jest.config.js +23 -0
  23. package/jest.setup.js +2 -0
  24. package/package.json +105 -0
  25. package/public/favicon.ico +0 -0
  26. package/public/index.html +11 -0
  27. package/public/logo192.png +0 -0
  28. package/public/logo512.png +0 -0
  29. package/public/manifest.json +25 -0
  30. package/public/map_tile_caosdb_logo.png +0 -0
  31. package/public/mock.js +41 -0
  32. package/public/robots.txt +3 -0
  33. package/select_query.json +3 -0
  34. package/src/AllMapEntities.tsx +294 -0
  35. package/src/CurrentPageEntities.js +318 -0
  36. package/src/Map.helpers.css +8 -0
  37. package/src/Map.helpers.js +536 -0
  38. package/src/Map.js +288 -0
  39. package/src/Map.test.js +252 -0
  40. package/src/MapConfig.js +75 -0
  41. package/src/__snapshots__/Map.test.js.snap +1725 -0
  42. package/src/components/Coordinates.js +24 -0
  43. package/src/components/ErrorComponent.tsx +2 -0
  44. package/src/components/Graticule.js +27 -0
  45. package/src/components/Loader.module.css +17 -0
  46. package/src/components/Loader.tsx +36 -0
  47. package/src/components/PathDropDown.js +108 -0
  48. package/src/components/SearchControl.js +502 -0
  49. package/src/components/ToggleMapButton.js +194 -0
  50. package/src/components/ViewChangeControl.js +104 -0
  51. package/src/constants/index.js +1 -0
  52. package/src/context/ConfigProvider.test.js +232 -0
  53. package/src/context/ConfigProvider.tsx +189 -0
  54. package/src/context/LoadingProvider.test.js +124 -0
  55. package/src/context/LoadingProvider.tsx +117 -0
  56. package/src/context/PathIdProvider.js +102 -0
  57. package/src/contrib/latlnggraticule/LICENSE +20 -0
  58. package/src/contrib/latlnggraticule/README.md +68 -0
  59. package/src/contrib/latlnggraticule/leaflet.latlng-graticule.js +528 -0
  60. package/src/contrib/simplegraticule/L.Graticule.js +138 -0
  61. package/src/default_config.json +57 -0
  62. package/src/global.d.ts +8 -0
  63. package/src/index.js +6 -0
  64. package/src/index.scss +133 -0
  65. package/src/logging.js +7 -0
  66. package/src/renderHtmlTemplate.test.js +60 -0
  67. package/src/select-search.min.svg +1 -0
  68. package/src/select-search.svg +46 -0
  69. package/src/setupTests.js +5 -0
  70. package/src/utils/GenerateQueryString.js +200 -0
  71. package/src/utils/GenerateQueryString.test.js +304 -0
  72. package/src/utils/index.ts +3 -0
  73. package/standalone.config.js +5 -0
  74. package/static/map_tile_caosdb_logo.png +0 -0
  75. package/tsconfig.json +25 -0
  76. package/webpack.config.js +193 -0
@@ -0,0 +1,528 @@
1
+ /* eslint-disable indent,semi,no-redeclare,no-unused-vars, no-import-assign */
2
+ import L from "leaflet"; // importing as * causes issues probably because it is a read only obj
3
+
4
+ /**
5
+ * Create a Canvas as ImageOverlay to draw the Lat/Lon Graticule,
6
+ * and show the axis tick label on the edge of the map.
7
+ * Author: lanwei@cloudybay.com.tw
8
+ */
9
+ (function (window, document) {
10
+ L.LatLngGraticule = L.Layer.extend({
11
+ includes: L.Evented.prototype || L.Mixin.Events,
12
+ options: {
13
+ showLabel: true,
14
+ opacity: 1,
15
+ weight: 0.8,
16
+ color: "#aaa",
17
+ font: "12px Verdana",
18
+ dashArray: [0, 0],
19
+ lngLineCurved: 0,
20
+ latLineCurved: 0,
21
+ zoomInterval: [
22
+ { start: 2, end: 2, interval: 40 },
23
+ { start: 3, end: 3, interval: 20 },
24
+ { start: 4, end: 4, interval: 10 },
25
+ { start: 5, end: 7, interval: 5 },
26
+ { start: 8, end: 20, interval: 1 },
27
+ ],
28
+ sides: ["N", "S", "E", "W"],
29
+ },
30
+
31
+ initialize: function (options) {
32
+ L.setOptions(this, options);
33
+
34
+ var defaultFontName = "Verdana";
35
+ var _ff = this.options.font.split(" ");
36
+ if (_ff.length < 2) {
37
+ this.options.font += " " + defaultFontName;
38
+ }
39
+
40
+ if (!this.options.fontColor) {
41
+ this.options.fontColor = this.options.color;
42
+ }
43
+
44
+ if (this.options.zoomInterval) {
45
+ if (this.options.zoomInterval.latitude) {
46
+ this.options.latInterval = this.options.zoomInterval.latitude;
47
+ if (!this.options.zoomInterval.longitude) {
48
+ this.options.lngInterval = this.options.zoomInterval.latitude;
49
+ }
50
+ }
51
+ if (this.options.zoomInterval.longitude) {
52
+ this.options.lngInterval = this.options.zoomInterval.longitude;
53
+ if (!this.options.zoomInterval.latitude) {
54
+ this.options.latInterval = this.options.zoomInterval.longitude;
55
+ }
56
+ }
57
+ if (!this.options.latInterval) {
58
+ this.options.latInterval = this.options.zoomInterval;
59
+ }
60
+ if (!this.options.lngInterval) {
61
+ this.options.lngInterval = this.options.zoomInterval;
62
+ }
63
+ }
64
+ },
65
+
66
+ onAdd: function (map) {
67
+ this._map = map;
68
+
69
+ if (!this._canvas) {
70
+ this._initCanvas();
71
+ }
72
+
73
+ map._panes.overlayPane.appendChild(this._canvas);
74
+
75
+ map.on("viewreset", this._reset, this);
76
+ map.on("move", this._reset, this);
77
+ map.on("moveend", this._reset, this);
78
+
79
+ if (map.options.zoomAnimation && L.Browser.any3d) {
80
+ map.on("zoomanim", this._animateZoom, this);
81
+ }
82
+
83
+ this._reset();
84
+ },
85
+
86
+ onRemove: function (map) {
87
+ L.DomUtil.remove(this._canvas);
88
+
89
+ map.off("viewreset", this._reset, this);
90
+ map.off("move", this._reset, this);
91
+ map.off("moveend", this._reset, this);
92
+
93
+ if (map.options.zoomAnimation) {
94
+ map.off("zoomanim", this._animateZoom, this);
95
+ }
96
+ },
97
+
98
+ addTo: function (map) {
99
+ map.addLayer(this);
100
+ return this;
101
+ },
102
+
103
+ setOpacity: function (opacity) {
104
+ this.options.opacity = opacity;
105
+ this._updateOpacity();
106
+ return this;
107
+ },
108
+
109
+ bringToFront: function () {
110
+ //if (this._canvas) {
111
+ //this._map._panes.overlayPane.appendChild(this._canvas);
112
+ //}
113
+ return this;
114
+ },
115
+
116
+ bringToBack: function () {
117
+ //var pane = this._map._panes.overlayPane;
118
+ //if (this._canvas) {
119
+ //pane.insertBefore(this._canvas, pane.firstChild);
120
+ //}
121
+ return this;
122
+ },
123
+
124
+ getAttribution: function () {
125
+ return this.options.attribution;
126
+ },
127
+
128
+ _initCanvas: function () {
129
+ this._canvas = L.DomUtil.create("canvas", "");
130
+
131
+ if (this._map.options.zoomAnimation && L.Browser.any3d) {
132
+ L.DomUtil.addClass(this._canvas, "leaflet-zoom-animated");
133
+ } else {
134
+ L.DomUtil.addClass(this._canvas, "leaflet-zoom-hide");
135
+ }
136
+
137
+ this._updateOpacity();
138
+
139
+ L.extend(this._canvas, {
140
+ onselectstart: L.Util.falseFn,
141
+ onmousemove: L.Util.falseFn,
142
+ onload: L.bind(this._onCanvasLoad, this),
143
+ });
144
+ },
145
+
146
+ _animateZoom: function (e) {
147
+ var map = this._map,
148
+ canvas = this._canvas,
149
+ scale = map.getZoomScale(e.zoom),
150
+ nw = map.containerPointToLatLng([0, 0]),
151
+ se = map.containerPointToLatLng([canvas.width, canvas.height]),
152
+ topLeft = map._latLngToNewLayerPoint(nw, e.zoom, e.center),
153
+ size = map
154
+ ._latLngToNewLayerPoint(se, e.zoom, e.center)
155
+ ._subtract(topLeft),
156
+ origin = topLeft._add(size._multiplyBy((1 / 2) * (1 - 1 / scale)));
157
+
158
+ L.DomUtil.setTransform(canvas, origin, scale);
159
+ },
160
+
161
+ _reset: function () {
162
+ var canvas = this._canvas,
163
+ size = this._map.getSize(),
164
+ lt = this._map.containerPointToLayerPoint([0, 0]);
165
+
166
+ L.DomUtil.setPosition(canvas, lt);
167
+
168
+ canvas.width = size.x;
169
+ canvas.height = size.y;
170
+ canvas.style.width = size.x + "px";
171
+ canvas.style.height = size.y + "px";
172
+
173
+ this.__calcInterval();
174
+
175
+ this.__draw(true);
176
+ },
177
+
178
+ _onCanvasLoad: function () {
179
+ this.fire("load");
180
+ },
181
+
182
+ _updateOpacity: function () {
183
+ L.DomUtil.setOpacity(this._canvas, this.options.opacity);
184
+ },
185
+
186
+ __format_lat: function (lat) {
187
+ if (this.options.latFormatTickLabel) {
188
+ return this.options.latFormatTickLabel(lat);
189
+ }
190
+
191
+ // todo: format type of float
192
+ if (lat < 0) {
193
+ return "" + lat * -1 + this.options.sides[1];
194
+ } else if (lat > 0) {
195
+ return "" + lat + this.options.sides[0];
196
+ }
197
+ return "" + lat;
198
+ },
199
+
200
+ __format_lng: function (lng) {
201
+ if (this.options.lngFormatTickLabel) {
202
+ return this.options.lngFormatTickLabel(lng);
203
+ }
204
+
205
+ // todo: format type of float
206
+ if (lng > 180) {
207
+ return "" + (360 - lng) + this.options.sides[3];
208
+ } else if (lng > 0 && lng < 180) {
209
+ return "" + lng + this.options.sides[2];
210
+ } else if (lng < 0 && lng > -180) {
211
+ return "" + lng * -1 + this.options.sides[3];
212
+ } else if (lng === -180) {
213
+ return "" + lng * -1;
214
+ } else if (lng < -180) {
215
+ return "" + (360 + lng) + this.options.sides[3];
216
+ }
217
+ return "" + lng;
218
+ },
219
+
220
+ __calcInterval: function () {
221
+ var zoom = this._map.getZoom();
222
+ if (this._currZoom !== zoom) {
223
+ this._currLngInterval = 0;
224
+ this._currLatInterval = 0;
225
+ this._currZoom = zoom;
226
+ }
227
+
228
+ if (!this._currLngInterval) {
229
+ try {
230
+ for (var idx in this.options.lngInterval) {
231
+ var dict = this.options.lngInterval[idx];
232
+ if (dict.start <= zoom) {
233
+ if (dict.end && dict.end >= zoom) {
234
+ this._currLngInterval = dict.interval;
235
+ break;
236
+ }
237
+ }
238
+ }
239
+ } catch (e) {
240
+ this._currLngInterval = 0;
241
+ }
242
+ }
243
+
244
+ if (!this._currLatInterval) {
245
+ try {
246
+ for (var idx in this.options.latInterval) {
247
+ var dict = this.options.latInterval[idx];
248
+ if (dict.start <= zoom) {
249
+ if (dict.end && dict.end >= zoom) {
250
+ this._currLatInterval = dict.interval;
251
+ break;
252
+ }
253
+ }
254
+ }
255
+ } catch (e) {
256
+ this._currLatInterval = 0;
257
+ }
258
+ }
259
+ },
260
+
261
+ __draw: function (label) {
262
+ function _parse_px_to_int(txt) {
263
+ if (txt.length > 2) {
264
+ if (txt.charAt(txt.length - 2) === "p") {
265
+ txt = txt.substr(0, txt.length - 2);
266
+ }
267
+ }
268
+ try {
269
+ return parseInt(txt, 10);
270
+ // eslint-disable-next-line no-empty
271
+ } catch (e) {}
272
+ return 0;
273
+ }
274
+
275
+ var canvas = this._canvas,
276
+ map = this._map,
277
+ curvedLon = this.options.lngLineCurved,
278
+ curvedLat = this.options.latLineCurved;
279
+
280
+ if (L.Browser.canvas && map) {
281
+ if (!this._currLngInterval || !this._currLatInterval) {
282
+ this.__calcInterval();
283
+ }
284
+
285
+ var latInterval = this._currLatInterval,
286
+ lngInterval = this._currLngInterval;
287
+
288
+ var ctx = canvas.getContext("2d");
289
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
290
+ ctx.lineWidth = this.options.weight;
291
+ ctx.strokeStyle = this.options.color;
292
+ ctx.fillStyle = this.options.fontColor;
293
+ ctx.setLineDash(this.options.dashArray);
294
+
295
+ if (this.options.font) {
296
+ ctx.font = this.options.font;
297
+ }
298
+ var txtWidth = ctx.measureText("0").width;
299
+ var txtHeight = 12;
300
+ try {
301
+ var _font_size = ctx.font.trim().split(" ")[0];
302
+ txtHeight = _parse_px_to_int(_font_size);
303
+ // eslint-disable-next-line no-empty
304
+ } catch (e) {}
305
+
306
+ var ww = canvas.width,
307
+ hh = canvas.height;
308
+
309
+ var lt = map.containerPointToLatLng(L.point(0, 0));
310
+ var rt = map.containerPointToLatLng(L.point(ww, 0));
311
+ var rb = map.containerPointToLatLng(L.point(ww, hh));
312
+
313
+ var _lat_b = rb.lat,
314
+ _lat_t = lt.lat;
315
+ var _lon_l = lt.lng,
316
+ _lon_r = rt.lng;
317
+
318
+ var _point_per_lat = (_lat_t - _lat_b) / (hh * 0.2);
319
+ if (isNaN(_point_per_lat)) {
320
+ return;
321
+ }
322
+
323
+ if (_point_per_lat < 1) {
324
+ _point_per_lat = 1;
325
+ }
326
+ if (_lat_b < -90) {
327
+ _lat_b = -90;
328
+ } else {
329
+ _lat_b = parseInt(_lat_b - _point_per_lat, 10);
330
+ }
331
+
332
+ if (_lat_t > 90) {
333
+ _lat_t = 90;
334
+ } else {
335
+ _lat_t = parseInt(_lat_t + _point_per_lat, 10);
336
+ }
337
+
338
+ var _point_per_lon = (_lon_r - _lon_l) / (ww * 0.2);
339
+ if (_point_per_lon < 1) {
340
+ _point_per_lon = 1;
341
+ }
342
+ if (_lon_l > 0 && _lon_r < 0) {
343
+ _lon_r += 360;
344
+ }
345
+ _lon_r = parseInt(_lon_r + _point_per_lon, 10);
346
+ _lon_l = parseInt(_lon_l - _point_per_lon, 10);
347
+
348
+ var ll,
349
+ latstr,
350
+ lngstr,
351
+ _lon_delta = 0.5;
352
+ // eslint-disable-next-line no-inner-declarations
353
+ function __draw_lat_line(self, lat_tick) {
354
+ ll = self._latLngToCanvasPoint(L.latLng(lat_tick, _lon_l));
355
+ latstr = self.__format_lat(lat_tick);
356
+ txtWidth = ctx.measureText(latstr).width;
357
+ var spacer = self.options.showLabel && label ? txtWidth + 10 : 0;
358
+
359
+ if (curvedLat) {
360
+ if (typeof curvedLat == "number") {
361
+ _lon_delta = curvedLat;
362
+ }
363
+
364
+ var __lon_left = _lon_l,
365
+ __lon_right = _lon_r;
366
+ if (ll.x > 0) {
367
+ var __lon_left = map.containerPointToLatLng(L.point(0, ll.y));
368
+ __lon_left = __lon_left.lng - _point_per_lon;
369
+ ll.x = 0;
370
+ }
371
+ var rr = self._latLngToCanvasPoint(L.latLng(lat_tick, __lon_right));
372
+ if (rr.x < ww) {
373
+ __lon_right = map.containerPointToLatLng(L.point(ww, rr.y));
374
+ __lon_right = __lon_right.lng + _point_per_lon;
375
+ if (__lon_left > 0 && __lon_right < 0) {
376
+ __lon_right += 360;
377
+ }
378
+ }
379
+
380
+ ctx.beginPath();
381
+ ctx.moveTo(ll.x + spacer, ll.y);
382
+ var _prev_p = null;
383
+ for (var j = __lon_left; j <= __lon_right; j += _lon_delta) {
384
+ rr = self._latLngToCanvasPoint(L.latLng(lat_tick, j));
385
+ ctx.lineTo(rr.x - spacer, rr.y);
386
+
387
+ if (self.options.showLabel && label && _prev_p != null) {
388
+ if (_prev_p.x < 0 && rr.x >= 0) {
389
+ var _s = (rr.x - 0) / (rr.x - _prev_p.x);
390
+ var _y = rr.y - (rr.y - _prev_p.y) * _s;
391
+ ctx.fillText(latstr, 0, _y + txtHeight / 2);
392
+ } else if (_prev_p.x <= ww - txtWidth && rr.x > ww - txtWidth) {
393
+ var _s = (rr.x - ww) / (rr.x - _prev_p.x);
394
+ var _y = rr.y - (rr.y - _prev_p.y) * _s;
395
+ ctx.fillText(latstr, ww - txtWidth, _y + txtHeight / 2 - 2);
396
+ }
397
+ }
398
+
399
+ _prev_p = { x: rr.x, y: rr.y, lon: j, lat: i };
400
+ }
401
+ ctx.stroke();
402
+ } else {
403
+ var __lon_right = _lon_r;
404
+ var rr = self._latLngToCanvasPoint(L.latLng(lat_tick, __lon_right));
405
+ if (curvedLon) {
406
+ __lon_right = map.containerPointToLatLng(L.point(0, rr.y));
407
+ __lon_right = __lon_right.lng;
408
+ rr = self._latLngToCanvasPoint(L.latLng(lat_tick, __lon_right));
409
+
410
+ var __lon_left = map.containerPointToLatLng(L.point(ww, rr.y));
411
+ __lon_left = __lon_left.lng;
412
+ ll = self._latLngToCanvasPoint(L.latLng(lat_tick, __lon_left));
413
+ }
414
+
415
+ ctx.beginPath();
416
+ ctx.moveTo(1 + spacer, ll.y);
417
+ ctx.lineTo(rr.x - 1 - spacer, rr.y);
418
+ ctx.stroke();
419
+ if (self.options.showLabel && label) {
420
+ var _yy = ll.y + txtHeight / 2 - 2;
421
+ ctx.fillText(latstr, 0, _yy);
422
+ ctx.fillText(latstr, ww - txtWidth, _yy);
423
+ }
424
+ }
425
+ }
426
+
427
+ if (latInterval > 0) {
428
+ for (var i = latInterval; i <= _lat_t; i += latInterval) {
429
+ if (i >= _lat_b) {
430
+ __draw_lat_line(this, i);
431
+ }
432
+ }
433
+ for (var i = 0; i >= _lat_b; i -= latInterval) {
434
+ if (i <= _lat_t) {
435
+ __draw_lat_line(this, i);
436
+ }
437
+ }
438
+ }
439
+
440
+ // eslint-disable-next-line no-inner-declarations
441
+ function __draw_lon_line(self, lon_tick) {
442
+ lngstr = self.__format_lng(lon_tick);
443
+ txtWidth = ctx.measureText(lngstr).width;
444
+ var bb = self._latLngToCanvasPoint(L.latLng(_lat_b, lon_tick));
445
+ var spacer = self.options.showLabel && label ? txtHeight + 5 : 0;
446
+
447
+ if (curvedLon) {
448
+ var _lat_delta;
449
+ if (typeof curvedLon == "number") {
450
+ _lat_delta = curvedLon;
451
+ }
452
+
453
+ ctx.beginPath();
454
+ ctx.moveTo(bb.x, 5 + spacer);
455
+ var _prev_p = null;
456
+ for (var j = _lat_b; j < _lat_t; j += _lat_delta) {
457
+ var tt = self._latLngToCanvasPoint(L.latLng(j, lon_tick));
458
+ ctx.lineTo(tt.x, tt.y - spacer);
459
+
460
+ if (self.options.showLabel && label && _prev_p != null) {
461
+ if (_prev_p.y > 8 && tt.y <= 8) {
462
+ ctx.fillText(lngstr, tt.x - txtWidth / 2, txtHeight + 5);
463
+ } else if (_prev_p.y >= hh && tt.y < hh) {
464
+ ctx.fillText(lngstr, tt.x - txtWidth / 2, hh - 2);
465
+ }
466
+ }
467
+
468
+ _prev_p = { x: tt.x, y: tt.y, lon: lon_tick, lat: j };
469
+ }
470
+ ctx.stroke();
471
+ } else {
472
+ var __lat_top = _lat_t;
473
+ var tt = self._latLngToCanvasPoint(L.latLng(__lat_top, lon_tick));
474
+ if (curvedLat) {
475
+ __lat_top = map.containerPointToLatLng(L.point(tt.x, 0));
476
+ __lat_top = __lat_top.lat;
477
+ if (__lat_top > 90) {
478
+ __lat_top = 90;
479
+ }
480
+ tt = self._latLngToCanvasPoint(L.latLng(__lat_top, lon_tick));
481
+
482
+ var __lat_bottom = map.containerPointToLatLng(L.point(bb.x, hh));
483
+ __lat_bottom = __lat_bottom.lat;
484
+ if (__lat_bottom < -90) {
485
+ __lat_bottom = -90;
486
+ }
487
+ bb = self._latLngToCanvasPoint(L.latLng(__lat_bottom, lon_tick));
488
+ }
489
+
490
+ ctx.beginPath();
491
+ ctx.moveTo(tt.x, 5 + spacer);
492
+ ctx.lineTo(bb.x, hh - 1 - spacer);
493
+ ctx.stroke();
494
+
495
+ if (self.options.showLabel && label) {
496
+ ctx.fillText(lngstr, tt.x - txtWidth / 2, txtHeight + 5);
497
+ ctx.fillText(lngstr, bb.x - txtWidth / 2, hh - 3);
498
+ }
499
+ }
500
+ }
501
+
502
+ if (lngInterval > 0) {
503
+ for (var i = lngInterval; i <= _lon_r; i += lngInterval) {
504
+ if (i >= _lon_l) {
505
+ __draw_lon_line(this, i);
506
+ }
507
+ }
508
+ for (var i = 0; i >= _lon_l; i -= lngInterval) {
509
+ if (i <= _lon_r) {
510
+ __draw_lon_line(this, i);
511
+ }
512
+ }
513
+ }
514
+ }
515
+ },
516
+
517
+ _latLngToCanvasPoint: function (latlng) {
518
+ var map = this._map;
519
+ var projectedPoint = map.project(L.latLng(latlng));
520
+ projectedPoint._subtract(map.getPixelOrigin());
521
+ return L.point(projectedPoint).add(map._getMapPanePos());
522
+ },
523
+ });
524
+
525
+ L.latlngGraticule = function (options) {
526
+ return new L.LatLngGraticule(options);
527
+ };
528
+ })(this, document);
@@ -0,0 +1,138 @@
1
+ // MIT License
2
+ //
3
+ // Copyright © 2013 turban, tmcw
4
+ //
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the “Software”), to
7
+ // deal in the Software without restriction, including without limitation the
8
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9
+ // sell copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+ //
12
+ // The above copyright notice and this permission notice shall be included in
13
+ // all copies or substantial portions of the Software.
14
+ //
15
+ // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
+ // IN THE SOFTWARE.
22
+
23
+ import * as L from "leaflet";
24
+
25
+ /*
26
+ Graticule plugin for Leaflet powered maps.
27
+ */
28
+ // eslint-disable-next-line no-import-assign
29
+ L.Graticule = L.GeoJSON.extend({
30
+ options: {
31
+ style: {
32
+ color: "#333",
33
+ weight: 1,
34
+ },
35
+ interval: 20,
36
+ },
37
+
38
+ initialize: function (options) {
39
+ L.Util.setOptions(this, options);
40
+ this._layers = {};
41
+
42
+ if (this.options.sphere) {
43
+ this.addData(this._getFrame());
44
+ } else {
45
+ this.addData(this._getGraticule());
46
+ }
47
+ },
48
+
49
+ _getFrame: function () {
50
+ return {
51
+ type: "Polygon",
52
+ coordinates: [
53
+ this._getMeridian(-180).concat(this._getMeridian(180).reverse()),
54
+ ],
55
+ };
56
+ },
57
+
58
+ _getGraticule: function () {
59
+ var features = [],
60
+ interval = this.options.interval;
61
+
62
+ // Meridians
63
+ for (var lng = 0; lng <= 180; lng = lng + interval) {
64
+ features.push(
65
+ this._getFeature(this._getMeridian(lng), {
66
+ name: lng ? lng.toString() + "° E" : "Prime meridian",
67
+ })
68
+ );
69
+ if (lng !== 0) {
70
+ features.push(
71
+ this._getFeature(this._getMeridian(-lng), {
72
+ name: lng.toString() + "° W",
73
+ })
74
+ );
75
+ }
76
+ }
77
+
78
+ // Parallels
79
+ for (var lat = 0; lat <= 90; lat = lat + interval) {
80
+ features.push(
81
+ this._getFeature(this._getParallel(lat), {
82
+ name: lat ? lat.toString() + "° N" : "Equator",
83
+ })
84
+ );
85
+ if (lat !== 0) {
86
+ features.push(
87
+ this._getFeature(this._getParallel(-lat), {
88
+ name: lat.toString() + "° S",
89
+ })
90
+ );
91
+ }
92
+ }
93
+
94
+ return {
95
+ type: "FeatureCollection",
96
+ features: features,
97
+ };
98
+ },
99
+
100
+ _getMeridian: function (lng) {
101
+ lng = this._lngFix(lng);
102
+ var coords = [];
103
+ for (var lat = -90; lat <= 90; lat++) {
104
+ coords.push([lng, lat]);
105
+ }
106
+ return coords;
107
+ },
108
+
109
+ _getParallel: function (lat) {
110
+ var coords = [];
111
+ for (var lng = -180; lng <= 180; lng++) {
112
+ coords.push([this._lngFix(lng), lat]);
113
+ }
114
+ return coords;
115
+ },
116
+
117
+ _getFeature: function (coords, prop) {
118
+ return {
119
+ type: "Feature",
120
+ geometry: {
121
+ type: "LineString",
122
+ coordinates: coords,
123
+ },
124
+ properties: prop,
125
+ };
126
+ },
127
+
128
+ _lngFix: function (lng) {
129
+ if (lng >= 180) return 179.999999;
130
+ if (lng <= -180) return -179.999999;
131
+ return lng;
132
+ },
133
+ });
134
+
135
+ // eslint-disable-next-line no-import-assign
136
+ L.graticule = function (options) {
137
+ return new L.Graticule(options);
138
+ };