aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/dumbyUtils.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dumbyUtils.mjs')
-rw-r--r--src/dumbyUtils.mjs40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs
index 95bb3dd..be45139 100644
--- a/src/dumbyUtils.mjs
+++ b/src/dumbyUtils.mjs
@@ -6,7 +6,7 @@ import { insideWindow, insideParent } from './utils'
6 * 6 *
7 * @param {Boolean} reverse -- focus previous map 7 * @param {Boolean} reverse -- focus previous map
8 */ 8 */
9export function focusNextMap (reverse = false) { 9export function focusNextMap(reverse = false) {
10 const renderedList = this.utils.renderedMaps() 10 const renderedList = this.utils.renderedMaps()
11 const index = renderedList.findIndex(e => e.classList.contains('focus')) 11 const index = renderedList.findIndex(e => e.classList.contains('focus'))
12 const nextIndex = (index + (reverse ? -1 : 1)) % renderedList.length 12 const nextIndex = (index + (reverse ? -1 : 1)) % renderedList.length
@@ -21,7 +21,7 @@ export function focusNextMap (reverse = false) {
21 * 21 *
22 * @param {Boolean} reverse -- focus previous block 22 * @param {Boolean} reverse -- focus previous block
23 */ 23 */
24export function focusNextBlock (reverse = false) { 24export function focusNextBlock(reverse = false) {
25 const blocks = this.blocks.filter(b => 25 const blocks = this.blocks.filter(b =>
26 b.checkVisibility({ 26 b.checkVisibility({
27 contentVisibilityAuto: true, 27 contentVisibilityAuto: true,
@@ -56,7 +56,7 @@ export const scrollToBlock = block => {
56/** 56/**
57 * focusDelay. Delay of throttle, value changes by cases 57 * focusDelay. Delay of throttle, value changes by cases
58 */ 58 */
59export function focusDelay () { 59export function focusDelay() {
60 return window.window.getComputedStyle(this.showcase).display === 'none' ? 50 : 300 60 return window.window.getComputedStyle(this.showcase).display === 'none' ? 50 : 300
61} 61}
62 62
@@ -65,7 +65,7 @@ export function focusDelay () {
65 * 65 *
66 * @param {Boolean} reverse -- Switch to previous one 66 * @param {Boolean} reverse -- Switch to previous one
67 */ 67 */
68export function switchToNextLayout (reverse = false) { 68export function switchToNextLayout(reverse = false) {
69 const layouts = this.layouts 69 const layouts = this.layouts
70 const currentLayoutName = this.container.getAttribute('data-layout') 70 const currentLayoutName = this.container.getAttribute('data-layout')
71 const currentIndex = layouts.map(l => l.name).indexOf(currentLayoutName) 71 const currentIndex = layouts.map(l => l.name).indexOf(currentLayoutName)
@@ -81,7 +81,7 @@ export function switchToNextLayout (reverse = false) {
81/** 81/**
82 * removeBlockFocus. 82 * removeBlockFocus.
83 */ 83 */
84export function removeBlockFocus () { 84export function removeBlockFocus() {
85 this.blocks.forEach(b => b.classList.remove('focus')) 85 this.blocks.forEach(b => b.classList.remove('focus'))
86} 86}
87 87
@@ -243,3 +243,33 @@ const isAnchorVisible = anchor => {
243 const mapContainer = anchor.closest('.mapclay') 243 const mapContainer = anchor.closest('.mapclay')
244 return insideWindow(anchor) && insideParent(anchor, mapContainer) 244 return insideWindow(anchor) && insideParent(anchor, mapContainer)
245} 245}
246
247export const addAnchorByEvent = ({
248 event,
249 map,
250 validateAnchorName = () => true
251}) => {
252 const rect = map.getBoundingClientRect()
253 const [x, y] = map.renderer
254 .unproject([event.x - rect.left, event.y - rect.top])
255 .map(coord => Number(coord.toFixed(7)))
256
257 let prompt
258 let anchorName
259
260 do {
261 prompt = prompt ? 'Anchor name exists' : 'Name this anchor'
262 anchorName = window.prompt(prompt, `${x}, ${y}`)
263 }
264 while (anchorName !== null && !validateAnchorName(anchorName))
265 if (anchorName === null) return
266
267 const link = `geo:${y},${x}?xy=${x},${y}&id=${map.id} "${anchorName}"`
268 map.renderer.addMarker({
269 xy: [x, y],
270 title: `${map.id}@${x}, ${y}`,
271 type: 'circle',
272 })
273
274 return { ref: anchorName, link }
275}