mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:07:08 +00:00
Add server-side map rendering component.
Based on our own fork of leaflet-headless.
This commit is contained in:
22
lib/www/server/lib/map/index.js
Normal file
22
lib/www/server/lib/map/index.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const L = require('leaflet-headless');
|
||||
|
||||
function leafletMap (cfg) {
|
||||
|
||||
const container = document.createElement("div");
|
||||
container.style.setProperty("background-color", "transparent");
|
||||
let map = L.map(container);
|
||||
|
||||
const bbox = cfg.bbox || L.geoJSON(cfg.layers.map(i => i.features)).getBounds();
|
||||
map.fitBounds(bbox);
|
||||
map.setSize(cfg.size?.width || 500, cfg.size?.height || 500);
|
||||
|
||||
for (let layer of cfg.layers) {
|
||||
L.geoJSON(layer.features, layer.options).addTo(map);
|
||||
}
|
||||
|
||||
map.fitBounds(bbox); // again
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
module.exports = leafletMap;
|
||||
2458
lib/www/server/package-lock.json
generated
2458
lib/www/server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@
|
||||
"express": "^4.17.1",
|
||||
"express-jwt": "^6.0.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"leaflet-headless": "gitlab:aaltronav/contrib/leaflet-headless#devel",
|
||||
"marked": "^2.0.3",
|
||||
"netmask": "^1.0.6",
|
||||
"node-fetch": "^2.6.1",
|
||||
|
||||
Reference in New Issue
Block a user