dawarich/app/javascript/maps/layers.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-02-15 11:42:10 -05:00
// Import the maps configuration
2025-02-15 12:16:48 -05:00
// In non-self-hosted mode, we need to mount external maps_config.js to the container
2025-02-15 11:42:10 -05:00
import { mapsConfig } from './maps_config';
export function createMapLayer(map, selectedLayerName, layerKey) {
const config = mapsConfig[layerKey];
if (!config) {
console.warn(`No configuration found for layer: ${layerKey}`);
return null;
}
let layer = L.tileLayer(config.url, {
maxZoom: config.maxZoom,
attribution: config.attribution,
// Add any other config properties that might be needed
});
if (selectedLayerName === layerKey) {
return layer.addTo(map);
} else {
return layer;
}
}
// Helper function to create all map layers
export function createAllMapLayers(map, selectedLayerName) {
const layers = {};
Object.keys(mapsConfig).forEach(layerKey => {
layers[layerKey] = createMapLayer(map, selectedLayerName, layerKey);
});
return layers;
}
2024-09-15 15:04:13 -04:00
export function osmMapLayer(map, selectedLayerName) {
let layerName = 'OpenStreetMap';
2024-09-15 15:04:13 -04:00
let layer = L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution: "&copy; <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>",
2024-09-15 15:04:13 -04:00
});
if (selectedLayerName === layerName) {
return layer.addTo(map);
} else {
return layer;
}
}