wiki-plugin-rcnmap 0.5.1 → 0.5.3

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.
package/client/rcnmap.js CHANGED
@@ -154,6 +154,80 @@
154
154
  if (f.seen.has(id)) return 0.42
155
155
  return f.click ? 0.3 : 0.13
156
156
  }
157
+ // Whole or Step, item by item (Nov 17 2026), the same choice as the explorer's
158
+ // panes (tools/rcn-together.html). Step: a walk — this item's or one it
159
+ // follows — zooms the item to each step. Whole: the item shows the whole
160
+ // timeline, map or drawing and stays where you put it; steps light things in
161
+ // place, and you pan and zoom by hand. A click elsewhere still brings the item
162
+ // to what was clicked. ⤢ shows the whole thing again. Each kind of item
163
+ // (timeline, map, sketch) remembers its last choice in this browser.
164
+ const FRAME_KEY = 'rcnLineupFrame'
165
+ const frameSaved = () => { try { return JSON.parse(localStorage.getItem(FRAME_KEY)) || {} } catch (e) { return {} } }
166
+ R.frame = el => el.rcnFrame || (el.rcnFrame = frameSaved()[el.rcnKind] === 'whole' ? 'whole' : 'step')
167
+ R.whole = el => R.frame(el) === 'whole'
168
+ const frameHTML = fr => {
169
+ const b = 'font:inherit;font-size:12px;border:0;padding:2px 8px;cursor:pointer;'
170
+ const on = 'background:#4f46e5;color:#fff;', off = 'background:#fff;color:#334155;'
171
+ return `<button data-fr="whole" style="${b}${fr === 'whole' ? on : off}" title="Show the whole thing; a walk lights things where they are and leaves the view to you. Drag to pan, pinch or ⌘-scroll to zoom.">Whole</button>` +
172
+ `<button data-fr="step" style="${b}border-left:1px solid #cbd5e1;${fr === 'step' ? on : off}" title="Zoom in on each step of a walk">Step</button>` +
173
+ (fr === 'whole' ? `<button data-fr="fit" style="${b}border-left:1px solid #cbd5e1;${off}" title="Show the whole thing again">⤢</button>` : '')
174
+ }
175
+ // The switch, for an item's button row. kind: 'timeline' | 'map' | 'sketch'.
176
+ R.frameSwitch = kind => `<span class="rcn-frame" data-kind="${kind}" style="display:inline-flex;vertical-align:middle;border:1px solid #cbd5e1;border-radius:6px;overflow:hidden" role="group" aria-label="During a walk"></span>`
177
+ // Wire an item's switch. fn(frame, fit) redraws the item for the new choice.
178
+ R.bindFrame = function (el, kind, fn) {
179
+ el.rcnKind = kind
180
+ const draw = () => el.querySelectorAll('.rcn-frame').forEach(s => { s.innerHTML = frameHTML(R.frame(el)) })
181
+ draw()
182
+ if (el.rcnFrameBound) { el.rcnFrameFn = fn; return }
183
+ el.rcnFrameBound = true; el.rcnFrameFn = fn
184
+ el.addEventListener('click', e => {
185
+ const b = e.target.closest && e.target.closest('.rcn-frame button')
186
+ if (!b) return
187
+ e.stopPropagation()
188
+ const v = b.dataset.fr, was = R.frame(el)
189
+ if (v !== 'fit') {
190
+ el.rcnFrame = v
191
+ const s = frameSaved(); s[kind] = v
192
+ try { localStorage.setItem(FRAME_KEY, JSON.stringify(s)) } catch (err) {}
193
+ }
194
+ el.querySelectorAll('.rcn-frame').forEach(s => { s.innerHTML = frameHTML(R.frame(el)) })
195
+ if (v === 'fit' || v !== was) try { el.rcnFrameFn(R.frame(el), v === 'fit') } catch (err) { console.warn('rcn-frame:', err) }
196
+ })
197
+ }
198
+ // Hand pan and zoom on an element, for items without their own (the timeline
199
+ // and the drawing; the map has Leaflet's). Only while on() says so. Drag pans,
200
+ // pinch or ⌘/Ctrl-scroll zooms about the pointer, double-click shows the whole.
201
+ // A drag swallows the click that ends it, so it never counts as a click on a box.
202
+ // h: {on(), pan(dxPx, dyPx), zoom(factor, xPx, yPx), reset()}; positions are
203
+ // relative to the element's top-left corner.
204
+ R.handView = function (box, h) {
205
+ if (box.rcnHand) { box.rcnHand = h; return }
206
+ box.rcnHand = h
207
+ let drag = null, moved = false
208
+ box.addEventListener('pointerdown', e => {
209
+ if (!box.rcnHand.on() || e.button !== 0) return
210
+ drag = { x: e.clientX, y: e.clientY, id: e.pointerId }; moved = false
211
+ })
212
+ box.addEventListener('pointermove', e => {
213
+ if (!drag || e.pointerId !== drag.id) return
214
+ const dx = e.clientX - drag.x, dy = e.clientY - drag.y
215
+ if (!moved && Math.hypot(dx, dy) < 4) return
216
+ if (!moved) { moved = true; try { box.setPointerCapture(e.pointerId) } catch (err) {} box.style.cursor = 'grabbing' }
217
+ drag.x = e.clientX; drag.y = e.clientY
218
+ box.rcnHand.pan(dx, dy)
219
+ })
220
+ const up = () => { if (drag) { drag = null; box.style.cursor = '' } }
221
+ box.addEventListener('pointerup', up); box.addEventListener('pointercancel', up)
222
+ box.addEventListener('click', e => { if (moved) { moved = false; e.stopPropagation(); e.preventDefault() } }, true)
223
+ box.addEventListener('wheel', e => {
224
+ if (!box.rcnHand.on() || !(e.ctrlKey || e.metaKey)) return // a plain scroll still scrolls the wiki page
225
+ e.preventDefault()
226
+ const r = box.getBoundingClientRect()
227
+ box.rcnHand.zoom(Math.exp(-e.deltaY * (e.deltaMode ? 0.05 : 0.002) * (e.ctrlKey ? 10 : 1)), e.clientX - r.left, e.clientY - r.top) // a pinch arrives as ctrl+wheel in small steps
228
+ }, { passive: false })
229
+ box.addEventListener('dblclick', e => { if (box.rcnHand.on()) { e.preventDefault(); e.stopPropagation(); box.rcnHand.reset() } }, true)
230
+ }
157
231
  // "⧉ Open together": the Time Place Causality Explorer on an item's set file
158
232
  // (item.set). A bare file name lives in the site's /assets/NDC/ folder beside
159
233
  // the explorer and the full tools; a full address may point anywhere, and the
@@ -202,6 +276,49 @@
202
276
  const ESRI = 'https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/'
203
277
  const DEFAULT_COLOR = '#64748b'
204
278
 
279
+ // ── Base maps ─────────────────────────────────────────────────────────
280
+ // The full RCN Map's seven, no-key tile sources only. Light (Esri's grey
281
+ // canvas) is the default: coloured points and ties read best on it. An item
282
+ // may name its own first choice (item.basemap, e.g. "Topo"). Once a viewer
283
+ // picks one, that choice is kept in this browser (localStorage rcnBasemap, the
284
+ // key the full RCN Map uses too) and wins everywhere, and every map open on the
285
+ // site follows a new pick: the items on this page and the full map in other tabs.
286
+ const BASEMAP_KEY = 'rcnBasemap'
287
+ const OSM_CREDIT = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
288
+ function basemaps () {
289
+ const L = window.L
290
+ const esri = shade => L.layerGroup([
291
+ L.tileLayer(ESRI + 'World_' + shade + '_Gray_Base/MapServer/tile/{z}/{y}/{x}', {
292
+ maxNativeZoom: 16, maxZoom: 19, attribution: 'Tiles © Esri — Esri, HERE, Garmin, © OpenStreetMap contributors' }),
293
+ L.tileLayer(ESRI + 'World_' + shade + '_Gray_Reference/MapServer/tile/{z}/{y}/{x}', { maxNativeZoom: 16, maxZoom: 19 })
294
+ ])
295
+ return {
296
+ Light: esri('Light'),
297
+ OpenStreetMap: L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: OSM_CREDIT }),
298
+ Satellite: L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
299
+ maxZoom: 19, attribution: 'Tiles © Esri — Source: Esri, USGS, NOAA' }),
300
+ Topo: L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
301
+ maxZoom: 17, attribution: '© <a href="https://opentopomap.org">OpenTopoMap</a> (CC-BY-SA)' }),
302
+ CyclOSM: L.tileLayer('https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png', {
303
+ maxZoom: 19, attribution: '© <a href="https://www.cyclosm.org">CyclOSM</a> — ' + OSM_CREDIT }),
304
+ Transport: L.tileLayer('https://tile.memomaps.de/tilegen/{z}/{x}/{y}.png', {
305
+ maxZoom: 18, attribution: '© <a href="https://memomaps.de">MeMoMaps</a> — ' + OSM_CREDIT }),
306
+ Dark: esri('Dark')
307
+ }
308
+ }
309
+ const BASE_NAMES = ['Light', 'OpenStreetMap', 'Satellite', 'Topo', 'CyclOSM', 'Transport', 'Dark']
310
+ function storedBase () {
311
+ try { const k = localStorage.getItem(BASEMAP_KEY); return BASE_NAMES.includes(k) ? k : null } catch (e) { return null }
312
+ }
313
+ // Every RCN map item drawn on this page moves to base map `name`.
314
+ function followBase (name) {
315
+ document.querySelectorAll('.rcnmap-source').forEach(el => { if (el.rcnmDrawn && el.rcnmDrawn.setBase) el.rcnmDrawn.setBase(name) })
316
+ }
317
+ if (typeof window !== 'undefined' && !window.rcnmapBaseListen) {
318
+ window.rcnmapBaseListen = true
319
+ window.addEventListener('storage', e => { if (e.key === BASEMAP_KEY && BASE_NAMES.includes(e.newValue)) followBase(e.newValue) })
320
+ }
321
+
205
322
  const esc = s => String(s == null ? '' : s)
206
323
  .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
207
324
 
@@ -439,7 +556,7 @@
439
556
  if (!d) return
440
557
  const L = window.L, walk = wk && wk.w !== null ? walkList(item)[wk.w] : null
441
558
  const f = !walk && el.rcnmFollow && el.rcnmFollow.lit ? el.rcnmFollow : null
442
- if (f) { followPaint(d, item, f); return }
559
+ if (f) { followPaint(d, item, f, RL.whole && RL.whole(el) && !f.click); return }
443
560
  const st = walk && walk.steps[wk.i], lit = st ? stepLit(st) : null
444
561
  const seenP = new Set(), seenT = new Set()
445
562
  if (walk) walk.steps.slice(0, wk.i).forEach(s => { const x = stepLit(s); if (x) { x.P.forEach(v => seenP.add(v)); x.T.forEach(v => seenT.add(v)) } })
@@ -458,6 +575,9 @@
458
575
  const tiles = d.map.getPane('tilePane')
459
576
  if (tiles) tiles.style.opacity = walk ? '0.55' : ''
460
577
  walkLabels(d, item, lit ? lit.P : null)
578
+ // Whole (the Whole / Step switch, rcn-lineup-follow): the walk lights its points
579
+ // where they are and the map stays where you put it.
580
+ if (RL && RL.whole && RL.whole(el)) return
461
581
  if (!walk) { if (!stay) d.home(); return }
462
582
  if (st.view && Array.isArray(st.view.center)) { d.map.flyTo(st.view.center, st.view.zoom || 12, { duration: 1.1 }); return }
463
583
  const pts = lit ? [...lit.P].map(id => d.markers[id] && d.markers[id].getLatLng()).filter(Boolean) : []
@@ -481,7 +601,7 @@
481
601
  // Following another item in the lineup (see rcn-lineup-follow): the points it
482
602
  // lights here at full strength and named, a tie between two of them heavier,
483
603
  // what it lit before at half, the rest faded; the map flies to the lit points.
484
- function followPaint (d, item, f) {
604
+ function followPaint (d, item, f, stay) { // stay: light them in place (Whole), don't fly
485
605
  const L = window.L, op = id => RL.op(f, id)
486
606
  d.ties.forEach(t => {
487
607
  const [a, b] = t.key.split('>'), on = f.lit.has(a) && f.lit.has(b)
@@ -496,6 +616,7 @@
496
616
  const tiles = d.map.getPane('tilePane')
497
617
  if (tiles) tiles.style.opacity = '0.55'
498
618
  walkLabels(d, item, f.lit)
619
+ if (stay) return
499
620
  const pts = [...f.lit].map(id => d.markers[id] && d.markers[id].getLatLng()).filter(Boolean)
500
621
  if (pts.length === 1) d.map.flyTo(pts[0], Math.max(d.map.getZoom(), 13), { duration: 1.1 })
501
622
  else if (pts.length) d.map.flyToBounds(L.latLngBounds(pts), { padding: [30, 30], maxZoom: 14, duration: 1.1 })
@@ -799,7 +920,7 @@
799
920
  <p class="caption" style="margin:4px 0 0;">${wiki.resolveLinks ? wiki.resolveLinks(esc(caption(item))) : esc(caption(item))}</p>
800
921
  ${controls}
801
922
  ${walkBar(item)}
802
- ${canOpen(item) || (RL && RL.togetherButton(item)) ? `<div style="text-align:center;padding-top:6px">${canOpen(item) ? `<button class="rcnm-open" style="cursor:pointer;font-size:12px;padding:2px 8px" title="Open this map in the full RCN Map to write or change its walks; Save to wiki there brings them back here">🗺 Open in RCN Map</button> ` : ''}${RL ? RL.togetherButton(item) : ''}</div>` : ''}
923
+ ${canOpen(item) || (RL && (RL.togetherButton(item) || RL.frameSwitch)) ? `<div style="text-align:center;padding-top:6px">${canOpen(item) ? `<button class="rcnm-open" style="cursor:pointer;font-size:12px;padding:2px 8px" title="Open this map in the full RCN Map to write or change its walks; Save to wiki there brings them back here">🗺 Open in RCN Map</button> ` : ''}${RL ? RL.togetherButton(item) : ''} ${RL && RL.frameSwitch ? RL.frameSwitch('map') : ''}</div>` : ''}
803
924
  </div>
804
925
  <style>
805
926
  .rcnm-label{background:none;border:0}
@@ -819,17 +940,23 @@
819
940
  function draw ($item, item, m, id) {
820
941
  const L = window.L
821
942
  const map = L.map(id, { scrollWheelZoom: false, zoomControl: true, attributionControl: true })
822
- L.tileLayer(ESRI + 'World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}', {
823
- maxNativeZoom: 16, maxZoom: 19,
824
- attribution: 'Tiles © Esri — Esri, HERE, Garmin, © OpenStreetMap contributors'
825
- }).addTo(map)
826
- L.tileLayer(ESRI + 'World_Light_Gray_Reference/MapServer/tile/{z}/{y}/{x}', {
827
- maxNativeZoom: 16, maxZoom: 19
828
- }).addTo(map)
943
+ const bases = basemaps()
944
+ const first = storedBase() || (BASE_NAMES.includes(item.basemap) ? item.basemap : 'Light')
945
+ bases[first].addTo(map)
946
+ L.control.layers(bases, null, { position: 'topleft', collapsed: true }).addTo(map)
829
947
 
830
948
  const byId = {}
831
949
  m.parcels.forEach(p => { byId[p.id] = p })
832
- const drawn = { map, markers: {}, ties: [], labels: null }
950
+ const drawn = { map, markers: {}, ties: [], labels: null, base: first }
951
+ drawn.setBase = name => {
952
+ if (name === drawn.base || !bases[name]) return
953
+ map.removeLayer(bases[drawn.base]); bases[name].addTo(map); drawn.base = name
954
+ }
955
+ map.on('baselayerchange', e => {
956
+ drawn.base = e.name
957
+ try { localStorage.setItem(BASEMAP_KEY, e.name) } catch (err) {}
958
+ followBase(e.name)
959
+ })
833
960
 
834
961
  // Ties first, so the points sit on top and stay clickable.
835
962
  ;(m.links || []).forEach(l => {
@@ -881,6 +1008,9 @@
881
1008
  }
882
1009
  drawn.home()
883
1010
  el.rcnmDrawn = drawn
1011
+ // Whole / Step (rcn-lineup-follow). Whole and ⤢ go back to the item's own view,
1012
+ // then pan and zoom are yours; Step goes to what is lit now.
1013
+ if (RL && RL.bindFrame) RL.bindFrame(el, 'map', (fr, fit) => { if (fr === 'whole' || fit) drawn.home(); else walkPaint(el, item, true) })
884
1014
  // A click on the map itself lets go of what this map last lit beside it.
885
1015
  map.on('click', () => { if (RL && el.rcnClicked) RL.click(el, 'map', { clear: true }) })
886
1016
  map.on('zoomend moveend', () => walkDeclutter(drawn))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcnmap",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Federated Wiki plugin: a small RCN map on a page that draws points and the ties between them; each point opens its page",
5
5
  "keywords": ["wiki", "federated wiki", "plugin", "rcn", "map"],
6
6
  "author": "RCN Network <rcn@relocalizecreativity.net>",
@@ -21,6 +21,11 @@
21
21
  "text": "Editing the item. Double-click to open the text editor. The first line of the text is the caption; the rest lists the points and ties in plain words, so wiki search finds them. The points and ties themselves live in the item\u2019s map field. A new item from the Factory has no map field yet: type lines of the form 48.75, -122.48 Name and each becomes a point, as in the native Map plugin.",
22
22
  "id": "9f943464d295f7ea"
23
23
  },
24
+ {
25
+ "type": "paragraph",
26
+ "id": "b566c6177960e085",
27
+ "text": "Base maps. The stacked-layers icon at the top left of the map switches between the full RCN Map's seven: Light, OpenStreetMap, Satellite, Topo, CyclOSM, Transport and Dark. Light is the default, because coloured points and ties read best on it; an item can name its own with a basemap field, for example \"basemap\": \"Topo\". Once a viewer picks one, it is kept in their browser and used by every RCN map of the site, these items and the full RCN Map alike, and maps already open switch with it."
28
+ },
24
29
  {
25
30
  "type": "paragraph",
26
31
  "text": "Below: Community to Community and the co-ops it is tied to, from the Co-ops of Whatcom County pages.",
@@ -143,6 +148,11 @@
143
148
  "id": "167c2d7ef5bb6a19",
144
149
  "text": "Opening the explorer. Give the item a set field naming a set file, for example \"set\": \"superior.set.json\", and it shows a \u29c9 Open together button. The button opens the Time Place Causality Explorer, which puts the timeline, the map and the sketch side by side on one page. A bare file name means the site's /assets/NDC/ folder, where the explorer and the full tools sit; a full address can point to a set anywhere."
145
150
  },
151
+ {
152
+ "type": "paragraph",
153
+ "id": "11b78d613de9c2fe",
154
+ "text": "Whole or Step. Beside the item's buttons, Whole \u00b7 Step says what this map does while a walk plays, its own or one it follows. Step flies to what each step is about. Whole goes back to the map's own view and then stays where you put it: each step lights its points where they are, and you pan and zoom the map yourself. \u2922 goes back to the map's own view. A click on the timeline or the drawing beside it still brings the map to that place. You can switch at any time, in the middle of a walk too, and the choice is remembered in your browser. The Time Place Causality Explorer has the same switch on each of its panes."
155
+ },
146
156
  {
147
157
  "type": "paragraph",
148
158
  "id": "22dca488818d034f",
@@ -382,6 +392,28 @@
382
392
  },
383
393
  "after": "b6ab902739e74ee2",
384
394
  "date": 1794195627668
395
+ },
396
+ {
397
+ "type": "add",
398
+ "id": "b566c6177960e085",
399
+ "item": {
400
+ "type": "paragraph",
401
+ "id": "b566c6177960e085",
402
+ "text": "Base maps. The stacked-layers icon at the top left of the map switches between the full RCN Map's seven: Light, OpenStreetMap, Satellite, Topo, CyclOSM, Transport and Dark. Light is the default, because coloured points and ties read best on it; an item can name its own with a basemap field, for example \"basemap\": \"Topo\". Once a viewer picks one, it is kept in their browser and used by every RCN map of the site, these items and the full RCN Map alike, and maps already open switch with it."
403
+ },
404
+ "after": "9f943464d295f7ea",
405
+ "date": 1794199587785
406
+ },
407
+ {
408
+ "type": "add",
409
+ "id": "11b78d613de9c2fe",
410
+ "item": {
411
+ "type": "paragraph",
412
+ "id": "11b78d613de9c2fe",
413
+ "text": "Whole or Step. Beside the item's buttons, Whole \u00b7 Step says what this map does while a walk plays, its own or one it follows. Step flies to what each step is about. Whole goes back to the map's own view and then stays where you put it: each step lights its points where they are, and you pan and zoom the map yourself. \u2922 goes back to the map's own view. A click on the timeline or the drawing beside it still brings the map to that place. You can switch at any time, in the middle of a walk too, and the choice is remembered in your browser. The Time Place Causality Explorer has the same switch on each of its panes."
414
+ },
415
+ "after": "167c2d7ef5bb6a19",
416
+ "date": 1794945537903
385
417
  }
386
418
  ]
387
419
  }