Browse Source

Fix button behaviours

master
Kenneth Bruen 3 years ago
parent
commit
ecb1875077
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 45
      src/App.svelte

45
src/App.svelte

@ -86,20 +86,35 @@
else { else {
locationCircleLayerGroup.clearLayers(); locationCircleLayerGroup.clearLayers();
} }
$: if (coords && followLocation) {
map.fitBounds( const locationFollowLogic = {
L.latLng(coords.latitude, coords.longitude).toBounds(coords.accuracy * 2), follow: false,
{ coords: void 0,
animate: true, setFollow: function(shouldFollow: boolean) {
duration: 1, if (this.follow && !shouldFollow) {
}, map.setZoom(1, {
); animate: true,
} else if (map) { duration: 5,
map.setZoom(1, { });
animate: true, }
duration: 5, this.follow = shouldFollow;
}); },
} update: function(coords: GeolocationCoordinates) {
this.coords = coords;
if (this.coords && this.follow) {
map.fitBounds(
L.latLng(this.coords.latitude, this.coords.longitude).toBounds(this.coords.accuracy * 2),
{
animate: true,
duration: 1,
},
);
}
},
};
$: locationFollowLogic.setFollow(followLocation);
$: locationFollowLogic.update(coords);
function onPosition(e: GeolocationPosition) { function onPosition(e: GeolocationPosition) {
error = void 0; error = void 0;
@ -166,7 +181,7 @@
{/if} {/if}
<div id="button-area"> <div id="button-area">
{#key geoWatchHandle} {#key geoWatchHandle}
<button on:click={onLocationButtonClick}>{geoWatchHandle ? "Stop Watching" : "Find Location"}</button> <button on:click={onLocationButtonClick}>{geoWatchHandle !== (void 0) ? "Stop Watching" : "Find Location"}</button>
{/key} {/key}
{#key followLocation} {#key followLocation}
<button on:click={toggleFollowLocation}>{followLocation ? "Stop Zooming to Location" : "Zoom to Location"}</button> <button on:click={toggleFollowLocation}>{followLocation ? "Stop Zooming to Location" : "Zoom to Location"}</button>

Loading…
Cancel
Save