refactor(views/geo): remove dependency to leaflet in map layer

This commit is contained in:
Elian Doran 2025-07-24 15:35:03 +03:00
parent bea40d4c2f
commit 180841f364
No known key found for this signature in database
2 changed files with 19 additions and 20 deletions

View File

@ -10,8 +10,8 @@ import toast from "../../../services/toast.js";
import { CommandListenerData, EventData } from "../../../components/app_context.js"; import { CommandListenerData, EventData } from "../../../components/app_context.js";
import { createNewNote, moveMarker, setupDragging } from "./editing.js"; import { createNewNote, moveMarker, setupDragging } from "./editing.js";
import { openMapContextMenu } from "./context_menu.js"; import { openMapContextMenu } from "./context_menu.js";
import getMapLayer from "./map_layer.js";
import attributes from "../../../services/attributes.js"; import attributes from "../../../services/attributes.js";
import { MAP_LAYERS } from "./map_layer.js";
const TPL = /*html*/` const TPL = /*html*/`
<div class="geo-view"> <div class="geo-view">
@ -337,3 +337,21 @@ export default class GeoView extends ViewMode<MapData> {
} }
} }
async function getMapLayer(layerName: string) {
const layer = MAP_LAYERS[layerName] ?? MAP_LAYERS["openstreetmap"];
if (layer.type === "vector") {
const style = (typeof layer.style === "string" ? layer.style : await layer.style());
await import("@maplibre/maplibre-gl-leaflet");
return L.maplibreGL({
style: style as any
});
}
return L.tileLayer(layer.url, {
attribution: layer.attribution,
detectRetina: true
});
}

View File

@ -1,5 +1,3 @@
import L from "leaflet";
interface Layer { interface Layer {
name: string; name: string;
} }
@ -54,20 +52,3 @@ export const MAP_LAYERS: Record<string, VectorLayer | RasterLayer> = {
} }
}; };
export default async function getMapLayer(layerName: string) {
const layer = MAP_LAYERS[layerName] ?? MAP_LAYERS["openstreetmap"];
if (layer.type === "vector") {
const style = (typeof layer.style === "string" ? layer.style : await layer.style());
await import("@maplibre/maplibre-gl-leaflet");
return L.maplibreGL({
style: style as any
});
}
return L.tileLayer(layer.url, {
attribution: layer.attribution,
detectRetina: true
});
}