@abi-software/flatmapvuer 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +120 -120
  3. package/cypress.config.js +23 -23
  4. package/dist/flatmapvuer.js +43580 -38546
  5. package/dist/flatmapvuer.umd.cjs +189 -181
  6. package/dist/index.html +17 -17
  7. package/dist/style.css +1 -1
  8. package/package.json +95 -95
  9. package/public/index.html +17 -17
  10. package/reporter-config.json +9 -9
  11. package/src/App.vue +379 -379
  12. package/src/assets/_variables.scss +43 -43
  13. package/src/assets/styles.scss +5 -5
  14. package/src/components/AnnotationTool.vue +501 -501
  15. package/src/components/ConnectionDialog.vue +134 -134
  16. package/src/components/DrawTool.vue +502 -502
  17. package/src/components/EventBus.js +3 -3
  18. package/src/components/ExternalResourceCard.vue +109 -109
  19. package/src/components/FlatmapVuer.vue +3515 -3455
  20. package/src/components/HelpModeDialog.vue +360 -360
  21. package/src/components/MultiFlatmapVuer.vue +814 -814
  22. package/src/components/ProvenancePopup.vue +530 -530
  23. package/src/components/SelectionsGroup.vue +363 -363
  24. package/src/components/Tooltip.vue +50 -50
  25. package/src/components/TreeControls.vue +236 -236
  26. package/src/components/index.js +8 -8
  27. package/src/components/legends/DynamicLegends.vue +106 -106
  28. package/src/components/legends/SvgLegends.vue +112 -112
  29. package/src/icons/flatmap-marker.js +9 -1
  30. package/src/icons/fonts/mapicon-species.svg +14 -14
  31. package/src/icons/fonts/mapicon-species.ttf +0 -0
  32. package/src/icons/fonts/mapicon-species.woff +0 -0
  33. package/src/icons/mapicon-species-style.css +42 -42
  34. package/src/icons/yellowstar.js +5 -5
  35. package/src/legends/legend.svg +25 -25
  36. package/src/main.js +19 -19
  37. package/src/services/flatmapQueries.js +475 -475
  38. package/src/store/index.js +23 -23
  39. package/vite.config.js +73 -73
  40. package/vite.static-build.js +12 -12
  41. package/vuese-generator.js +64 -64
@@ -1,502 +1,502 @@
1
- <template>
2
- <div>
3
- <div class="drawtool-container">
4
- <el-popover
5
- content="Connection"
6
- placement="left"
7
- :teleported="false"
8
- trigger="manual"
9
- width="100"
10
- popper-class="flatmap-popper"
11
- :visible="hoverVisibilities[10].value"
12
- ref="connectionPopover"
13
- >
14
- <template #reference>
15
- <map-svg-icon
16
- icon="connection"
17
- class="icon-button drawConnection"
18
- @click="drawConnectionEvent()"
19
- @mouseover="showTooltip(10)"
20
- @mouseout="hideTooltip(10)"
21
- />
22
- </template>
23
- </el-popover>
24
- <el-popover
25
- content="Draw Point"
26
- placement="top"
27
- :teleported="false"
28
- trigger="manual"
29
- width="80"
30
- popper-class="flatmap-popper"
31
- :visible="hoverVisibilities[11].value"
32
- v-if="drawnType !== 'LineString' && drawnType !== 'Polygon'"
33
- ref="drawPointPopover"
34
- >
35
- <template #reference>
36
- <map-svg-icon
37
- icon="drawPoint"
38
- class="icon-button drawPoint"
39
- @click="drawToolEvent('Point')"
40
- @mouseover="showTooltip(11)"
41
- @mouseout="hideTooltip(11)"
42
- />
43
- </template>
44
- </el-popover>
45
- <el-popover
46
- content="Draw Line"
47
- placement="top"
48
- :teleported="false"
49
- trigger="manual"
50
- width="80"
51
- popper-class="flatmap-popper"
52
- :visible="hoverVisibilities[12].value"
53
- v-if="drawnType !== 'Point' && drawnType !== 'Polygon'"
54
- ref="drawLinePopover"
55
- >
56
- <template #reference>
57
- <map-svg-icon
58
- icon="drawLine"
59
- class="icon-button drawLineString"
60
- @click="drawToolEvent('LineString')"
61
- @mouseover="showTooltip(12)"
62
- @mouseout="hideTooltip(12)"
63
- />
64
- </template>
65
- </el-popover>
66
- <el-popover
67
- content="Draw Polygon"
68
- placement="top"
69
- :teleported="false"
70
- trigger="manual"
71
- width="80"
72
- popper-class="flatmap-popper"
73
- :visible="hoverVisibilities[13].value"
74
- v-if="drawnType !== 'Point' && drawnType !== 'LineString'"
75
- ref="drawPolygonPopover"
76
- >
77
- <template #reference>
78
- <map-svg-icon
79
- icon="drawPolygon"
80
- class="icon-button drawPolygon"
81
- @click="drawToolEvent('Polygon')"
82
- @mouseover="showTooltip(13)"
83
- @mouseout="hideTooltip(13)"
84
- />
85
- </template>
86
- </el-popover>
87
- <el-popover
88
- content="Delete"
89
- placement="top"
90
- :teleported="false"
91
- trigger="manual"
92
- width="80"
93
- popper-class="flatmap-popper"
94
- :visible="hoverVisibilities[14].value"
95
- ref="deletePopover"
96
- >
97
- <template #reference>
98
- <map-svg-icon
99
- icon="drawTrash"
100
- class="icon-button drawDelete"
101
- @click="drawModeEvent('Delete')"
102
- @mouseover="showTooltip(14)"
103
- @mouseout="hideTooltip(14)"
104
- />
105
- </template>
106
- </el-popover>
107
- <el-popover
108
- content="Edit"
109
- placement="top"
110
- :teleported="false"
111
- trigger="manual"
112
- width="80"
113
- popper-class="flatmap-popper"
114
- :visible="hoverVisibilities[15].value"
115
- ref="editPopover"
116
- >
117
- <template #reference>
118
- <map-svg-icon
119
- icon="comment"
120
- class="icon-button drawEdit"
121
- @click="drawModeEvent('Edit')"
122
- @mouseover="showTooltip(15)"
123
- @mouseout="hideTooltip(15)"
124
- />
125
- </template>
126
- </el-popover>
127
- </div>
128
- <ConnectionDialog
129
- class="connection-dialog"
130
- v-show="connectionDisplay"
131
- :connectionEntry="connectionEntry"
132
- :inDrawing="inDrawing"
133
- :hasConnection="hasConnection"
134
- @dialogDisplay="drawConnectionEvent()"
135
- @confirmDrawn="$emit('confirmDrawn', $event)"
136
- @cancelDrawn="$emit('cancelDrawn', $event)"
137
- @featureTooltip="$emit('featureTooltip', $event)"
138
- />
139
- </div>
140
- </template>
141
-
142
- <script>
143
- import { MapSvgIcon } from "@abi-software/svg-sprite";
144
- import "@abi-software/svg-sprite/dist/style.css";
145
- import ConnectionDialog from "./ConnectionDialog.vue";
146
- /* eslint-disable no-alert, no-console */
147
-
148
- /**
149
- * @param scopeElement Draggable scope area (Optional)
150
- * @param dragElement Draggable element
151
- */
152
- const draggable = (scopeElement, dragElement) => {
153
- let startX, startY, clickX, clickY, posX, posY;
154
- // reset position in case previous pupped up dialog is dragged
155
- dragElement.style.left = "";
156
- dragElement.style.top = "";
157
- // const scopeRect = scopeElement.getBoundingClientRect()
158
- // const dragRect = dragElement.getBoundingClientRect()
159
-
160
- dragElement.addEventListener(
161
- "mousedown",
162
- (e) => {
163
- e.preventDefault();
164
- startX = dragElement.offsetLeft;
165
- startY = dragElement.offsetTop;
166
- clickX = e.clientX;
167
- clickY = e.clientY;
168
-
169
- dragElement.addEventListener("mousemove", drag, false);
170
- document.addEventListener(
171
- "mouseup",
172
- () => {
173
- dragElement.removeEventListener("mousemove", drag, false);
174
- },
175
- false
176
- );
177
- },
178
- false
179
- );
180
-
181
- function drag(e) {
182
- e.preventDefault();
183
- posX = startX - (clickX - e.clientX);
184
- posY = startY - (clickY - e.clientY);
185
- // if (
186
- // (posX > scopeRect.left && ((posX + dragRect.width) < scopeRect.right)) &&
187
- // (posY > scopeRect.top && ((posY + dragRect.height) < scopeRect.bottom))
188
- // ) {
189
- dragElement.style.left = `${posX}px`;
190
- dragElement.style.top = `${posY}px`;
191
- // } else {
192
- // if (posX <= scopeRect.left) {
193
- // dragElement.style.left = '0px';
194
- // } else if (posX + dragRect.width >= scopeRect.right) {
195
- // dragElement.style.left = `${scopeRect.right - dragRect.width}px`;
196
- // }
197
- // if (posY <= scopeRect.top) {
198
- // dragElement.style.top = '0px';
199
- // } else if (posY + dragRect.height >= scopeRect.bottom) {
200
- // dragElement.style.top = `${scopeRect.bottom - dragRect.height}px`;
201
- // }
202
- // }
203
- }
204
- };
205
-
206
- export default {
207
- name: "DrawTool",
208
- components: {
209
- MapSvgIcon,
210
- },
211
- props: {
212
- flatmapCanvas: {
213
- type: Object,
214
- default: null,
215
- },
216
- drawnType: {
217
- type: String,
218
- },
219
- activeDrawTool: {
220
- type: String,
221
- },
222
- activeDrawMode: {
223
- type: String,
224
- },
225
- drawnCreatedEvent: {
226
- type: Object,
227
- },
228
- connectionEntry: {
229
- type: Object,
230
- },
231
- hoverVisibilities: {
232
- type: Array,
233
- },
234
- },
235
- data: function () {
236
- return {
237
- activeTool: undefined,
238
- activeMode: undefined,
239
- connectionDisplay: false,
240
- dialogPosition: {
241
- offsetX: 0,
242
- offsetY: 0,
243
- x: undefined,
244
- y: undefined,
245
- },
246
- toolbarIcons: [
247
- { name: "Connection", active: false, disabled: true },
248
- { name: "Point", active: false, disabled: false },
249
- { name: "LineString", active: false, disabled: false },
250
- { name: "Polygon", active: false, disabled: false },
251
- { name: "Edit", active: false, disabled: false },
252
- { name: "Delete", active: false, disabled: false },
253
- ],
254
- };
255
- },
256
- computed: {
257
- inDrawing: function () {
258
- return this.activeDrawTool !== undefined;
259
- },
260
- isFeatureDrawn: function () {
261
- return this.drawnCreatedEvent !== undefined;
262
- },
263
- hasConnection: function () {
264
- return Object.keys(this.connectionEntry).length > 0;
265
- },
266
- },
267
- watch: {
268
- activeDrawTool: function (value) {
269
- this.updateToolbarIcons(value);
270
- if (!value) this.connectionDisplay = false;
271
- },
272
- activeDrawMode: function (value) {
273
- this.updateToolbarIcons(value);
274
- if (value === "Delete") this.connectionDisplay = false;
275
- },
276
- hasConnection: function (value) {
277
- this.updateToolbarConnectionIcon(value, "disabled");
278
- if (!value) this.connectionDisplay = false;
279
- },
280
- isFeatureDrawn: function (value) {
281
- if (value) this.connectionDisplay = true;
282
- },
283
- connectionDisplay: function (value) {
284
- this.updateToolbarConnectionIcon(value, "active");
285
- if (value) this.dialogCssHacks();
286
- else this.$emit("featureTooltip", undefined);
287
- },
288
- dialogPosition: {
289
- handler: function () {
290
- const containerRect = this.$el.getBoundingClientRect();
291
- this.dialogPosition.offsetX = containerRect.x;
292
- this.dialogPosition.offsetY = containerRect.y;
293
- },
294
- deep: true,
295
- once: true,
296
- },
297
- },
298
- methods: {
299
- drawConnectionEvent: function () {
300
- if (
301
- this.hasConnection &&
302
- !this.activeDrawTool && // disable connection icon in drawing
303
- this.activeDrawMode !== "Delete" // disable connection icon in delete mode
304
- ) {
305
- this.connectionDisplay = !this.connectionDisplay;
306
- }
307
- },
308
- updateToolbarConnectionIcon: function (value, type) {
309
- this.toolbarIcons
310
- .filter((icon) => icon.name === "Connection")
311
- .map((icon) => {
312
- // Disable connection icon when delete mode is on
313
- if (this.activeDrawMode === "Delete") {
314
- icon.disabled = true;
315
- } else {
316
- if (type === "active") {
317
- if (value) icon.active = true;
318
- else icon.active = false;
319
- }
320
- if (type === "disabled") {
321
- if (value) icon.disabled = false;
322
- else icon.disabled = true;
323
- }
324
- }
325
- });
326
- this.toolbarCssHacks();
327
- },
328
- updateToolbarIcons: function (value) {
329
- this.toolbarIcons.map((icon) => {
330
- if (icon.name === value) icon.active = true;
331
- else icon.active = false;
332
- });
333
- this.toolbarIcons
334
- .filter((icon) => icon.name !== "Connection" && icon.name !== value)
335
- .map((icon) => {
336
- if (value) icon.disabled = true;
337
- else icon.disabled = false;
338
- });
339
- this.toolbarCssHacks();
340
- },
341
- drawToolEvent: function (type) {
342
- if (
343
- (!this.activeDrawTool || this.activeDrawTool === type) && // disable other tool icon when one is on
344
- !this.activeDrawMode && // disable tool icon in edit or delete mode
345
- !this.connectionDisplay // disable tool icon when connection displayed
346
- ) {
347
- if (type === "Point") {
348
- const point = this.flatmapCanvas.querySelector(
349
- ".mapbox-gl-draw_point"
350
- );
351
- point.click();
352
- this.activeTool = point.classList.contains("active")
353
- ? "Point"
354
- : undefined;
355
- } else if (type === "LineString") {
356
- const line = this.flatmapCanvas.querySelector(".mapbox-gl-draw_line");
357
- line.click();
358
- this.activeTool = line.classList.contains("active")
359
- ? "LineString"
360
- : undefined;
361
- } else if (type === "Polygon") {
362
- const polygon = this.flatmapCanvas.querySelector(
363
- ".mapbox-gl-draw_polygon"
364
- );
365
- polygon.click();
366
- this.activeTool = polygon.classList.contains("active")
367
- ? "Polygon"
368
- : undefined;
369
- }
370
- this.$emit("drawToolbarEvent", this.activeTool);
371
- }
372
- },
373
- drawModeEvent: function (type) {
374
- if (
375
- (!this.activeDrawMode || this.activeDrawMode === type) && // disable other mode icon when one is on
376
- !this.activeDrawTool // disable tool icon in drawing
377
- ) {
378
- this.activeMode = type;
379
- this.$emit("drawToolbarEvent", this.activeMode);
380
- }
381
- },
382
- toolbarCssHacks: function () {
383
- // set toolbar icon style
384
- this.toolbarIcons.map((icon) => {
385
- const iconElement = this.$el.querySelector(`.draw${icon.name}`);
386
- if (iconElement) {
387
- if (icon.active) iconElement.classList.add("active");
388
- else iconElement.classList.remove("active");
389
- if (icon.disabled) iconElement.classList.add("disabled");
390
- else iconElement.classList.remove("disabled");
391
- }
392
- });
393
- },
394
- dialogCssHacks: function () {
395
- this.$nextTick(() => {
396
- const dialog = this.$el.querySelector(".connection-dialog");
397
- draggable(this.flatmapCanvas, dialog);
398
- // dialog popup at the click position
399
- // slightly change x or y if close to boundary
400
- let posX, posY;
401
- const containerRect = this.flatmapCanvas.getBoundingClientRect();
402
- const dialogRect = dialog.getBoundingClientRect();
403
- if (this.dialogPosition.x > containerRect.width / 2) {
404
- posX = this.dialogPosition.x - dialogRect.width;
405
- } else {
406
- posX = this.dialogPosition.x;
407
- }
408
- if (this.dialogPosition.y > containerRect.height / 2) {
409
- posY = this.dialogPosition.y - dialogRect.height;
410
- } else {
411
- posY = this.dialogPosition.y;
412
- }
413
- dialog.style.transform = `translate(${
414
- posX - this.dialogPosition.offsetX
415
- }px, ${posY - this.dialogPosition.offsetY}px)`;
416
- });
417
- },
418
- showTooltip: function (tooltipNumber) {
419
- this.$emit("showTooltip", tooltipNumber);
420
- },
421
- hideTooltip: function (tooltipNumber) {
422
- this.$emit("hideTooltip", tooltipNumber);
423
- },
424
- clickHandler: function (e) {
425
- e.preventDefault();
426
- this.dialogPosition.x = e.clientX;
427
- this.dialogPosition.y = e.clientY;
428
- if (this.activeDrawTool === "Point") {
429
- this.dialogCssHacks();
430
- }
431
- },
432
- },
433
- mounted: function () {
434
- this.toolbarCssHacks();
435
- if (this.flatmapCanvas) {
436
- this.flatmapCanvas
437
- .querySelector(".maplibregl-canvas")
438
- .addEventListener("click", this.clickHandler, false);
439
- }
440
- },
441
- destroyed: function () {
442
- if (this.flatmapCanvas) {
443
- this.flatmapCanvas
444
- .querySelector(".maplibregl-canvas")
445
- .removeEventListener("click", this.clickHandler, false);
446
- }
447
- },
448
- };
449
- </script>
450
-
451
- <style lang="scss" scoped>
452
- .drawtool-container {
453
- background-color: var(--el-color-primary-light-9);
454
- padding: 4px 4px 2px 4px;
455
- border-style: solid;
456
- border-color: var(--el-color-primary-light-5);
457
- border-radius: 1rem;
458
- position: absolute;
459
- right: calc(50vw - 100px);
460
- bottom: 16px;
461
- z-index: 10;
462
- }
463
-
464
- .drawPoint,
465
- .drawLineString,
466
- .drawPolygon,
467
- .drawDelete,
468
- .drawEdit,
469
- .drawConnection {
470
- padding: 4px;
471
- color: var(--el-color-primary-light-5) !important;
472
- }
473
-
474
- .icon-button {
475
- height: 24px !important;
476
- width: 24px !important;
477
- color: $app-primary-color;
478
-
479
- &.open-map-button {
480
- margin-bottom: 4px;
481
- }
482
-
483
- &:hover {
484
- cursor: pointer;
485
- }
486
- }
487
-
488
- .active {
489
- color: var(--el-color-primary) !important;
490
- }
491
-
492
- .disabled {
493
- color: #dddddd !important;
494
- cursor: not-allowed !important;
495
- }
496
-
497
- .connection-dialog {
498
- position: absolute;
499
- z-index: 10;
500
- cursor: move;
501
- }
502
- </style>
1
+ <template>
2
+ <div>
3
+ <div class="drawtool-container">
4
+ <el-popover
5
+ content="Connection"
6
+ placement="left"
7
+ :teleported="false"
8
+ trigger="manual"
9
+ width="100"
10
+ popper-class="flatmap-popper"
11
+ :visible="hoverVisibilities[10].value"
12
+ ref="connectionPopover"
13
+ >
14
+ <template #reference>
15
+ <map-svg-icon
16
+ icon="connection"
17
+ class="icon-button drawConnection"
18
+ @click="drawConnectionEvent()"
19
+ @mouseover="showTooltip(10)"
20
+ @mouseout="hideTooltip(10)"
21
+ />
22
+ </template>
23
+ </el-popover>
24
+ <el-popover
25
+ content="Draw Point"
26
+ placement="top"
27
+ :teleported="false"
28
+ trigger="manual"
29
+ width="80"
30
+ popper-class="flatmap-popper"
31
+ :visible="hoverVisibilities[11].value"
32
+ v-if="drawnType !== 'LineString' && drawnType !== 'Polygon'"
33
+ ref="drawPointPopover"
34
+ >
35
+ <template #reference>
36
+ <map-svg-icon
37
+ icon="drawPoint"
38
+ class="icon-button drawPoint"
39
+ @click="drawToolEvent('Point')"
40
+ @mouseover="showTooltip(11)"
41
+ @mouseout="hideTooltip(11)"
42
+ />
43
+ </template>
44
+ </el-popover>
45
+ <el-popover
46
+ content="Draw Line"
47
+ placement="top"
48
+ :teleported="false"
49
+ trigger="manual"
50
+ width="80"
51
+ popper-class="flatmap-popper"
52
+ :visible="hoverVisibilities[12].value"
53
+ v-if="drawnType !== 'Point' && drawnType !== 'Polygon'"
54
+ ref="drawLinePopover"
55
+ >
56
+ <template #reference>
57
+ <map-svg-icon
58
+ icon="drawLine"
59
+ class="icon-button drawLineString"
60
+ @click="drawToolEvent('LineString')"
61
+ @mouseover="showTooltip(12)"
62
+ @mouseout="hideTooltip(12)"
63
+ />
64
+ </template>
65
+ </el-popover>
66
+ <el-popover
67
+ content="Draw Polygon"
68
+ placement="top"
69
+ :teleported="false"
70
+ trigger="manual"
71
+ width="80"
72
+ popper-class="flatmap-popper"
73
+ :visible="hoverVisibilities[13].value"
74
+ v-if="drawnType !== 'Point' && drawnType !== 'LineString'"
75
+ ref="drawPolygonPopover"
76
+ >
77
+ <template #reference>
78
+ <map-svg-icon
79
+ icon="drawPolygon"
80
+ class="icon-button drawPolygon"
81
+ @click="drawToolEvent('Polygon')"
82
+ @mouseover="showTooltip(13)"
83
+ @mouseout="hideTooltip(13)"
84
+ />
85
+ </template>
86
+ </el-popover>
87
+ <el-popover
88
+ content="Delete"
89
+ placement="top"
90
+ :teleported="false"
91
+ trigger="manual"
92
+ width="80"
93
+ popper-class="flatmap-popper"
94
+ :visible="hoverVisibilities[14].value"
95
+ ref="deletePopover"
96
+ >
97
+ <template #reference>
98
+ <map-svg-icon
99
+ icon="drawTrash"
100
+ class="icon-button drawDelete"
101
+ @click="drawModeEvent('Delete')"
102
+ @mouseover="showTooltip(14)"
103
+ @mouseout="hideTooltip(14)"
104
+ />
105
+ </template>
106
+ </el-popover>
107
+ <el-popover
108
+ content="Edit"
109
+ placement="top"
110
+ :teleported="false"
111
+ trigger="manual"
112
+ width="80"
113
+ popper-class="flatmap-popper"
114
+ :visible="hoverVisibilities[15].value"
115
+ ref="editPopover"
116
+ >
117
+ <template #reference>
118
+ <map-svg-icon
119
+ icon="comment"
120
+ class="icon-button drawEdit"
121
+ @click="drawModeEvent('Edit')"
122
+ @mouseover="showTooltip(15)"
123
+ @mouseout="hideTooltip(15)"
124
+ />
125
+ </template>
126
+ </el-popover>
127
+ </div>
128
+ <ConnectionDialog
129
+ class="connection-dialog"
130
+ v-show="connectionDisplay"
131
+ :connectionEntry="connectionEntry"
132
+ :inDrawing="inDrawing"
133
+ :hasConnection="hasConnection"
134
+ @dialogDisplay="drawConnectionEvent()"
135
+ @confirmDrawn="$emit('confirmDrawn', $event)"
136
+ @cancelDrawn="$emit('cancelDrawn', $event)"
137
+ @featureTooltip="$emit('featureTooltip', $event)"
138
+ />
139
+ </div>
140
+ </template>
141
+
142
+ <script>
143
+ import { MapSvgIcon } from "@abi-software/svg-sprite";
144
+ import "@abi-software/svg-sprite/dist/style.css";
145
+ import ConnectionDialog from "./ConnectionDialog.vue";
146
+ /* eslint-disable no-alert, no-console */
147
+
148
+ /**
149
+ * @param scopeElement Draggable scope area (Optional)
150
+ * @param dragElement Draggable element
151
+ */
152
+ const draggable = (scopeElement, dragElement) => {
153
+ let startX, startY, clickX, clickY, posX, posY;
154
+ // reset position in case previous pupped up dialog is dragged
155
+ dragElement.style.left = "";
156
+ dragElement.style.top = "";
157
+ // const scopeRect = scopeElement.getBoundingClientRect()
158
+ // const dragRect = dragElement.getBoundingClientRect()
159
+
160
+ dragElement.addEventListener(
161
+ "mousedown",
162
+ (e) => {
163
+ e.preventDefault();
164
+ startX = dragElement.offsetLeft;
165
+ startY = dragElement.offsetTop;
166
+ clickX = e.clientX;
167
+ clickY = e.clientY;
168
+
169
+ dragElement.addEventListener("mousemove", drag, false);
170
+ document.addEventListener(
171
+ "mouseup",
172
+ () => {
173
+ dragElement.removeEventListener("mousemove", drag, false);
174
+ },
175
+ false
176
+ );
177
+ },
178
+ false
179
+ );
180
+
181
+ function drag(e) {
182
+ e.preventDefault();
183
+ posX = startX - (clickX - e.clientX);
184
+ posY = startY - (clickY - e.clientY);
185
+ // if (
186
+ // (posX > scopeRect.left && ((posX + dragRect.width) < scopeRect.right)) &&
187
+ // (posY > scopeRect.top && ((posY + dragRect.height) < scopeRect.bottom))
188
+ // ) {
189
+ dragElement.style.left = `${posX}px`;
190
+ dragElement.style.top = `${posY}px`;
191
+ // } else {
192
+ // if (posX <= scopeRect.left) {
193
+ // dragElement.style.left = '0px';
194
+ // } else if (posX + dragRect.width >= scopeRect.right) {
195
+ // dragElement.style.left = `${scopeRect.right - dragRect.width}px`;
196
+ // }
197
+ // if (posY <= scopeRect.top) {
198
+ // dragElement.style.top = '0px';
199
+ // } else if (posY + dragRect.height >= scopeRect.bottom) {
200
+ // dragElement.style.top = `${scopeRect.bottom - dragRect.height}px`;
201
+ // }
202
+ // }
203
+ }
204
+ };
205
+
206
+ export default {
207
+ name: "DrawTool",
208
+ components: {
209
+ MapSvgIcon,
210
+ },
211
+ props: {
212
+ flatmapCanvas: {
213
+ type: Object,
214
+ default: null,
215
+ },
216
+ drawnType: {
217
+ type: String,
218
+ },
219
+ activeDrawTool: {
220
+ type: String,
221
+ },
222
+ activeDrawMode: {
223
+ type: String,
224
+ },
225
+ drawnCreatedEvent: {
226
+ type: Object,
227
+ },
228
+ connectionEntry: {
229
+ type: Object,
230
+ },
231
+ hoverVisibilities: {
232
+ type: Array,
233
+ },
234
+ },
235
+ data: function () {
236
+ return {
237
+ activeTool: undefined,
238
+ activeMode: undefined,
239
+ connectionDisplay: false,
240
+ dialogPosition: {
241
+ offsetX: 0,
242
+ offsetY: 0,
243
+ x: undefined,
244
+ y: undefined,
245
+ },
246
+ toolbarIcons: [
247
+ { name: "Connection", active: false, disabled: true },
248
+ { name: "Point", active: false, disabled: false },
249
+ { name: "LineString", active: false, disabled: false },
250
+ { name: "Polygon", active: false, disabled: false },
251
+ { name: "Edit", active: false, disabled: false },
252
+ { name: "Delete", active: false, disabled: false },
253
+ ],
254
+ };
255
+ },
256
+ computed: {
257
+ inDrawing: function () {
258
+ return this.activeDrawTool !== undefined;
259
+ },
260
+ isFeatureDrawn: function () {
261
+ return this.drawnCreatedEvent !== undefined;
262
+ },
263
+ hasConnection: function () {
264
+ return Object.keys(this.connectionEntry).length > 0;
265
+ },
266
+ },
267
+ watch: {
268
+ activeDrawTool: function (value) {
269
+ this.updateToolbarIcons(value);
270
+ if (!value) this.connectionDisplay = false;
271
+ },
272
+ activeDrawMode: function (value) {
273
+ this.updateToolbarIcons(value);
274
+ if (value === "Delete") this.connectionDisplay = false;
275
+ },
276
+ hasConnection: function (value) {
277
+ this.updateToolbarConnectionIcon(value, "disabled");
278
+ if (!value) this.connectionDisplay = false;
279
+ },
280
+ isFeatureDrawn: function (value) {
281
+ if (value) this.connectionDisplay = true;
282
+ },
283
+ connectionDisplay: function (value) {
284
+ this.updateToolbarConnectionIcon(value, "active");
285
+ if (value) this.dialogCssHacks();
286
+ else this.$emit("featureTooltip", undefined);
287
+ },
288
+ dialogPosition: {
289
+ handler: function () {
290
+ const containerRect = this.$el.getBoundingClientRect();
291
+ this.dialogPosition.offsetX = containerRect.x;
292
+ this.dialogPosition.offsetY = containerRect.y;
293
+ },
294
+ deep: true,
295
+ once: true,
296
+ },
297
+ },
298
+ methods: {
299
+ drawConnectionEvent: function () {
300
+ if (
301
+ this.hasConnection &&
302
+ !this.activeDrawTool && // disable connection icon in drawing
303
+ this.activeDrawMode !== "Delete" // disable connection icon in delete mode
304
+ ) {
305
+ this.connectionDisplay = !this.connectionDisplay;
306
+ }
307
+ },
308
+ updateToolbarConnectionIcon: function (value, type) {
309
+ this.toolbarIcons
310
+ .filter((icon) => icon.name === "Connection")
311
+ .map((icon) => {
312
+ // Disable connection icon when delete mode is on
313
+ if (this.activeDrawMode === "Delete") {
314
+ icon.disabled = true;
315
+ } else {
316
+ if (type === "active") {
317
+ if (value) icon.active = true;
318
+ else icon.active = false;
319
+ }
320
+ if (type === "disabled") {
321
+ if (value) icon.disabled = false;
322
+ else icon.disabled = true;
323
+ }
324
+ }
325
+ });
326
+ this.toolbarCssHacks();
327
+ },
328
+ updateToolbarIcons: function (value) {
329
+ this.toolbarIcons.map((icon) => {
330
+ if (icon.name === value) icon.active = true;
331
+ else icon.active = false;
332
+ });
333
+ this.toolbarIcons
334
+ .filter((icon) => icon.name !== "Connection" && icon.name !== value)
335
+ .map((icon) => {
336
+ if (value) icon.disabled = true;
337
+ else icon.disabled = false;
338
+ });
339
+ this.toolbarCssHacks();
340
+ },
341
+ drawToolEvent: function (type) {
342
+ if (
343
+ (!this.activeDrawTool || this.activeDrawTool === type) && // disable other tool icon when one is on
344
+ !this.activeDrawMode && // disable tool icon in edit or delete mode
345
+ !this.connectionDisplay // disable tool icon when connection displayed
346
+ ) {
347
+ if (type === "Point") {
348
+ const point = this.flatmapCanvas.querySelector(
349
+ ".mapbox-gl-draw_point"
350
+ );
351
+ point.click();
352
+ this.activeTool = point.classList.contains("active")
353
+ ? "Point"
354
+ : undefined;
355
+ } else if (type === "LineString") {
356
+ const line = this.flatmapCanvas.querySelector(".mapbox-gl-draw_line");
357
+ line.click();
358
+ this.activeTool = line.classList.contains("active")
359
+ ? "LineString"
360
+ : undefined;
361
+ } else if (type === "Polygon") {
362
+ const polygon = this.flatmapCanvas.querySelector(
363
+ ".mapbox-gl-draw_polygon"
364
+ );
365
+ polygon.click();
366
+ this.activeTool = polygon.classList.contains("active")
367
+ ? "Polygon"
368
+ : undefined;
369
+ }
370
+ this.$emit("drawToolbarEvent", this.activeTool);
371
+ }
372
+ },
373
+ drawModeEvent: function (type) {
374
+ if (
375
+ (!this.activeDrawMode || this.activeDrawMode === type) && // disable other mode icon when one is on
376
+ !this.activeDrawTool // disable tool icon in drawing
377
+ ) {
378
+ this.activeMode = type;
379
+ this.$emit("drawToolbarEvent", this.activeMode);
380
+ }
381
+ },
382
+ toolbarCssHacks: function () {
383
+ // set toolbar icon style
384
+ this.toolbarIcons.map((icon) => {
385
+ const iconElement = this.$el.querySelector(`.draw${icon.name}`);
386
+ if (iconElement) {
387
+ if (icon.active) iconElement.classList.add("active");
388
+ else iconElement.classList.remove("active");
389
+ if (icon.disabled) iconElement.classList.add("disabled");
390
+ else iconElement.classList.remove("disabled");
391
+ }
392
+ });
393
+ },
394
+ dialogCssHacks: function () {
395
+ this.$nextTick(() => {
396
+ const dialog = this.$el.querySelector(".connection-dialog");
397
+ draggable(this.flatmapCanvas, dialog);
398
+ // dialog popup at the click position
399
+ // slightly change x or y if close to boundary
400
+ let posX, posY;
401
+ const containerRect = this.flatmapCanvas.getBoundingClientRect();
402
+ const dialogRect = dialog.getBoundingClientRect();
403
+ if (this.dialogPosition.x > containerRect.width / 2) {
404
+ posX = this.dialogPosition.x - dialogRect.width;
405
+ } else {
406
+ posX = this.dialogPosition.x;
407
+ }
408
+ if (this.dialogPosition.y > containerRect.height / 2) {
409
+ posY = this.dialogPosition.y - dialogRect.height;
410
+ } else {
411
+ posY = this.dialogPosition.y;
412
+ }
413
+ dialog.style.transform = `translate(${
414
+ posX - this.dialogPosition.offsetX
415
+ }px, ${posY - this.dialogPosition.offsetY}px)`;
416
+ });
417
+ },
418
+ showTooltip: function (tooltipNumber) {
419
+ this.$emit("showTooltip", tooltipNumber);
420
+ },
421
+ hideTooltip: function (tooltipNumber) {
422
+ this.$emit("hideTooltip", tooltipNumber);
423
+ },
424
+ clickHandler: function (e) {
425
+ e.preventDefault();
426
+ this.dialogPosition.x = e.clientX;
427
+ this.dialogPosition.y = e.clientY;
428
+ if (this.activeDrawTool === "Point") {
429
+ this.dialogCssHacks();
430
+ }
431
+ },
432
+ },
433
+ mounted: function () {
434
+ this.toolbarCssHacks();
435
+ if (this.flatmapCanvas) {
436
+ this.flatmapCanvas
437
+ .querySelector(".maplibregl-canvas")
438
+ .addEventListener("click", this.clickHandler, false);
439
+ }
440
+ },
441
+ destroyed: function () {
442
+ if (this.flatmapCanvas) {
443
+ this.flatmapCanvas
444
+ .querySelector(".maplibregl-canvas")
445
+ .removeEventListener("click", this.clickHandler, false);
446
+ }
447
+ },
448
+ };
449
+ </script>
450
+
451
+ <style lang="scss" scoped>
452
+ .drawtool-container {
453
+ background-color: var(--el-color-primary-light-9);
454
+ padding: 4px 4px 2px 4px;
455
+ border-style: solid;
456
+ border-color: var(--el-color-primary-light-5);
457
+ border-radius: 1rem;
458
+ position: absolute;
459
+ right: calc(50vw - 100px);
460
+ bottom: 16px;
461
+ z-index: 10;
462
+ }
463
+
464
+ .drawPoint,
465
+ .drawLineString,
466
+ .drawPolygon,
467
+ .drawDelete,
468
+ .drawEdit,
469
+ .drawConnection {
470
+ padding: 4px;
471
+ color: var(--el-color-primary-light-5) !important;
472
+ }
473
+
474
+ .icon-button {
475
+ height: 24px !important;
476
+ width: 24px !important;
477
+ color: $app-primary-color;
478
+
479
+ &.open-map-button {
480
+ margin-bottom: 4px;
481
+ }
482
+
483
+ &:hover {
484
+ cursor: pointer;
485
+ }
486
+ }
487
+
488
+ .active {
489
+ color: var(--el-color-primary) !important;
490
+ }
491
+
492
+ .disabled {
493
+ color: #dddddd !important;
494
+ cursor: not-allowed !important;
495
+ }
496
+
497
+ .connection-dialog {
498
+ position: absolute;
499
+ z-index: 10;
500
+ cursor: move;
501
+ }
502
+ </style>