map = {
let container = DOM.element('div', {
style: `width:${width}px; height:${width / 1.6}px`
});
yield container;
let map = L.map(container, { renderer: L.canvas() });
let osmLayer = L.tileLayer(
'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png',
{
attribution:
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}
).addTo(map);
let options = { maxIterations: 50, distance: 20, numDots: 20 };
let dots = [];
let geojsonLayer = L.geoJson(geojson, {
weight: 1,
color: '#432',
onEachFeature: (feature, layer) => {
layer.bindPopup(feature.properties.name);
layer.bindTooltip(feature.properties.name);
let bounds = layer.getBounds();
let width = Math.abs(bounds._northEast.lng - bounds._southWest.lng);
let height = Math.abs(bounds._northEast.lat - bounds._southWest.lat);
outer: for (let i = 0; i < options.maxIterations; i++) {
let p = [
bounds._southWest.lat + Math.random() * height,
bounds._southWest.lng + Math.random() * width
];
if (
pip.pointInLayer(p, L.geoJSON(layer.toGeoJSON()), true).length > 0
) {
dots.push(p);
L.circleMarker(p, { radius: 1, weight: 1, color: 'black' }).addTo(
map
);
if (dots.length == options.numDots) break;
}
}
}
}).addTo(map);
map.fitBounds(geojsonLayer.getBounds());
}