Skip to content

Commit 2fc7514

Browse files
Include huts in places
1 parent f8009c6 commit 2fc7514

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

src/components/MapSearch.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script lang="ts">
2-
import geocode from '../search/geocode'
3-
import { createEventDispatcher, tick } from 'svelte'
2+
import { createEventDispatcher } from 'svelte'
43
import { getOlContext } from '../ol/Map.svelte'
5-
import MapControl from './MapControl.svelte'
6-
import grow from '../transitions/grow'
4+
import geocode from '../search/geocode'
75
import type { Place } from '../search/places'
6+
import grow from '../transitions/grow'
7+
import MapControl from './MapControl.svelte'
88
99
const dispatcher = createEventDispatcher()
1010
const { map } = getOlContext()

src/layers/FeatureLayers.svelte

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<script lang="ts">
2+
import ClusterLayer from '../ol/ClusterLayer.svelte'
23
import { getOlContext } from '../ol/Map.svelte'
3-
import { onMount, tick } from 'svelte'
44
import { enableZoomToCluster } from '../utils/zoomToFeature'
5-
import ClusterLayer from '../ol/ClusterLayer.svelte'
6-
import huts from './huts'
7-
import liveWeather from './LiveWeather.svelte'
8-
import VectorLayer from '../ol/VectorLayer.svelte'
9-
import VectorSource from 'ol/source/Vector'
10-
import onMountTick from '../utils/onMountTick'
115
import LiveWeather from './LiveWeather.svelte'
6+
import huts from './huts'
127
import mountains from './mountains'
138
149
const { map } = getOlContext()

src/layers/huts.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Feature from 'ol/Feature';
22
import Point from 'ol/geom/Point';
33
import { fromLonLat } from 'ol/proj';
4-
import GeoJSON from 'ol/format/GeoJSON';
5-
import { Style, Circle, Stroke, Fill, Text } from 'ol/style';
4+
import { Circle, Fill, Stroke, Style, Text } from 'ol/style';
5+
import type { Place } from '../search/places';
66
import fragment from '../stores/fragment';
77

88
const styleCache = {};
@@ -33,10 +33,17 @@ export default {
3333
}
3434
return styleCache[size];
3535
},
36-
getFeatures: async () => {
36+
getData: async () => {
3737
const url = "/data/huts.json"
3838
const response = await fetch(url);
3939
const data = await response.json() as any[];
40+
for (const hut of data) {
41+
hut.place = 'hut'
42+
}
43+
return data as Place[]
44+
},
45+
async getFeatures() {
46+
const data = await this.getData()
4047
return data.map(hut => {
4148
const coords = fromLonLat([hut.lon, hut.lat]);
4249
const feature = new Feature(new Point(coords));

src/search/places.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const url = '/data/places.json'
1+
import huts from '../layers/huts'
2+
3+
const placesUrl = '/data/places.json'
24

35
export interface Place {
46
name: string,
@@ -9,9 +11,16 @@ export interface Place {
911

1012
let placesPromise: Promise<Place[]>;
1113

14+
const makePlacesPromise = async (sources: (() => Promise<Place[]>)[]) => {
15+
return Promise.all(sources.map(s => s())).then(r => r.flat())
16+
}
17+
1218
export const getPlaces = () => {
1319
if (!placesPromise) {
14-
placesPromise = fetch(url).then(r => r.json())
20+
placesPromise = makePlacesPromise([
21+
() => fetch(placesUrl).then(r => r.json() as Promise<Place[]>),
22+
huts.getData
23+
])
1524
}
1625
return placesPromise
1726
}

0 commit comments

Comments
 (0)