Chore: small linting issues and formatting

This commit is contained in:
Pieter Vander Vennet 2025-02-22 23:42:06 +01:00
parent b606fa57a8
commit 6a9677fc78
4 changed files with 16 additions and 31 deletions

View file

@ -68,8 +68,7 @@
"type": "fill", "type": "fill",
"source": "protomaps", "source": "protomaps",
"source-layer": "landuse", "source-layer": "landuse",
"filter": [ "filter":
"any",
[ [
"in", "in",
"kind", "kind",
@ -78,7 +77,6 @@
"cemetery", "cemetery",
"nature_reserve", "nature_reserve",
"golf_course" "golf_course"
]
], ],
"paint": { "paint": {
"fill-color": [ "fill-color": [

View file

@ -1,17 +1,11 @@
import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource" import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource"
import maplibregl, { import maplibregl, { Map as MLMap, Map as MlMap, ScaleControl } from "maplibre-gl"
Map as MLMap,
Map as MlMap,
ScaleControl,
SourceSpecification,
} from "maplibre-gl"
import { RasterLayerPolygon } from "../../Models/RasterLayers" import { RasterLayerPolygon } from "../../Models/RasterLayers"
import { Utils } from "../../Utils" import { Utils } from "../../Utils"
import { BBox } from "../../Logic/BBox" import { BBox } from "../../Logic/BBox"
import { ExportableMap, KeyNavigationEvent, MapProperties } from "../../Models/MapProperties" import { ExportableMap, KeyNavigationEvent, MapProperties } from "../../Models/MapProperties"
import SvelteUIElement from "../Base/SvelteUIElement" import SvelteUIElement from "../Base/SvelteUIElement"
import MaplibreMap from "./MaplibreMap.svelte" import MaplibreMap from "./MaplibreMap.svelte"
import { RasterLayerProperties } from "../../Models/RasterLayerProperties"
import * as htmltoimage from "html-to-image" import * as htmltoimage from "html-to-image"
import RasterLayerHandler from "./RasterLayerHandler" import RasterLayerHandler from "./RasterLayerHandler"
import Constants from "../../Models/Constants" import Constants from "../../Models/Constants"
@ -125,7 +119,6 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
nearestFeature?: Feature nearestFeature?: Feature
}>(undefined) }>(undefined)
this.lastClickLocation = lastClickLocation this.lastClickLocation = lastClickLocation
const self = this
new RasterLayerHandler(this._maplibreMap, this.rasterLayer) new RasterLayerHandler(this._maplibreMap, this.rasterLayer)
@ -294,10 +287,6 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
} }
} }
public static prepareWmsSource(layer: RasterLayerProperties): SourceSpecification {
return RasterLayerHandler.prepareSource(layer)
}
/** /**
* Prepares an ELI-URL to be compatible with mapbox * Prepares an ELI-URL to be compatible with mapbox
*/ */

View file

@ -1,4 +1,4 @@
import { Map as MLMap, RasterSourceSpecification, VectorTileSource } from "maplibre-gl" import { Map as MLMap, RasterSourceSpecification } from "maplibre-gl"
import { Store, Stores, UIEventSource } from "../../Logic/UIEventSource" import { Store, Stores, UIEventSource } from "../../Logic/UIEventSource"
import { RasterLayerPolygon } from "../../Models/RasterLayers" import { RasterLayerPolygon } from "../../Models/RasterLayers"
import { RasterLayerProperties } from "../../Models/RasterLayerProperties" import { RasterLayerProperties } from "../../Models/RasterLayerProperties"
@ -144,8 +144,8 @@ class SingleBackgroundHandler {
type: "raster", type: "raster",
source: background.id, source: background.id,
paint: { paint: {
"raster-opacity": 0, "raster-opacity": 0
}, }
}, },
addLayerBeforeId addLayerBeforeId
) )
@ -166,14 +166,14 @@ class SingleBackgroundHandler {
Stores.Chronic( Stores.Chronic(
8, 8,
() => this.opacity.data > 0 && this._deactivationTime !== undefined () => this.opacity.data > 0 && this._deactivationTime !== undefined
).addCallback((_) => this.opacity.setData(Math.max(0, this.opacity.data - this.fadeStep))) ).addCallback(() => this.opacity.setData(Math.max(0, this.opacity.data - this.fadeStep)))
} }
private fadeIn() { private fadeIn() {
Stores.Chronic( Stores.Chronic(
8, 8,
() => this.opacity.data < 1.0 && this._deactivationTime === undefined () => this.opacity.data < 1.0 && this._deactivationTime === undefined
).addCallback((_) => this.opacity.setData(Math.min(1.0, this.opacity.data + this.fadeStep))) ).addCallback(() => this.opacity.setData(Math.min(1.0, this.opacity.data + this.fadeStep)))
} }
} }
@ -193,11 +193,10 @@ export default class RasterLayerHandler {
layer: RasterLayerProperties layer: RasterLayerProperties
): RasterSourceSpecification | VectorSourceSpecification { ): RasterSourceSpecification | VectorSourceSpecification {
if (layer.type === "vector") { if (layer.type === "vector") {
const vs: VectorSourceSpecification = { return {
type: "vector", type: "vector",
url: layer.url, url: layer.url
} }
return vs
} }
return { return {
type: "raster", type: "raster",
@ -208,7 +207,7 @@ export default class RasterLayerHandler {
minzoom: layer["min_zoom"] ?? 1, minzoom: layer["min_zoom"] ?? 1,
maxzoom: layer["max_zoom"] ?? 25, maxzoom: layer["max_zoom"] ?? 25,
// Bit of a hack, but seems to work // Bit of a hack, but seems to work
scheme: layer.url.includes("{-y}") ? "tms" : "xyz", scheme: layer.url.includes("{-y}") ? "tms" : "xyz"
} }
} }
@ -222,7 +221,7 @@ export default class RasterLayerHandler {
"{width}": "" + size, "{width}": "" + size,
"{height}": "" + size, "{height}": "" + size,
"{zoom}": "{z}", "{zoom}": "{z}",
"{-y}": "{y}", "{-y}": "{y}"
} }
for (const key in toReplace) { for (const key in toReplace) {

View file

@ -1,8 +1,8 @@
import { Store, UIEventSource } from "../../Logic/UIEventSource" import { Store, UIEventSource } from "../../Logic/UIEventSource"
import { Map as MlMap } from "maplibre-gl" import { Map as MlMap } from "maplibre-gl"
import { Utils } from "../../Utils" import { Utils } from "../../Utils"
import { MapLibreAdaptor } from "./MapLibreAdaptor"
import { RasterLayerProperties } from "../../Models/RasterLayerProperties" import { RasterLayerProperties } from "../../Models/RasterLayerProperties"
import RasterLayerHandler from "./RasterLayerHandler"
export default class ShowOverlayRasterLayer { export default class ShowOverlayRasterLayer {
private readonly _map: UIEventSource<MlMap> private readonly _map: UIEventSource<MlMap>
@ -42,9 +42,9 @@ export default class ShowOverlayRasterLayer {
} }
private setVisibility() { private setVisibility() {
let zoom = this._mapProperties?.zoom?.data const zoom = this._mapProperties?.zoom?.data
let withinRange = zoom === undefined || zoom > this._layer.min_zoom const withinRange = zoom === undefined || zoom > this._layer.min_zoom
let isDisplayed = (this._isDisplayed?.data ?? true) && withinRange const isDisplayed = (this._isDisplayed?.data ?? true) && withinRange
try { try {
this._map.data?.setLayoutProperty( this._map.data?.setLayoutProperty(
this._layer.id, this._layer.id,
@ -78,8 +78,7 @@ export default class ShowOverlayRasterLayer {
return return
} }
const background: RasterLayerProperties = this._layer const background: RasterLayerProperties = this._layer
map.addSource(background.id, RasterLayerHandler.prepareSource(background))
map.addSource(background.id, MapLibreAdaptor.prepareWmsSource(background))
this._mllayer = map.addLayer({ this._mllayer = map.addLayer({
id: background.id, id: background.id,
type: "raster", type: "raster",