Merge develop

This commit is contained in:
Pieter Vander Vennet 2024-09-17 02:36:38 +02:00
commit 5a9f8f0a0a
62 changed files with 4448 additions and 710 deletions

View file

@ -1,5 +1,5 @@
import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource"
import maplibregl, { Map as MLMap, Map as MlMap, SourceSpecification } from "maplibre-gl"
import maplibregl, { Map as MLMap, Map as MlMap, ScaleControl, SourceSpecification } from "maplibre-gl"
import { RasterLayerPolygon } from "../../Models/RasterLayers"
import { Utils } from "../../Utils"
import { BBox } from "../../Logic/BBox"
@ -48,6 +48,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
readonly rotation: UIEventSource<number>
readonly pitch: UIEventSource<number>
readonly useTerrain: Store<boolean>
readonly showScale: UIEventSource<boolean>
private static pmtilesInited = false
/**
@ -93,6 +94,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
this.useTerrain = state?.useTerrain ?? new ImmutableStore<boolean>(false)
this.rasterLayer =
state?.rasterLayer ?? new UIEventSource<RasterLayerPolygon | undefined>(undefined)
this.showScale = state?.showScale ?? new UIEventSource<boolean>(false)
const lastClickLocation = new UIEventSource<{
lat: number
@ -131,6 +133,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
self.setMaxzoom(self.maxzoom.data)
self.setBounds(self.bounds.data)
self.setTerrain(self.useTerrain.data)
self.setScale(self.showScale.data)
this.updateStores(true)
})
self.MoveMapToCurrentLoc(self.location.data)
@ -144,6 +147,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
self.setBounds(self.bounds.data)
self.SetRotation(self.rotation.data)
self.setTerrain(self.useTerrain.data)
self.setScale(self.showScale.data)
this.updateStores(true)
map.on("movestart", () => {
this.isFlying.setData(true)
@ -221,6 +225,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
this.allowZooming.addCallbackAndRun((allowZooming) => self.setAllowZooming(allowZooming))
this.bounds.addCallbackAndRunD((bounds) => self.setBounds(bounds))
this.useTerrain?.addCallbackAndRun((useTerrain) => self.setTerrain(useTerrain))
this.showScale?.addCallbackAndRun(showScale => self.setScale(showScale))
}
/**
@ -703,6 +708,32 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
}
}
private scaleControl: maplibregl.ScaleControl = undefined
private setScale(showScale: boolean) {
const map = this._maplibreMap.data
if (!map) {
return
}
if (!showScale) {
if(this.scaleControl){
map.removeControl(this.scaleControl)
this.scaleControl = undefined
}
return
}
if (this.scaleControl === undefined) {
this.scaleControl = new ScaleControl({
maxWidth: 100,
unit: "metric"
})
}
if (!map.hasControl(this.scaleControl)) {
map.addControl(this.scaleControl, "bottom-right")
}
}
public flyTo(lon: number, lat: number, zoom: number) {
this.lockZoom()
window.requestAnimationFrame(() => {