//minX, minY, maxX, maxY
let layerWEST = layer.getBounds().getWest();
let layerEAST = layer.getBounds().getEast();
let layerNORTH = layer.getBounds().getNorth();
let layerSOUTH = layer.getBounds().getSouth();

let WEST = map.getBounds().getWest();
let EAST = map.getBounds().getEast();
let NORTH = map.getBounds().getNorth();
let SOUTH = map.getBounds().getSouth();

 swal({
 title: "!!!!",
 text: "Confirm",
 icon: "info",
 buttons: ["Use current Map bounds", "Use layer extension bounds"],
 dangerMode: true
 }).then(function(isConfirm) {
 if (isConfirm) {

 boundoptions = {
 bbox: [layerWEST, layerSOUTH, layerEAST, layerNORTH]
 };

 } else {

 boundoptions = {
 bbox: [WEST, SOUTH, EAST, NORTH]
 };

 }

try {
voronoifeatures = turf.featureCollection(voronoigeojsoned.features, boundoptions);
voronoiPolygons = turf.voronoi(voronoifeatures, boundoptions);
} 
catch (error) {
console.log(error);

if (error.toString().indexOf('must be a Point')) {
//if the geometry consists of polygons we create centroid points from those geometries. 
swal("This layer does not consist of Points. The non points were converted to centroid points");
let centroids = {
type: 'FeatureCollection',
features: voronoigeojsoned.features.map(function(feature) {
return {
type: 'Feature',
properties: feature.properties,
geometry: turf.centroid(feature).geometry}})};
console.log("centroids",centroids);
voronoigeojsoned = centroids;
voronoifeatures = turf.featureCollection(centroids.features, boundoptions);
voronoiPolygons = turf.voronoi(voronoifeatures, boundoptions);
} // if (error.toString().indexOf('must be a Point')) { }finally{

voronoifeaturegroup.clearLayers();
voronoipointLayer.clearLayers();
voronoipointTempLayer = new L.geoJSON(voronoigeojsoned.features);

//we check the length of geometry objects returned and accordingly 
//we prompt the user.
if(Object.keys(voronoiPolygons.features).length > 4000)
{
swal("!!You just run the voronoi function in a vast area.Please run the function for a confined area.(zoom in the specific area you want to analyse and choose the option - Current map bounds - )");
hideSpinner();
destroyanalysis();
return;
}

//console.log("voronoifeatures.length", Object.keys(voronoiPolygons.features).length);
try {
turf.featureEach(voronoiPolygons, function(currentFeature, featureIndex) {
//console.log("featureIndex.length",featureIndex);
if (currentFeature && currentFeature.geometry && currentFeature.geometry.type === "Polygon") {
//we flip the coordinates in the geometry.
let flipped = turf.flip(currentFeature);
let polygon = L.polygon(flipped.geometry.coordinates, {
weight: 4, fillOpacity: 0.07,
color: 'black',
dashArray: '1',
fillColor: '#0000FF',
pane: "topoPane"
}).addTo(voronoifeaturegroup);
}
});
} catch (error) {
console.log(error)
hideSpinner();
swal("An error occured");
}
Shortest distance on line network
The code is inspired from the main demo of the geojson path finder plugin but here is altered accordingly to fit this specific instance.
//Based on https://www.liedman.net/geojson-path-finder/

router = new rooter(network); //console.log("router", router);controlpoint1 = [router.\_points.features[0].geometry.coordinates[1], router.\_points.features[0].geometry.coordinates[0]];
controlpoint2 = [router.\_points.features[1].geometry.coordinates[1], router.\_points.features[1].geometry.coordinates[0]];
routingcontrol = L.Routing.control({
createMarker: function(i, wp) {
return L.marker(wp.latLng, {
icon: L.icon.glyph({
prefix: '',
glyph: String.fromCharCode(65 + i)
}),
draggable: true
})
},
router: router,
routeWhileDragging: true,
routeDragInterval: 100
}).addTo(map);
routingcontrol.setWaypoints([
controlpoint1,
controlpoint2,
]);
try {
totalDistance = network.features.reduce(function(total, feature) {
if (feature.geometry.type === 'LineString') {
return total += lineDistance(feature, 'kilometers');
} else {
return total;
}
}, 0);
/minX, minY, maxX, maxYlet layerWEST = layer.getBounds().getWest();let layerEAST = layer.getBounds().getEast();let layerNORTH = layer.getBounds().getNorth();let layerSOUTH = layer.getBounds().getSouth();let WEST = map.getBounds().getWest();let EAST = map.getBounds().getEast();let NORTH = map.getBounds().getNorth();let SOUTH = map.getBounds().getSouth(); swal({ title: "!!!!", text: "확인", icon: "정보", 버튼: ["현재 맵 경계 사용", "레이어 확장 경계 사용"], 위험모드: true }).then(function(isConfirm) { if (isConfirm) { bound옵션 = { bbox: [layerWEST, layerSOUTH, layerEAST, layerNORTH] } }; } else { bound옵션 = { bbox: [서쪽, 남쪽, 동쪽, 북쪽] } }; }try {voronoifeatures = turf.featureCollection(voronoigeojsoned.features, bound옵션);다각형 = turf.voronoi(voronoifeatures, bound옵션);} catch (error) {console.log(error);if (error.toString().indexOf('점이어야 함')) {//지오메트리가 다각형으로 구성된 경우 해당 지오메트리에서 중심점을 생성합니다. swal("이 레이어는 점으로 구성되지 않았습니다. 포인트가 아닌 점들은 중심점으로 변환되었습니다.");let centroids = {유형: 'FeatureCollection',features: voronoigeojsoned.features.map(function(feature) {return {type: 'Feature',속성: feature.properties,기하형상: turf.centroid(feature).geometry}})};console.log("centroids",centroids);보로노이제오손드 = 중심점;voronoifeatures = turf.featureCollection(centroids.features, bound옵션);보로노이폴리곤 = turf.voronoi(보로노이특징, 바운드옵션);} // if (error.toString().indexOf('점이어야 함')) { }finally{voronoifeaturegroup.clearLayers();voronoipointLayer.clearLayers();voronoipointTempLayer = new L.geoJSON(voronoigeojsoned.features);//리턴된 지오메트리 객체의 길이를 확인하고 그에 따라 //사용자에게 메시지를 표시합니다.if(Object.keys(voronoiPolygons.features).length > 4000){swal("!!방금 넓은 영역에서 voronoi 함수를 실행했습니다.제한된 영역에 대해 함수를 실행하세요.(분석하려는 특정 영역을 확대하고 옵션 - 현재 맵 경계 - 를 선택하세요.)");hideSpinner();destroyanalysis();return;}//console.log("voronoifeatures.length", Object.keys(voronoiPolygons.features).length);try {turf.featureEach(voronoiPolygons, function(currentFeature, featureIndex) {//console.log("featureIndex.length",featureIndex);if (currentFeature && currentFeature.geometry && currentFeature.geometry.type === "Polygon") {//지오메트리의 좌표를 뒤집습니다.let flipped = turf.flip(currentFeature);let polygon = L.polygon(flipped.geometry.coordinates, {weight: 4, fillOpacity: 0.07,color: 'black',dashArray: '1',fillColor: '#0000FF',pane: "topoPane"}).addTo(보로노이피처그룹);}});} catch (error) {console.log(error)hideSpinner();swal("오류가 발생했습니다");}온라인 네트워크에서 최단 거리이 코드는 지오지슨 경로 찾기 플러그인의 메인 데모에서 영감을 얻었지만 여기서는 이 특정 인스턴스에 맞게 적절히 변경되었습니다.//Based on https://www.liedman.net/geojson-path-finder/router = new rooter(network); //console.log("라우터", 라우터);controlpoint1 = [router.\_points.features[0].geometry.coordinates[1], router.\_points.features[0].geometry.coordinates[0]];controlpoint2 = [router.\_points.features[1].geometry.coordinates[1], router.\_points.features[1].geometry.coordinates[0]];라우팅컨트롤 = L.Routing.control({createMarker: function(i, wp) {return L.marker(wp.latLng, {icon: L.icon.glyph({접두사: '',글리프: String.fromCharCode(65 + i)}),드래그 가능: true})},라우터: 라우터,routeWhileDragging: true,routeDragInterval: 100}).addTo(map);routingcontrol.setWaypoints([[controlpoint1,controlpoint2,]);try {totalDistance = network.features.reduce(function(total, feature) {if (feature.geometry.type === 'LineString') {return total += lineDistance(feature, 'kilometers');} else {return total;}}, 0);