Skip to content

Commit a9ee97f

Browse files
Merge branch 'beta' (early part)
2 parents 5533e47 + 47eed50 commit a9ee97f

21 files changed

+285
-166
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"@rollup/plugin-commonjs": "25.0.7",
1414
"@rollup/plugin-json": "6.1.0",
1515
"@rollup/plugin-node-resolve": "15.2.3",
16-
"@rollup/plugin-typescript": "11.1.5",
1716
"@rollup/plugin-terser": "0.4.4",
17+
"@rollup/plugin-typescript": "11.1.5",
1818
"@tsconfig/svelte": "5.0.2",
1919
"@types/human-date": "^1.4.0",
2020
"autoprefixer": "10.4.13",

public/data/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
## `huts.json`
44

5-
curl 'https://api.doc.govt.nz/v2/huts?coordinates=wgs84' -H 'x-api-key: yNyjpuXvMJ1g2d0YEpUmW7VZhePMqbCv96GRjq8L' > huts.json
5+
curl 'https://api.doc.govt.nz/v2/huts?coordinates=wgs84' -H 'x-api-key: yNyjpuXvMJ1g2d0YEpUmW7VZhePMqbCv96GRjq8L' > huts.json
6+
7+
## `places.json`
8+
9+
curl 'https://raw.githubusercontent.com/fallaciousreasoning/nz-place-search/master/data/min_nz_places.json' > places.json

public/data/places.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<link rel="stylesheet" href="/build/extra.css" />
1313
<link rel="stylesheet" href="/build/tailwind.css" />
1414

15-
<script defer src='/build/bundle.js'></script>
15+
<script defer src='/build/main.js' type="module"></script>
1616
<script defer>
1717
if ('serviceWorker' in navigator)
1818
navigator.serviceWorker.register('/serviceWorker.js');

public/serviceWorker.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ const downloadFirstRunAssets = async () => {
2323
'/global.css',
2424
'/build/extra.css',
2525
'/build/tailwind.css',
26-
'/build/bundle.js',
26+
'/build/main.js',
2727
'/data/huts.json',
2828
'/icons/marker.svg',
29-
'/icons/location-indicator.svg'
29+
'/icons/location-indicator.svg',
30+
'https://search.topos.nz/data/min_excluded_places.json'
3031
]);
3132
};
3233

@@ -106,9 +107,6 @@ const rules = {
106107
// First party scripts should be fetched from the network, if possible.
107108
[self.registration.scope]: networkThenCache,
108109

109-
// Cache doc huts.
110-
"https://api.doc.govt.nz/v2/huts?coordinates=wgs84": cacheThenNetwork,
111-
112110
// Fetch latest mountain data, if we have a network connection.
113111
"https://raw.githubusercontent.com/fallaciousreasoning/nz-mountains/main/mountains.json": networkThenCache,
114112
}

rollup.config.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import terser from '@rollup/plugin-terser';
99
import sveltePreprocess from 'svelte-preprocess';
1010
import tailwindcss from 'tailwindcss';
1111
import { spawn } from 'child_process'
12+
import fs from 'fs/promises'
13+
import path from 'path'
1214

1315
const production = !process.env.ROLLUP_WATCH;
1416

@@ -37,9 +39,9 @@ export default {
3739
input: 'src/main.ts',
3840
output: {
3941
sourcemap: true,
40-
format: 'iife',
42+
format: 'es',
4143
name: 'app',
42-
file: 'public/build/bundle.js'
44+
dir: 'public/build'
4345
},
4446
context: 'window',
4547
plugins: [

src/TopoMap.svelte

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import fragment from './stores/fragment'
2323
import { nzBounds } from './utils/bounds'
2424
import { XYZ } from 'ol/source'
25+
import MapPin from './components/MapPin.svelte'
2526
</script>
2627

2728
<div id="topo-map">
@@ -32,26 +33,29 @@
3233
maxZoom={18}
3334
minZoom={4}
3435
extent={nzBounds}
35-
initialView={nzBounds} />
36+
initialView={nzBounds}
37+
/>
3638
<MapPositioner />
3739
<LayerGroup title="Base Layers">
3840
{#each layerDefinitions.filter((l) => l.type === 'base') as definition}
3941
<TileLayer
4042
title={definition.name}
4143
type="base"
4244
visible={false}
43-
source={cachingSource(definition)} />
45+
source={cachingSource(definition)}
46+
/>
4447
{/each}
4548
</LayerGroup>
4649
<LayerGroup title="Overlays">
4750
{#each layerDefinitions.filter((l) => l.type === 'overlay') as definition}
4851
<TileLayer
4952
title={definition.name}
5053
prerender={definition.prerender}
51-
type={"overlay"}
54+
type={'overlay'}
5255
minZoom={definition.minZoom}
5356
visible={definition.defaultVisible}
54-
source={cachingSource(definition)} />
57+
source={cachingSource(definition)}
58+
/>
5559
{/each}
5660
</LayerGroup>
5761
<LayerGroup title="Features">
@@ -64,7 +68,8 @@
6468
on:change={(e) => {
6569
const [lng, lat] = [e.detail.result.lon, e.detail.result.lat]
6670
$fragment.label = { lat, lng, text: e.detail.result.name }
67-
}} />
71+
}}
72+
/>
6873
<MapZoom />
6974
<MapLocator />
7075
<MapMeasure />
@@ -73,6 +78,7 @@
7378
<MapRotate />
7479
</Controls>
7580
<MapLabel />
81+
<MapPin />
7682
</Map>
7783
</div>
7884

src/components/MapLocator.svelte

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
11
<script lang="ts">
2-
import Geolocation from "ol/Geolocation"
3-
import type { Coordinate } from "ol/coordinate"
4-
import Icon from "ol/style/Icon"
5-
import Style from "ol/style/Style"
6-
import Feature from "../ol/Feature.svelte"
7-
import { getOlContext } from "../ol/Map.svelte"
8-
import VectorLayer from "../ol/VectorLayer.svelte"
9-
import MapControl from "./MapControl.svelte"
2+
import Geolocation from 'ol/Geolocation'
3+
import type { Coordinate } from 'ol/coordinate'
4+
import Icon from 'ol/style/Icon'
5+
import Style from 'ol/style/Style'
6+
import Feature from '../ol/Feature.svelte'
7+
import { getOlContext } from '../ol/Map.svelte'
8+
import VectorLayer from '../ol/VectorLayer.svelte'
9+
import MapControl from './MapControl.svelte'
1010
11-
const { map } = getOlContext();
11+
const { map } = getOlContext()
1212
13-
let tracking = false;
14-
let position: Coordinate;
13+
let tracking = false
14+
let position: Coordinate
1515
1616
let geolocation = new Geolocation({
1717
projection: map.getView().getProjection(),
1818
trackingOptions: {
19-
enableHighAccuracy: true
20-
}
21-
});
22-
geolocation.on("change", (e) => {
23-
position = geolocation.getPosition();
24-
});
19+
enableHighAccuracy: true,
20+
},
21+
})
22+
geolocation.on('change', (e) => {
23+
const locatedPos = geolocation.getPosition()
24+
if (!locatedPos) return
25+
position = locatedPos
26+
})
2527
2628
$: {
2729
if (tracking) {
28-
geolocation.once("change", () =>
29-
map.getView().setCenter(geolocation.getPosition())
30-
);
30+
geolocation.once('change', () =>
31+
map.getView().setCenter(geolocation.getPosition()),
32+
)
3133
}
3234
33-
geolocation.setTracking(tracking);
35+
geolocation.setTracking(tracking)
3436
}
3537
</script>
3638

3739
<MapControl>
3840
<button
39-
on:click={() => tracking = !tracking}
40-
class={`map-button ${tracking && 'hover:bg-primary-hover hover:text-background'}`}>
41+
on:click={() => (tracking = !tracking)}
42+
class={`map-button ${
43+
tracking && 'hover:bg-primary-hover hover:text-background'
44+
}`}
45+
>
4146
4247
</button>
4348
</MapControl>
@@ -50,11 +55,12 @@
5055
image: new Icon({
5156
anchor: [0.5, 0.5],
5257
opacity: 0.9,
53-
imgSize: [600, 600],
58+
size: [600, 600],
5459
scale: 0.08,
5560
color: '#578dfF',
5661
src: '/icons/location-indicator.svg',
5762
}),
58-
})} />
63+
})}
64+
/>
5965
{/if}
6066
</VectorLayer>

src/components/MapPin.svelte

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts">
2+
import { toLonLat } from 'ol/proj'
3+
import { getOlContext } from '../ol/Map.svelte'
4+
import fragment from '../stores/fragment'
5+
import { findPlace } from '../search/nearest'
6+
import round from '../utils/round'
7+
8+
const { map } = getOlContext()
9+
10+
map.on('click', async (e) => {
11+
const [lng, lat] = toLonLat(e.coordinate)
12+
const closestPoint = await findPlace(lat, lng)
13+
$fragment.label = {
14+
lat: closestPoint?.lat ?? lat,
15+
lng: closestPoint?.lon ?? lng,
16+
text: closestPoint?.name ?? `Lat/Lon: ${round(lat, 5)},${round(lng, 5)}`,
17+
}
18+
})
19+
</script>

0 commit comments

Comments
 (0)