Klick på en delad pin flyttar platsen dit (exakt lagrad position)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
aeb1c76428
commit
a28b091002
@@ -1009,7 +1009,7 @@
|
||||
}
|
||||
function pinsGeo() {
|
||||
return { type: 'FeatureCollection', features: pinData.cities.map(c => ({ type: 'Feature',
|
||||
properties: { n: c.n, label: `${c.city}, ${c.country} · ${c.n} ${c.n === 1 ? 'delad pin' : 'delade pins'}` },
|
||||
properties: { n: c.n, lat: c.lat, lng: c.lng, place: `${c.city}, ${c.country}`, label: `${c.city}, ${c.country} · ${c.n} ${c.n === 1 ? 'delad pin' : 'delade pins'}` },
|
||||
geometry: { type: 'Point', coordinates: [c.lng, c.lat] } })) };
|
||||
}
|
||||
async function initMap() {
|
||||
@@ -1043,6 +1043,7 @@
|
||||
+ '<button type="button" id="gz-out" aria-label="Zooma ut" title="Zooma ut">−</button></div>');
|
||||
$('gz-in').onclick = () => map.zoomIn(); $('gz-out').onclick = () => map.zoomOut();
|
||||
setInterval(() => map.getSource('night') && map.getSource('night').setData(nightPolygon(now())), 60 * 1000);
|
||||
if (q.has('debug')) window.__globe = map; // test hook
|
||||
map.on('load', () => { fetchPins(); $('map').dataset.proj = JSON.stringify(map.getProjection && map.getProjection()); }); // diagnostics
|
||||
map.on('error', ev => { $('map').dataset.err = String(ev && ev.error && ev.error.message || ev).slice(0, 200); });
|
||||
const el = document.createElement('div'); el.className = 'me-pin'; el.title = 'Din valda plats';
|
||||
@@ -1054,7 +1055,13 @@
|
||||
map.on('mouseleave', 'pins', () => { tip.style.display = 'none'; map.getCanvas().style.cursor = ''; });
|
||||
map.on('click', ev => {
|
||||
const hit = map.getLayer('pins') && map.queryRenderedFeatures(ev.point, { layers: ['pins', 'pins-glow'] })[0];
|
||||
if (hit) { tip.textContent = hit.properties.label; tip.style.left = ev.point.x + 'px'; tip.style.top = ev.point.y + 'px'; tip.style.display = 'block'; return; }
|
||||
if (hit) { // a shared pin: jump straight to that city
|
||||
const { lat, lng } = hit.properties; // exact stored position (rendered geometry is slightly quantized)
|
||||
tip.style.display = 'none';
|
||||
$('p-loc-note').textContent = `Du tittar nu på himlen över ${hit.properties.place}.`;
|
||||
setLocation({ lat, lng, name: hit.properties.place, home: false });
|
||||
return;
|
||||
}
|
||||
setLocation({ lat: ev.lngLat.lat, lng: ((ev.lngLat.lng + 540) % 360) - 180, name: null, home: false });
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user