diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MenuItem.mjs | 36 | ||||
-rw-r--r-- | src/dumbyUtils.mjs | 6 | ||||
-rw-r--r-- | src/dumbymap.mjs | 9 |
3 files changed, 47 insertions, 4 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs index 74b01d5..874c829 100644 --- a/src/MenuItem.mjs +++ b/src/MenuItem.mjs | |||
@@ -1,4 +1,5 @@ | |||
1 | import { shiftByWindow } from './utils.mjs' | 1 | import { shiftByWindow } from './utils.mjs' |
2 | import * as utils from './dumbyUtils.mjs' | ||
2 | 3 | ||
3 | /** | 4 | /** |
4 | * @typedef {Object} RefLink | 5 | * @typedef {Object} RefLink |
@@ -426,3 +427,38 @@ export const addRefLink = (cm, refLinks) => | |||
426 | }) | 427 | }) |
427 | }), | 428 | }), |
428 | }) | 429 | }) |
430 | |||
431 | /** | ||
432 | * setGeoLinkTypeItem. | ||
433 | * | ||
434 | * @param {HTMLAnchorElement} link | ||
435 | * @param {String} text | ||
436 | * @param {String} type | ||
437 | */ | ||
438 | export const setGeoLinkTypeItem = ({ link, text, type }) => { | ||
439 | const params = new URLSearchParams(link.search) | ||
440 | return new Item({ | ||
441 | text, | ||
442 | onclick: () => { | ||
443 | params.set('type', type) | ||
444 | link.search = params | ||
445 | utils.removeLeaderLines(link) | ||
446 | utils.getMarkersFromMaps(link) | ||
447 | .forEach(marker => marker.remove()) | ||
448 | utils.getMarkersFromMaps(link) | ||
449 | }, | ||
450 | }) | ||
451 | } | ||
452 | |||
453 | /** | ||
454 | * setGeoLinkType. | ||
455 | * | ||
456 | * @param {HTMLAnchorElement} link | ||
457 | */ | ||
458 | export const setGeoLinkType = (link) => new Folder({ | ||
459 | text: 'Marker Type', | ||
460 | items: [ | ||
461 | setGeoLinkTypeItem({ link, text: 'Pin', type: 'pin' }), | ||
462 | setGeoLinkTypeItem({ link, text: 'Circle', type: 'circle' }), | ||
463 | ], | ||
464 | }) | ||
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 42a51bc..8fe23eb 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs | |||
@@ -93,7 +93,8 @@ export function removeBlockFocus () { | |||
93 | * @param {HTMLAnchorElement} link | 93 | * @param {HTMLAnchorElement} link |
94 | * @return {HTMLElement[]} markers | 94 | * @return {HTMLElement[]} markers |
95 | */ | 95 | */ |
96 | const getMarkersFromMaps = link => { | 96 | export const getMarkersFromMaps = link => { |
97 | const params = new URLSearchParams(link.search) | ||
97 | const maps = Array.from( | 98 | const maps = Array.from( |
98 | link.closest('.Dumby') | 99 | link.closest('.Dumby') |
99 | .querySelectorAll('.mapclay[data-render="fulfilled"]'), | 100 | .querySelectorAll('.mapclay[data-render="fulfilled"]'), |
@@ -107,7 +108,7 @@ const getMarkersFromMaps = link => { | |||
107 | const marker = map.querySelector(`.marker[data-xy="${lonLat}"]`) ?? | 108 | const marker = map.querySelector(`.marker[data-xy="${lonLat}"]`) ?? |
108 | renderer.addMarker({ | 109 | renderer.addMarker({ |
109 | xy: lonLat, | 110 | xy: lonLat, |
110 | type: link.type, | 111 | type: params.get('type') ?? null, |
111 | }) | 112 | }) |
112 | marker.dataset.xy = lonLat | 113 | marker.dataset.xy = lonLat |
113 | marker.title = new URLSearchParams(link.search).get('xy') ?? lonLat | 114 | marker.title = new URLSearchParams(link.search).get('xy') ?? lonLat |
@@ -167,7 +168,6 @@ export const createGeoLink = (link) => { | |||
167 | link.classList.remove('not-geolink') | 168 | link.classList.remove('not-geolink') |
168 | // TODO refactor as data attribute | 169 | // TODO refactor as data attribute |
169 | link.targets = params.get('id')?.split(',') ?? null | 170 | link.targets = params.get('id')?.split(',') ?? null |
170 | link.type = params.get('type') ?? null | ||
171 | link.title = 'Left-Click to move Camera, Middle-Click to clean anchor' | 171 | link.title = 'Left-Click to move Camera, Middle-Click to clean anchor' |
172 | 172 | ||
173 | link.lines = [] | 173 | link.lines = [] |
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index 6e5bc38..4d6657f 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -555,9 +555,16 @@ export const generateMaps = (container, { | |||
555 | if (geoLink.classList.contains('from-text')) { | 555 | if (geoLink.classList.contains('from-text')) { |
556 | menu.appendChild(new menuItem.Item({ | 556 | menu.appendChild(new menuItem.Item({ |
557 | text: 'Delete', | 557 | text: 'Delete', |
558 | onclick: () => geoLink.replaceWith(document.createTextNode(geoLink.textContent)), | 558 | onclick: () => { |
559 | utils.getMarkersFromMaps(geoLink) | ||
560 | .forEach(m => m.remove()) | ||
561 | geoLink.replaceWith( | ||
562 | document.createTextNode(geoLink.textContent), | ||
563 | ) | ||
564 | }, | ||
559 | })) | 565 | })) |
560 | } | 566 | } |
567 | menu.appendChild(menuItem.setGeoLinkType(geoLink)) | ||
561 | return | 568 | return |
562 | } | 569 | } |
563 | 570 | ||