Skip to content

Commit 47eed50

Browse files
Compile error
1 parent 32eba69 commit 47eed50

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

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>

0 commit comments

Comments
 (0)