概要
leafletを鍛えてみた。
turf.jsでvoronoiやってみた。
写真
サンプルコード
var options = {
bbox: [139, 37, 141, 39]
};
var points = turf.randomPoint(100, options);
var voronoiPolygons = turf.voronoi(points, options);
var map = L.map('map').setView([38.0, 140.0], 7);
var mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© ' + mapLink + ' Contributors',
maxZoom: 18,
}).addTo(map);
out.value = JSON.stringify(voronoiPolygons);
L.geoJson(voronoiPolygons, {
pointToLayer: function(feature, latlng) {
var c = "#f60";
if (feature.properties.rain > 0)
{
c ="#06f";
}
return new L.CircleMarker(latlng, {
radius: 10,
color: "#000",
weight: 1,
fillColor: c,
fillOpacity: 0.75
});
}
}).addTo(map);
var pointStyle = {
pointToLayer: function(feature, latlng) {
return L.circle(latlng);
},
style: {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
}
}
L.geoJson(points, pointStyle).addTo(map);
成果物
以上。