@abi-software/flatmap-viewer 2.7.1 → 2.7.3-a.1

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 (122) hide show
  1. package/README.rst +1 -1
  2. package/dist/flatmapviewer.es.js +80577 -0
  3. package/dist/flatmapviewer.umd.js +1687 -0
  4. package/dist/lib/index.d.ts +4 -0
  5. package/dist/style.css +1 -0
  6. package/package.json +10 -8
  7. package/lib/index.ts +0 -10
  8. package/src/contextmenu.js +0 -97
  9. package/src/controls/annotation.js +0 -302
  10. package/src/controls/controls.js +0 -645
  11. package/src/controls/flightpaths.js +0 -95
  12. package/src/controls/info.js +0 -291
  13. package/src/controls/minimap.js +0 -442
  14. package/src/controls/paths.js +0 -143
  15. package/src/controls/search.js +0 -113
  16. package/src/controls/systems.js +0 -75
  17. package/src/controls/taxons.js +0 -73
  18. package/src/flatmap-viewer.js +0 -1789
  19. package/src/images.js +0 -66
  20. package/src/interactions.js +0 -1569
  21. package/src/layers/cluster.js +0 -178
  22. package/src/layers/filter.js +0 -310
  23. package/src/layers/flightpaths.js +0 -383
  24. package/src/layers/index.js +0 -478
  25. package/src/layers/styling.js +0 -1077
  26. package/src/main.js +0 -272
  27. package/src/mapserver.js +0 -64
  28. package/src/mathjax.js +0 -100
  29. package/src/pathways.js +0 -427
  30. package/src/search.js +0 -137
  31. package/src/systems.js +0 -146
  32. package/src/utils.js +0 -152
  33. package/static/css/flatmap-viewer.css +0 -238
  34. package/static/icons/favicon.ico +0 -0
  35. package/static/images/active.png +0 -0
  36. package/static/images/inactive.png +0 -0
  37. package/static/images/reset-map-active.png +0 -0
  38. package/static/images/reset-map-button.png +0 -0
  39. package/static/images/rounded-background.png +0 -0
  40. package/static/images/zoom-in-active.png +0 -0
  41. package/static/images/zoom-in-button.png +0 -0
  42. package/static/images/zoom-out-active.png +0 -0
  43. package/static/images/zoom-out-button.png +0 -0
  44. package/thirdParty/maplibre-gl-svg/CHANGELOG.md +0 -13
  45. package/thirdParty/maplibre-gl-svg/LICENSE +0 -21
  46. package/thirdParty/maplibre-gl-svg/LICENSE.md +0 -21
  47. package/thirdParty/maplibre-gl-svg/README.md +0 -24
  48. package/thirdParty/maplibre-gl-svg/assets/Add custom SVG template to template manager.jpg +0 -0
  49. package/thirdParty/maplibre-gl-svg/assets/All built-in SVG templates as HTML markers.jpg +0 -0
  50. package/thirdParty/maplibre-gl-svg/assets/All built-in SVG templates as symbols.jpg +0 -0
  51. package/thirdParty/maplibre-gl-svg/assets/Fill polygon with built-in SVG template.jpg +0 -0
  52. package/thirdParty/maplibre-gl-svg/assets/HTML Marker with Custom SVG Template.jpg +0 -0
  53. package/thirdParty/maplibre-gl-svg/assets/HTML Marker with built-in SVG template.jpg +0 -0
  54. package/thirdParty/maplibre-gl-svg/assets/Line layer with built-in SVG template.jpg +0 -0
  55. package/thirdParty/maplibre-gl-svg/assets/Load SVG from URL.jpg +0 -0
  56. package/thirdParty/maplibre-gl-svg/assets/SVG template options.jpg +0 -0
  57. package/thirdParty/maplibre-gl-svg/assets/Smiley_face_changed.svg +0 -37
  58. package/thirdParty/maplibre-gl-svg/assets/Symbol layer with built-in SVG template.jpg +0 -0
  59. package/thirdParty/maplibre-gl-svg/assets/image-templates/arrow-up-thin.png +0 -0
  60. package/thirdParty/maplibre-gl-svg/assets/image-templates/arrow-up.png +0 -0
  61. package/thirdParty/maplibre-gl-svg/assets/image-templates/car.png +0 -0
  62. package/thirdParty/maplibre-gl-svg/assets/image-templates/checker-rotated.png +0 -0
  63. package/thirdParty/maplibre-gl-svg/assets/image-templates/checker.png +0 -0
  64. package/thirdParty/maplibre-gl-svg/assets/image-templates/circles-spaced.png +0 -0
  65. package/thirdParty/maplibre-gl-svg/assets/image-templates/circles.png +0 -0
  66. package/thirdParty/maplibre-gl-svg/assets/image-templates/diagonal-lines-down.png +0 -0
  67. package/thirdParty/maplibre-gl-svg/assets/image-templates/diagonal-lines-up.png +0 -0
  68. package/thirdParty/maplibre-gl-svg/assets/image-templates/diagonal-stripes-down.png +0 -0
  69. package/thirdParty/maplibre-gl-svg/assets/image-templates/diagonal-stripes-up.png +0 -0
  70. package/thirdParty/maplibre-gl-svg/assets/image-templates/dots.png +0 -0
  71. package/thirdParty/maplibre-gl-svg/assets/image-templates/flag-triangle.png +0 -0
  72. package/thirdParty/maplibre-gl-svg/assets/image-templates/flag.png +0 -0
  73. package/thirdParty/maplibre-gl-svg/assets/image-templates/grid-lines.png +0 -0
  74. package/thirdParty/maplibre-gl-svg/assets/image-templates/hexagon-rounded-thick.png +0 -0
  75. package/thirdParty/maplibre-gl-svg/assets/image-templates/hexagon-rounded.png +0 -0
  76. package/thirdParty/maplibre-gl-svg/assets/image-templates/hexagon-thick.png +0 -0
  77. package/thirdParty/maplibre-gl-svg/assets/image-templates/hexagon.png +0 -0
  78. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-arrow.png +0 -0
  79. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-ball-pin.png +0 -0
  80. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-circle.png +0 -0
  81. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-flat.png +0 -0
  82. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-square-cluster.png +0 -0
  83. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-square-rounded-cluster.png +0 -0
  84. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-square-rounded.png +0 -0
  85. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-square.png +0 -0
  86. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker-thick.png +0 -0
  87. package/thirdParty/maplibre-gl-svg/assets/image-templates/marker.png +0 -0
  88. package/thirdParty/maplibre-gl-svg/assets/image-templates/pin-round.png +0 -0
  89. package/thirdParty/maplibre-gl-svg/assets/image-templates/pin.png +0 -0
  90. package/thirdParty/maplibre-gl-svg/assets/image-templates/rotated-grid-lines.png +0 -0
  91. package/thirdParty/maplibre-gl-svg/assets/image-templates/rotated-grid-stripes.png +0 -0
  92. package/thirdParty/maplibre-gl-svg/assets/image-templates/rounded-square-thick.png +0 -0
  93. package/thirdParty/maplibre-gl-svg/assets/image-templates/rounded-square.png +0 -0
  94. package/thirdParty/maplibre-gl-svg/assets/image-templates/triangle-arrow-left.png +0 -0
  95. package/thirdParty/maplibre-gl-svg/assets/image-templates/triangle-arrow-up.png +0 -0
  96. package/thirdParty/maplibre-gl-svg/assets/image-templates/triangle-thick.png +0 -0
  97. package/thirdParty/maplibre-gl-svg/assets/image-templates/triangle.png +0 -0
  98. package/thirdParty/maplibre-gl-svg/assets/image-templates/x-fill.png +0 -0
  99. package/thirdParty/maplibre-gl-svg/assets/image-templates/zig-zag-vertical.png +0 -0
  100. package/thirdParty/maplibre-gl-svg/assets/image-templates/zig-zag.png +0 -0
  101. package/thirdParty/maplibre-gl-svg/build/build.js +0 -210
  102. package/thirdParty/maplibre-gl-svg/dist/maplibre-gl-svg.js +0 -339
  103. package/thirdParty/maplibre-gl-svg/dist/maplibre-gl-svg.min.js +0 -4
  104. package/thirdParty/maplibre-gl-svg/docs/docs.md +0 -375
  105. package/thirdParty/maplibre-gl-svg/examples/Add custom SVG template to template manager.html +0 -101
  106. package/thirdParty/maplibre-gl-svg/examples/All built-in SVG templates as HTML markers.html +0 -82
  107. package/thirdParty/maplibre-gl-svg/examples/All built-in SVG templates as symbols.html +0 -124
  108. package/thirdParty/maplibre-gl-svg/examples/Fill polygon with built-in SVG template.html +0 -94
  109. package/thirdParty/maplibre-gl-svg/examples/HTML Marker with Custom SVG Template.html +0 -86
  110. package/thirdParty/maplibre-gl-svg/examples/HTML Marker with built-in SVG template.html +0 -83
  111. package/thirdParty/maplibre-gl-svg/examples/Line layer with built-in SVG template.html +0 -129
  112. package/thirdParty/maplibre-gl-svg/examples/Load SVG from URL.html +0 -96
  113. package/thirdParty/maplibre-gl-svg/examples/SVG template options.html +0 -264
  114. package/thirdParty/maplibre-gl-svg/examples/Symbol layer with built-in SVG template.html +0 -93
  115. package/thirdParty/maplibre-gl-svg/index.html +0 -151
  116. package/thirdParty/maplibre-gl-svg/package-lock.json +0 -5882
  117. package/thirdParty/maplibre-gl-svg/package.json +0 -49
  118. package/thirdParty/maplibre-gl-svg/src/SvgManager.ts +0 -186
  119. package/thirdParty/maplibre-gl-svg/src/SvgTemplateManager.ts +0 -144
  120. package/thirdParty/maplibre-gl-svg/src/index.ts +0 -4
  121. package/thirdParty/maplibre-gl-svg/tsconfig.json +0 -31
  122. package/thirdParty/maplibre-gl-svg/typings/index.d.ts +0 -111
@@ -1,442 +0,0 @@
1
- /******************************************************************************
2
-
3
- Flatmap viewer and annotation tool
4
-
5
- Copyright (c) 2019 - 2023 David Brooks
6
-
7
- Licensed under the Apache License, Version 2.0 (the "License");
8
- you may not use this file except in compliance with the License.
9
- You may obtain a copy of the License at
10
-
11
- http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- Unless required by applicable law or agreed to in writing, software
14
- distributed under the License is distributed on an "AS IS" BASIS,
15
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- See the License for the specific language governing permissions and
17
- limitations under the License.
18
-
19
- ******************************************************************************/
20
-
21
- /* Based on https://github.com/aesqe/maplibre-minimap
22
- *
23
- * MIT License
24
- *
25
- * Copyright (c) 2019 Bruno Babic
26
- *
27
- * Permission is hereby granted, free of charge, to any person obtaining a copy
28
- * of this software and associated documentation files (the "Software"), to deal
29
- * in the Software without restriction, including without limitation the rights
30
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
- * copies of the Software, and to permit persons to whom the Software is
32
- * furnished to do so, subject to the following conditions:
33
- *
34
- * The above copyright notice and this permission notice shall be included in all
35
- * copies or substantial portions of the Software.
36
- *
37
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
- * SOFTWARE.
44
- */
45
-
46
- //==============================================================================
47
-
48
- import maplibregl from 'maplibre-gl';
49
-
50
- //==============================================================================
51
-
52
- const DEFAULTS = {
53
- fillColor: '#DDD',
54
- fillOpacity: 0.3,
55
- lineColor: "#08F",
56
- lineOpacity: 1,
57
- lineWidth: 1,
58
- position: 'bottom-left',
59
- width: 320
60
- };
61
-
62
- //==============================================================================
63
-
64
- // if parent map zoom >= 18 and minimap zoom >= 14, set minimap zoom to 16
65
-
66
- const ZOOMLEVELS = [
67
- [18, 14, 16],
68
- [16, 12, 14],
69
- [14, 10, 12],
70
- [12, 8, 10],
71
- [10, 6, 8]
72
- ];
73
-
74
- //==============================================================================
75
-
76
- export class MinimapControl
77
- {
78
- constructor(flatmap, options)
79
- {
80
- this._flatmap = flatmap;
81
- this._map = undefined;
82
- this._container = null;
83
-
84
- // In case parent map background is changed before minimap loads
85
-
86
- this._background = null;
87
- this._opacity = null;
88
- this._loaded = false;
89
-
90
- // Check user configurable settings
91
-
92
- this._options = Object.assign({}, DEFAULTS);
93
- if (typeof options === 'object') {
94
- if ('position' in options) {
95
- this._options.position = options.position;
96
- }
97
- if ('width' in options) {
98
- this._options.width = options.width;
99
- }
100
- }
101
-
102
- this._ticking = false;
103
- this._lastMouseMoveEvent = null;
104
- this._isDragging = false;
105
- this._isCursorOverFeature = false;
106
- this._previousPoint = [0, 0];
107
- this._currentPoint = [0, 0];
108
- this._trackingRectCoordinates = [[[], [], [], [], []]];
109
- }
110
-
111
- getDefaultPosition()
112
- //==================
113
- {
114
- return this._options.position;
115
- }
116
-
117
- onAdd(map)
118
- //========
119
- {
120
- this._map = map;
121
-
122
- // Create the container element
123
-
124
- const container = document.createElement('div');
125
- container.className = 'maplibregl-ctrl-minimap maplibregl-ctrl';
126
- container.id = 'maplibre-minimap';
127
- this._container = container;
128
-
129
- // Set the size of the container
130
-
131
- const mapCanvasElement = map.getCanvas();
132
- let width = DEFAULTS.width;
133
- if (typeof this._options.width === 'string') {
134
- width = parseInt(this._options.width);
135
- if (this._options.width.includes('%')) {
136
- width = width*mapCanvasElement.width/100;
137
- }
138
- } else if (typeof this._options.width === 'number') {
139
- width = this._options.width;
140
- }
141
- container.setAttribute('style', `width: ${width}px; height: ${width*mapCanvasElement.height/mapCanvasElement.width}px;`);
142
-
143
- // Ignore context menu events
144
-
145
- container.addEventListener('contextmenu', this._preventDefault);
146
-
147
- // Create the actual minimap
148
-
149
- this._miniMap = new maplibregl.Map({
150
- attributionControl: false,
151
- container: container,
152
- style: map.getStyle(),
153
- bounds: map.getBounds()
154
- });
155
-
156
- return this._container;
157
- }
158
-
159
- onRemove()
160
- //========
161
- {
162
- this._container.parentNode.removeChild(this._container);
163
- this._map = undefined;
164
- this._container = null;
165
- }
166
-
167
- initialise()
168
- //==========
169
- {
170
- const opts = this._options;
171
- const parentMap = this._map;
172
- const miniMap = this._miniMap;
173
-
174
- // Disable most user interactions with the minimap
175
-
176
- const interactions = [
177
- 'dragPan', 'scrollZoom', 'boxZoom', 'dragRotate',
178
- 'keyboard', 'doubleClickZoom', 'touchZoomRotate'
179
- ];
180
- interactions.forEach(i => miniMap[i].disable());
181
-
182
- // Set background if specified (default is the parent map's)
183
-
184
- if (this._background !== null) {
185
- miniMap.setPaintProperty('background', 'background-color', this._background);
186
- }
187
- if (this._opacity !== null) {
188
- miniMap.setPaintProperty('background', 'background-opacity', this._opacity);
189
- }
190
-
191
- // Fit minimap to its container
192
-
193
- miniMap.resize();
194
- miniMap.fitBounds(this._flatmap.bounds);
195
-
196
- const bounds = miniMap.getBounds();
197
- this.convertBoundsToPoints_(bounds);
198
-
199
- miniMap.addSource('trackingRect', {
200
- 'type': 'geojson',
201
- 'data': {
202
- 'type': 'Feature',
203
- 'properties': {
204
- 'name': 'trackingRect'
205
- },
206
- 'geometry': {
207
- 'type': 'Polygon',
208
- 'coordinates': this._trackingRectCoordinates
209
- }
210
- }
211
- });
212
-
213
- miniMap.addLayer({
214
- 'id': 'trackingRectOutline',
215
- 'type': 'line',
216
- 'source': 'trackingRect',
217
- 'layout': {},
218
- 'paint': {
219
- 'line-color': opts.lineColor,
220
- 'line-width': opts.lineWidth,
221
- 'line-opacity': opts.lineOpacity
222
- }
223
- });
224
-
225
- // needed for dragging
226
- miniMap.addLayer({
227
- 'id': 'trackingRectFill',
228
- 'type': 'fill',
229
- 'source': 'trackingRect',
230
- 'layout': {},
231
- 'paint': {
232
- 'fill-color': opts.fillColor,
233
- 'fill-opacity': opts.fillOpacity
234
- }
235
- });
236
-
237
- this._trackingRect = this._miniMap.getSource('trackingRect');
238
-
239
- this.update_();
240
-
241
- parentMap.on('move', this.update_.bind(this));
242
-
243
- miniMap.on('mousemove', this.mouseMove_.bind(this));
244
- miniMap.on('mousedown', this.mouseDown_.bind(this));
245
- miniMap.on('mouseup', this.mouseUp_.bind(this));
246
-
247
- miniMap.on('touchmove', this.mouseMove_.bind(this));
248
- miniMap.on('touchstart', this.mouseDown_.bind(this));
249
- miniMap.on('touchend', this.mouseUp_.bind(this));
250
-
251
- this._miniMapCanvas = miniMap.getCanvasContainer();
252
- this._miniMapCanvas.addEventListener('wheel', this.preventDefault_);
253
- this._miniMapCanvas.addEventListener('mousewheel', this.preventDefault_);
254
- }
255
-
256
- mouseDown_(e)
257
- //===========
258
- {
259
- if (this._isCursorOverFeature) {
260
- this._isDragging = true;
261
- this._previousPoint = this._currentPoint;
262
- this._currentPoint = [e.lngLat.lng, e.lngLat.lat];
263
- }
264
- }
265
-
266
- mouseMove_(e)
267
- //===========
268
- {
269
- this._ticking = false;
270
-
271
- const miniMap = this._miniMap;
272
- const features = miniMap.queryRenderedFeatures(e.point, {
273
- layers: ['trackingRectFill']
274
- });
275
-
276
- // don't update if we're still hovering the area
277
- if (!(this._isCursorOverFeature && features.length > 0)) {
278
- this._isCursorOverFeature = features.length > 0;
279
- this._miniMapCanvas.style.cursor = this._isCursorOverFeature ? 'move' : '';
280
- }
281
-
282
- if (this._isDragging) {
283
- this._previousPoint = this._currentPoint;
284
- this._currentPoint = [e.lngLat.lng, e.lngLat.lat];
285
-
286
- const offset = [
287
- this._previousPoint[0] - this._currentPoint[0],
288
- this._previousPoint[1] - this._currentPoint[1]
289
- ];
290
-
291
- const newBounds = this.moveTrackingRect_(offset);
292
-
293
- this._map.fitBounds(newBounds, {
294
- duration: 80,
295
- noMoveStart: true
296
- });
297
- }
298
- }
299
-
300
- mouseUp_()
301
- //========
302
- {
303
- this._isDragging = false;
304
- this._ticking = false;
305
- }
306
-
307
- moveTrackingRect_(offset)
308
- //=======================
309
- {
310
- const source = this._trackingRect;
311
- const data = source._data;
312
- const bounds = data.properties.bounds;
313
-
314
- bounds._ne.lat -= offset[1];
315
- bounds._ne.lng -= offset[0];
316
- bounds._sw.lat -= offset[1];
317
- bounds._sw.lng -= offset[0];
318
-
319
- this.convertBoundsToPoints_(bounds);
320
- source.setData(data);
321
-
322
- return bounds;
323
- }
324
-
325
- setTrackingRectBounds_(bounds)
326
- //============================
327
- {
328
- const source = this._trackingRect;
329
- const data = source._data;
330
-
331
- data.properties.bounds = bounds;
332
- this.convertBoundsToPoints_(bounds);
333
- source.setData(data);
334
- }
335
-
336
- convertBoundsToPoints_(bounds)
337
- //============================
338
- {
339
- const ne = bounds._ne;
340
- const sw = bounds._sw;
341
- const trc = this._trackingRectCoordinates;
342
-
343
- trc[0][0][0] = ne.lng;
344
- trc[0][0][1] = ne.lat;
345
- trc[0][1][0] = sw.lng;
346
- trc[0][1][1] = ne.lat;
347
- trc[0][2][0] = sw.lng;
348
- trc[0][2][1] = sw.lat;
349
- trc[0][3][0] = ne.lng;
350
- trc[0][3][1] = sw.lat;
351
- trc[0][4][0] = ne.lng;
352
- trc[0][4][1] = ne.lat;
353
- }
354
-
355
- update_(e)
356
- //========
357
- {
358
- if (this._isDragging) {
359
- return;
360
- }
361
-
362
- const parentBounds = this._map.getBounds();
363
- this.setTrackingRectBounds_(parentBounds);
364
-
365
- this.zoomAdjust_();
366
- }
367
-
368
- zoomAdjust_()
369
- //===========
370
- {
371
- const miniMap = this._miniMap;
372
- const parentMap = this._map;
373
- const miniZoom = parseInt(miniMap.getZoom(), 10);
374
- const parentZoom = parseInt(parentMap.getZoom(), 10);
375
- let found = false;
376
-
377
- ZOOMLEVELS.forEach(function(zoom) {
378
- if (!found && parentZoom >= zoom[0]) {
379
- if (miniZoom >= zoom[1]) {
380
- miniMap.setZoom(zoom[2]);
381
- }
382
-
383
- miniMap.setCenter(parentMap.getCenter());
384
- found = true;
385
- }
386
- });
387
- }
388
-
389
- preventDefault_(e)
390
- //================
391
- {
392
- e.preventDefault();
393
- }
394
-
395
- /**
396
- * Sets the minimap's background colour.
397
- *
398
- * @param {string} colour The colour
399
- */
400
- setBackgroundColour(colour)
401
- //=========================
402
- {
403
- if (this._loaded) {
404
- this._miniMap.setPaintProperty('background', 'background-color', colour);
405
- } else {
406
- this._background = colour;
407
- }
408
- }
409
-
410
- /**
411
- * Sets the minimap's background opacity.
412
- *
413
- * @param {number} opacity The opacity
414
- */
415
- setBackgroundOpacity(opacity)
416
- //===========================
417
- {
418
- if (this._loaded) {
419
- this._miniMap.setPaintProperty('background', 'background-opacity', opacity);
420
- } else {
421
- this._opacity = opacity;
422
- }
423
- }
424
-
425
- /**
426
- * Show and hide the minimap.
427
- *
428
- * @param {boolean} showMinimap Set false to hide minimap
429
- */
430
- show(showMinimap)
431
- //===============
432
- {
433
- if (this._container) {
434
- if (showMinimap) {
435
- this._container.style.display = "block";
436
- this.update_();
437
- } else {
438
- this._container.style.display = "none";
439
- }
440
- }
441
- }
442
- }
@@ -1,143 +0,0 @@
1
- /******************************************************************************
2
-
3
- Flatmap viewer and annotation tool
4
-
5
- Copyright (c) 2019 - 2023 David Brooks
6
-
7
- Licensed under the Apache License, Version 2.0 (the "License");
8
- you may not use this file except in compliance with the License.
9
- You may obtain a copy of the License at
10
-
11
- http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- Unless required by applicable law or agreed to in writing, software
14
- distributed under the License is distributed on an "AS IS" BASIS,
15
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- See the License for the specific language governing permissions and
17
- limitations under the License.
18
-
19
- ******************************************************************************/
20
-
21
- export class PathControl
22
- {
23
- constructor(flatmap, pathTypes)
24
- {
25
- this._flatmap = flatmap;
26
- this._map = undefined;
27
- this.__pathTypes = pathTypes;
28
- }
29
-
30
- getDefaultPosition()
31
- //==================
32
- {
33
- return 'top-right';
34
- }
35
-
36
- onAdd(map)
37
- //========
38
- {
39
- this._map = map;
40
- this._container = document.createElement('div');
41
- this._container.className = 'maplibregl-ctrl';
42
- this._container.id = 'flatmap-nerve-key';
43
-
44
- this._legend = document.createElement('div');
45
- this._legend.id = 'nerve-key-text';
46
- this._legend.className = 'flatmap-nerve-grid';
47
-
48
- const innerHTML = [];
49
- innerHTML.push(`<label for="path-all-paths">ALL PATHS:</label><div class="nerve-line"></div><input id="path-all-paths" type="checkbox" checked/>`);
50
- this.__checkedCount = 0;
51
- for (const path of this.__pathTypes) {
52
- const checked = !('enabled' in path) || path.enabled ? 'checked' : '';
53
- if (checked != '') {
54
- this.__checkedCount += 1;
55
- }
56
- const colour = path.colour || '#440';
57
- const style = path.dashed ? `background: repeating-linear-gradient(to right,${colour} 0,${colour} 6px,transparent 6px,transparent 9px);`
58
- : `background: ${colour};`;
59
-
60
- innerHTML.push(`<label for="path-${path.type}">${path.label}</label><div class="nerve-line" style="${style}"></div><input id="path-${path.type}" type="checkbox" ${checked}/>`);
61
- }
62
- this._legend.innerHTML = innerHTML.join('\n');
63
- this.__halfCount = Math.trunc(this.__pathTypes.length/2);
64
-
65
- this._button = document.createElement('button');
66
- this._button.id = 'nerve-key-button';
67
- this._button.className = 'control-button text-button';
68
- this._button.setAttribute('type', 'button');
69
- this._button.setAttribute('aria-label', 'Nerve paths legend');
70
- this._button.setAttribute('control-visible', 'false');
71
- this._button.textContent = 'PATHS';
72
- this._button.title = 'Show/hide neuron paths';
73
- this._container.appendChild(this._button);
74
-
75
- this._container.addEventListener('click', this.onClick_.bind(this));
76
- return this._container;
77
- }
78
-
79
- onRemove()
80
- //========
81
- {
82
- this._container.parentNode.removeChild(this._container);
83
- this._map = undefined;
84
- }
85
-
86
- onClick_(event)
87
- //=============
88
- {
89
- if (event.target.id === 'nerve-key-button') {
90
- if (this._button.getAttribute('control-visible') === 'false') {
91
- this._container.appendChild(this._legend);
92
- this._button.setAttribute('control-visible', 'true');
93
- const allPathsCheckbox = document.getElementById('path-all-paths');
94
- allPathsCheckbox.indeterminate = this.__checkedCount < this.__pathTypes.length
95
- && this.__checkedCount > 0;
96
- this._legend.focus();
97
- } else {
98
- this._legend = this._container.removeChild(this._legend);
99
- this._button.setAttribute('control-visible', 'false');
100
- }
101
- } else if (event.target.tagName === 'INPUT') {
102
- if (event.target.id === 'path-all-paths') {
103
- if (event.target.indeterminate) {
104
- event.target.checked = (this.__checkedCount >= this.__halfCount);
105
- event.target.indeterminate = false;
106
- }
107
- if (event.target.checked) {
108
- this.__checkedCount = this.__pathTypes.length;
109
- } else {
110
- this.__checkedCount = 0;
111
- }
112
- for (const path of this.__pathTypes) {
113
- const pathCheckbox = document.getElementById(`path-${path.type}`);
114
- if (pathCheckbox) {
115
- pathCheckbox.checked = event.target.checked;
116
- this._flatmap.enablePath(path.type, event.target.checked);
117
- }
118
- }
119
- } else if (event.target.id.startsWith('path-')) {
120
- const pathType = event.target.id.substring(5);
121
- this._flatmap.enablePath(pathType, event.target.checked);
122
- if (event.target.checked) {
123
- this.__checkedCount += 1;
124
- } else {
125
- this.__checkedCount -= 1;
126
- }
127
- const allPathsCheckbox = document.getElementById('path-all-paths');
128
- if (this.__checkedCount === 0) {
129
- allPathsCheckbox.checked = false;
130
- allPathsCheckbox.indeterminate = false;
131
- } else if (this.__checkedCount === this.__pathTypes.length) {
132
- allPathsCheckbox.checked = true;
133
- allPathsCheckbox.indeterminate = false;
134
- } else {
135
- allPathsCheckbox.indeterminate = true;
136
- }
137
- }
138
- }
139
- event.stopPropagation();
140
- }
141
- }
142
-
143
- //==============================================================================
@@ -1,113 +0,0 @@
1
- /******************************************************************************
2
-
3
- Flatmap viewer and annotation tool
4
-
5
- Copyright (c) 2019 - 2023 David Brooks
6
-
7
- Licensed under the Apache License, Version 2.0 (the "License");
8
- you may not use this file except in compliance with the License.
9
- You may obtain a copy of the License at
10
-
11
- http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- Unless required by applicable law or agreed to in writing, software
14
- distributed under the License is distributed on an "AS IS" BASIS,
15
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- See the License for the specific language governing permissions and
17
- limitations under the License.
18
-
19
- **/
20
- //==============================================================================
21
-
22
- export class SearchControl
23
- {
24
- constructor(flatmap)
25
- {
26
- this.__flatmap = flatmap;
27
- }
28
-
29
- onAdd(map)
30
- //========
31
- {
32
- this._map = map;
33
- this._container = document.createElement('div');
34
- this._container.className = 'maplibregl-ctrl search-control';
35
-
36
- this._input = document.createElement('input');
37
- this._input.id = 'search-control-input';
38
- this._input.setAttribute('type', 'search');
39
- this._input.setAttribute('visible', 'false');
40
- this._input.setAttribute('placeholder', 'Search...');
41
-
42
- this._button = document.createElement('button');
43
- this._button.id = 'search-control-button';
44
- this._button.className = 'control-button';
45
- this._button.title = 'Search flatmap';
46
- this._button.setAttribute('type', 'button');
47
- this._button.setAttribute('aria-label', 'Search flatmap');
48
- // https://iconmonstr.com/magnifier-6-svg/
49
- this._button.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" id="search-control-icon" viewBox="0 0 24 24">
50
- <path d="M21.172 24l-7.387-7.387c-1.388.874-3.024 1.387-4.785 1.387-4.971 0-9-4.029-9-9s4.029-9 9-9 9 4.029 9 9c0 1.761-.514 3.398-1.387 4.785l7.387 7.387-2.828 2.828zm-12.172-8c3.859 0 7-3.14 7-7s-3.141-7-7-7-7 3.14-7 7 3.141 7 7 7z"/>
51
- </svg>`;
52
- this._container.appendChild(this._button);
53
-
54
- this._container.onclick = this.onClick_.bind(this);
55
- return this._container;
56
- }
57
-
58
- getDefaultPosition()
59
- //==================
60
- {
61
- return 'top-right';
62
- }
63
-
64
- onRemove()
65
- //========
66
- {
67
- this._container.parentNode.removeChild(this._container);
68
- this._map = undefined;
69
- }
70
-
71
- searchMap_(search=true)
72
- //=====================
73
- {
74
- this._input = this._container.removeChild(this._input);
75
- this._input.setAttribute('visible', 'false');
76
- const text = this._input.value;
77
- if (search && text !== '') {
78
- const results = this.__flatmap.search(text);
79
- this.__flatmap.showSearchResults(results);
80
- }
81
- }
82
-
83
- onKeyDown_(e)
84
- //===========
85
- {
86
- if (e.key === 'Enter') {
87
- this.searchMap_();
88
- } else if (e.key === 'Escape') {
89
- this.searchMap_(false);
90
- }
91
- }
92
-
93
- onClick_(e)
94
- //=========
95
- {
96
- const targetId = ('rangeTarget' in e) ? e.rangeTarget.id : e.target.id; // FF has rangeTarget
97
- if (['search-control-button', 'search-control-icon'].includes(targetId)) {
98
- if (this._input.getAttribute('visible') === 'false') {
99
- this._container.appendChild(this._input);
100
- this._container.appendChild(this._button);
101
- this._input.setAttribute('visible', 'true');
102
- this._input.onkeydown = this.onKeyDown_.bind(this);
103
- this._input.value = '';
104
- this.__flatmap.clearSearchResults();
105
- this._input.focus();
106
- } else {
107
- this.searchMap_();
108
- }
109
- }
110
- }
111
- }
112
-
113
- //==============================================================================