mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-01 08:12:32 +00:00
adapt scale control units
This commit is contained in:
@@ -7,18 +7,21 @@
|
|||||||
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
|
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
|
||||||
import '@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.css';
|
import '@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.css';
|
||||||
|
|
||||||
import { map } from '$lib/stores';
|
import { map, settings } from '$lib/stores';
|
||||||
|
|
||||||
mapboxgl.accessToken =
|
mapboxgl.accessToken =
|
||||||
'pk.eyJ1IjoiZ3B4c3R1ZGlvIiwiYSI6ImNrdHVoM2pjNTBodmUycG1yZTNwcnJ3MzkifQ.YZnNs9s9oCQPzoXAWs_SLg';
|
'pk.eyJ1IjoiZ3B4c3R1ZGlvIiwiYSI6ImNrdHVoM2pjNTBodmUycG1yZTNwcnJ3MzkifQ.YZnNs9s9oCQPzoXAWs_SLg';
|
||||||
|
|
||||||
export let distanceUnits: 'metric' | 'imperial' = 'metric';
|
|
||||||
let fitBoundsOptions: mapboxgl.FitBoundsOptions = {
|
let fitBoundsOptions: mapboxgl.FitBoundsOptions = {
|
||||||
maxZoom: 15,
|
maxZoom: 15,
|
||||||
linear: true,
|
linear: true,
|
||||||
easing: () => 1
|
easing: () => 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let scaleControl = new mapboxgl.ScaleControl({
|
||||||
|
unit: $settings.distanceUnits
|
||||||
|
});
|
||||||
|
|
||||||
function toggleTerrain() {
|
function toggleTerrain() {
|
||||||
if ($map) {
|
if ($map) {
|
||||||
if ($map.getPitch() > 0) {
|
if ($map.getPitch() > 0) {
|
||||||
@@ -85,15 +88,15 @@
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
$map.addControl(
|
$map.addControl(scaleControl);
|
||||||
new mapboxgl.ScaleControl({
|
|
||||||
unit: distanceUnits
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
$map.on('style.load', toggleTerrain);
|
$map.on('style.load', toggleTerrain);
|
||||||
$map.on('pitchstart', toggleTerrain);
|
$map.on('pitchstart', toggleTerrain);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$: if ($map) {
|
||||||
|
scaleControl.setUnit($settings.distanceUnits);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div {...$$restProps}>
|
<div {...$$restProps}>
|
||||||
|
Reference in New Issue
Block a user