Skip to content

Commit 11689c5

Browse files
Include mountains
1 parent 2fc7514 commit 11689c5

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/layers/mountains.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Feature from 'ol/Feature';
22
import Point from 'ol/geom/Point';
33
import { fromLonLat } from 'ol/proj';
4-
import { Style, Circle, Stroke, Fill, Text } from 'ol/style';
4+
import { Circle, Fill, Stroke, Style, Text } from 'ol/style';
55

66
import fragment from '../stores/fragment';
7-
import mountains, { Mountain, Mountains } from '../stores/mountains';
7+
import mountains, { type Mountains } from '../stores/mountains';
88

99
const styleCache = {};
1010

@@ -34,13 +34,16 @@ export default {
3434
}
3535
return styleCache[size];
3636
},
37-
getFeatures: async () => {
37+
getData: async () => {
3838
const url = "https://raw.githubusercontent.com/fallaciousreasoning/nz-mountains/main/mountains.json"
3939
const response = await fetch(url);
4040
const result = await response.json() as Mountains;
4141
mountains.set(result);
42-
43-
const points = Object.values(result).filter(a => a.latlng);
42+
return result
43+
},
44+
async getFeatures() {
45+
const data = await this.getData();
46+
const points = Object.values(data).filter(a => a.latlng);
4447
return points.map(mountain => {
4548
const coords = fromLonLat([mountain.latlng[1], mountain.latlng[0]]);
4649
const feature = new Feature(new Point(coords));

src/search/places.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import huts from '../layers/huts'
2+
import mountains from '../layers/mountains';
23

34
const placesUrl = '/data/places.json'
45

@@ -18,8 +19,12 @@ const makePlacesPromise = async (sources: (() => Promise<Place[]>)[]) => {
1819
export const getPlaces = () => {
1920
if (!placesPromise) {
2021
placesPromise = makePlacesPromise([
22+
huts.getData,
23+
() => mountains.getData()
24+
.then(r => Object.entries(r)
25+
.filter(([,m]) => m.latlng?.length && m.name)
26+
.map(([url, m]) => ({ name: m.name, lat: m.latlng[0], lon: m.latlng[1], type: 'peak', href: url }))),
2127
() => fetch(placesUrl).then(r => r.json() as Promise<Place[]>),
22-
huts.getData
2328
])
2429
}
2530
return placesPromise

0 commit comments

Comments
 (0)