17 lines
1.1 KiB
JavaScript
17 lines
1.1 KiB
JavaScript
const mapNode = document.querySelector('#event-map');
|
|
if (mapNode && window.maplibregl) {
|
|
const longitude = Number(mapNode.dataset.longitude);
|
|
const latitude = Number(mapNode.dataset.latitude);
|
|
const map = new maplibregl.Map({ container: mapNode, style: { version: 8, sources: { osm: { type: 'raster', tiles: ['https://tile.openstreetmap.org/{z}/{x}/{y}.png'], tileSize: 256, attribution: '© OpenStreetMap contributors' } }, layers: [{ id: 'osm', type: 'raster', source: 'osm' }] }, center: [longitude, latitude], zoom: 15 });
|
|
map.addControl(new maplibregl.NavigationControl(), 'top-right');
|
|
new maplibregl.Marker({ color: '#dd5b32' }).setLngLat([longitude, latitude]).setPopup(new maplibregl.Popup({ offset: 20 }).setText(mapNode.dataset.title)).addTo(map);
|
|
}
|
|
|
|
const shareButton = document.querySelector('#share-button');
|
|
if (shareButton) shareButton.addEventListener('click', async () => {
|
|
try {
|
|
if (navigator.share) await navigator.share({ title: document.title, url: location.href });
|
|
else { await navigator.clipboard.writeText(location.href); shareButton.textContent = 'Link copied'; }
|
|
} catch (_) {}
|
|
});
|