Skip to content

Commit

Permalink
Merge pull request #379 from kernvalley/patch/update
Browse files Browse the repository at this point in the history
Update `<leaflet-map>`
  • Loading branch information
shgysk8zer0 authored Jan 3, 2025
2 parents fc092c0 + 35a517b commit 872fc01
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 80 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v3.0.5] - 2025-01-03

### Changed
- Update to have `<leaflet-map>` handle `geo:` URIs and geohashes

### [v3.0.4] - 2025-01-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion _data/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Kern Valley Maps
shortName: KRV Maps
id: KRVMaps
startUrl: /?utm_source=pwa&utm_medium=pwa
version: 3.0.4
version: 3.0.5
lang: en
dir: ltr
display: standalone
Expand Down
2 changes: 1 addition & 1 deletion _data/importmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@aegisjsproject/aegis-md/": "https://unpkg.com/@aegisjsproject/[email protected]/",
"@aegisjsproject/url": "https://unpkg.com/@aegisjsproject/[email protected]/url.mjs",
"@aegisjsproject/url/": "https://unpkg.com/@aegisjsproject/[email protected]/",
"@shgysk8zer0/components/": "https://unpkg.com/@shgysk8zer0/[email protected].14/",
"@shgysk8zer0/components/": "https://unpkg.com/@shgysk8zer0/[email protected].15/",
"@aegisjsproject/state": "https://unpkg.com/@aegisjsproject/[email protected]/state.mjs",
"@aegisjsproject/state/": "https://unpkg.com/@aegisjsproject/[email protected]/",
"@aegisjsproject/router": "https://unpkg.com/@aegisjsproject/[email protected]/router.mjs",
Expand Down
4 changes: 2 additions & 2 deletions _data/scripts/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
type: module
defer: true
referrerPolicy: no-referrer
- src: https://unpkg.com/@shgysk8zer0/[email protected].14/leaflet/bundle.min.js
- src: https://unpkg.com/@shgysk8zer0/[email protected].15/leaflet/bundle.min.js
referrerPolicy: no-referrer
crossOrigin: anonymous
integrity: sha384-Wcpoq8RX6zqLoy6E7Q8R972SBG4HBN0E2aJqF1QooAHRk+1Mf3ZiMsPYYZP1/hvK
integrity: sha384-WUuJCItQM/sZRdTS+c7zbGzU70OOUCssPIU4RchSbaxr9joY5B+6eqIIyXhWH8vD
defer: true
4 changes: 2 additions & 2 deletions _data/scripts/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
- src: /js/index.min.js
referrerPolicy: no-referrer
defer: true
- src: https://unpkg.com/@shgysk8zer0/[email protected].14/leaflet/bundle.min.js
- src: https://unpkg.com/@shgysk8zer0/[email protected].15/leaflet/bundle.min.js
referrerPolicy: no-referrer
crossOrigin: anonymous
integrity: sha384-Wcpoq8RX6zqLoy6E7Q8R972SBG4HBN0E2aJqF1QooAHRk+1Mf3ZiMsPYYZP1/hvK
integrity: sha384-WUuJCItQM/sZRdTS+c7zbGzU70OOUCssPIU4RchSbaxr9joY5B+6eqIIyXhWH8vD
defer: true
2 changes: 1 addition & 1 deletion embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script type="application/javascript" defer="" referrerpolicy="no-referrer" crossorigin="anonymous" integrity="sha384-S6IiMVrhK2h8SpNcu3w1ybvXAcAPLcN6DC8dy35bqDEcqIt4wP5zBGTYd96qtGRi" src="https://unpkg.com/@shgysk8zer0/[email protected]/browser.min.js"></script>
<script type="application/javascript" defer="" referrerpolicy="no-referrer" crossorigin="anonymous" integrity="sha384-55L/wO9o0uIVTeubRIDQB4bewfNqyxrj4OXuxlW24NMEk+ioZwMHVw/tFV78mM+k" src="https://unpkg.com/@shgysk8zer0/[email protected]/harden.js"></script>
<script src="/js/embed.js" referrerpolicy="no-referrer" defer=""></script>
<script type="application/javascript" defer="" referrerpolicy="no-referrer" crossorigin="anonymous" integrity="sha384-Wcpoq8RX6zqLoy6E7Q8R972SBG4HBN0E2aJqF1QooAHRk+1Mf3ZiMsPYYZP1/hvK" src="https://unpkg.com/@shgysk8zer0/[email protected].14/leaflet/bundle.min.js"></script>
<script type="application/javascript" defer="" referrerpolicy="no-referrer" crossorigin="anonymous" integrity="sha384-WUuJCItQM/sZRdTS+c7zbGzU70OOUCssPIU4RchSbaxr9joY5B+6eqIIyXhWH8vD" src="https://unpkg.com/@shgysk8zer0/[email protected].15/leaflet/bundle.min.js"></script>
<link rel="stylesheet" href="/css/embed.css" referrerpolicy="no-referrer" media="all" />
</head>
<body></body>
Expand Down
4 changes: 4 additions & 0 deletions js/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ Promise.all([
map.loadMarkers(...types).catch(console.error),
]);
}
} else if (params.has('geo')) {
map.geo = params.get('geo');
} else if (params.has('geohash')) {
map.geohash = params.get('geohash');
}

if (location.hash.length > 1) {
Expand Down
76 changes: 17 additions & 59 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { getCustomElement } from '@shgysk8zer0/kazoo/custom-elements.js';
import { getGooglePolicy, getDefaultPolicy } from '@shgysk8zer0/kazoo/trust-policies.js';
import { ready, loaded, toggleClass, on, attr } from '@shgysk8zer0/kazoo/dom.js';
import { importGa, externalHandler, mailtoHandler, telHandler } from '@shgysk8zer0/kazoo/google-analytics.js';
import { decodeGeohash, parseGeoURI } from 'https://unpkg.com/@shgysk8zer0/[email protected]/geoutils.js';
import { consumeHandler } from './functions.js';
import { addEventsToMap } from './events.js';
import { GA } from './consts.js';
Expand Down Expand Up @@ -56,67 +55,26 @@ try {
}

if (location.search.includes('geo')) {
const params = new URLSearchParams(location.search);

if (params.has('geo')) {
try {
const {
coords: { latitude = NaN, longitude = NaN } = {},
params: { zoom = 16, query = 'Marked Location' } = {},
} = parseGeoURI(params.get('geo'));

if (! (Number.isNaN(latitude) || Number.isNaN(longitude))) {
Promise.all([
customElements.whenDefined('leaflet-marker'),
customElements.whenDefined('leaflet-map'),
]).then(([LeafletMarker]) => {
const popup = document.createElement('div');
const label = document.createElement('b');
const coords = document.createElement('pre');
const map = document.querySelector('leaflet-map');
const url = new URL(location.pathname, location.origin);

label.textContent = query;
coords.textContent = `${latitude.toFixed(5)}, ${longitude.toFixed(5)}`;
popup.append(label, document.createElement('br'), coords);
const marker = new LeafletMarker({ latitude, longitude, popup, open: false });
marker.id = 'marked-geo-location';
map.append(marker);
map.zoom = zoom;
marker.open = true;
url.hash = `#${latitude},${longitude},${zoom}`;
history.replaceState(history.state, '', url.href);
});
}
} catch(err) {
console.error(err);
}
} else if (params.has('geohash')) {
try {
const { latitude = NaN, longitude = NaN } = decodeGeohash(params.get('geohash'));

if (! (Number.isNaN(latitude) || Number.isNaN(longitude))) {
const url = new URL(location.pathname, location.origin);
url.hash = `#${latitude},${longitude}`;
history.replaceState(history.state, '', url.href);
}
} catch(err) {
console.error(err);
customElements.whenDefined('leaflet-map').then(() => {
const params = new URLSearchParams(location.search);
const map = document.getElementById('map');
const url = new URL(location.href);

if (params.has('geo')) {
map.geo = params.get('geo');
url.searchParams.delete('geo');
history.replaceState(history.state, '', url.href);
} else if (params.has('geohash')) {
map.geohash = params.get('geohash');
url.searchParams.delete('geohash');
history.replaceState(history.state, '', url.href);
}
}
});
//0123456789bcdefghjkmnpqrstuvwxyz 32-bit alphabet
} else if (location.hash.length > 2 && /^#[0-9b-hjk-np-z]{2,12}$/.test(location.hash)) {
try {
const { latitude = NaN, longitude = NaN } = decodeGeohash(location.hash.substring(1));

if (! (Number.isNaN(latitude) || Number.isNaN(longitude))) {
const url = new URL(location.pathname, location.origin);
url.hash = `#${latitude},${longitude}`;
history.replaceState(history.state, '', url.href);
}
} catch(err) {
console.error(err);
}
customElements.whenDefined('leaflet-map').then(() => {
document.getElementById('map').geohash = location.hash.substring(1);
});
}

ready().then(async () => {
Expand Down
37 changes: 26 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maps.kernvalley.us",
"version": "3.0.4",
"version": "3.0.5",
"private": true,
"type": "module",
"description": "Maps for the Kern River Valley",
Expand Down Expand Up @@ -81,7 +81,7 @@
"netlify-js-app": "^3.3.2"
},
"devDependencies": {
"@shgysk8zer0/importmap": "^1.4.37",
"@shgysk8zer0/importmap": "^1.4.38",
"@shgysk8zer0/rollup-import": "^1.2.5",
"@shgysk8zer0/svg-use-symbols": "^1.1.3"
}
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { importmap } from '@shgysk8zer0/importmap';
export default getConfig('./js/index.js', {
plugins: [
rollupImport(importmap),
rollupImportMeta({ baseURL: 'https://www.paradisecovelodge.com/' }),
rollupImportMeta({ baseURL: 'https://maps.kernvalley.us/' }),
],
format: 'iife',
minify: true,
Expand Down

0 comments on commit 872fc01

Please sign in to comment.