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;
