Properly handle polygons
This commit is contained in:
parent
f942ada46a
commit
57fbdb7691
|
@ -58,15 +58,20 @@ function wrapper(plugin_info) {
|
|||
window.plugin.portalsJSON.exportPolygons = function() {
|
||||
portalsData.clear(); // Clear the map before exporting
|
||||
startTime = new Date();
|
||||
|
||||
var searchItems = []; // Data about shapes that will be searched for portals
|
||||
|
||||
// Process drawn items
|
||||
if (window.plugin.drawTools && window.plugin.drawTools.drawnItems) {
|
||||
window.plugin.drawTools.drawnItems.eachLayer(function (layer) {
|
||||
if (layer instanceof L.GeodesicPolygon || layer instanceof L.Polygon || layer instanceof L.GeodesicCircle) {
|
||||
var vertices = layer.getLatLngs();
|
||||
var polygon = L.polygon(vertices);
|
||||
Object.values(window.portals).forEach(function (portal, index) {
|
||||
if (polygon.getBounds().contains(portal.getLatLng())) {
|
||||
window.plugin.portalsJSON.processPortal(portal);
|
||||
}
|
||||
window.plugin.drawTools.drawnItems.eachLayer(function (drawnItem) {
|
||||
if (drawnItem instanceof L.GeodesicCircle) {
|
||||
var searchCircle = window.plugin.polyCounts2.circleToSearchCircle(drawnItem);
|
||||
searchItems.push(searchCircle);
|
||||
}
|
||||
else if (drawnItem instanceof L.GeodesicPolygon) {
|
||||
var searchPolygons = window.plugin.polyCounts2.multiPolygonToSearchPolygons(drawnItem);
|
||||
$.each(searchPolygons, function (index, searchItem) {
|
||||
searchItems.push(searchItem);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -76,19 +81,42 @@ function wrapper(plugin_info) {
|
|||
if (window.search.lastSearch &&
|
||||
window.search.lastSearch.selectedResult &&
|
||||
window.search.lastSearch.selectedResult.layer) {
|
||||
window.search.lastSearch.selectedResult.layer.eachLayer(function (layer) {
|
||||
if (layer instanceof L.Polygon || layer instanceof L.Circle) {
|
||||
var vertices = layer.getLatLngs();
|
||||
var polygon = L.polygon(vertices);
|
||||
Object.values(window.portals).forEach(function (portal, index) {
|
||||
if (polygon.getBounds().contains(portal.getLatLng())) {
|
||||
window.plugin.portalsJSON.processPortal(portal);
|
||||
}
|
||||
window.search.lastSearch.selectedResult.layer.eachLayer(function (drawnItem) {
|
||||
if (drawnItem instanceof L.Polygon || (typeof L.MultiPolygon == "function" && drawnItem instanceof L.MultiPolygon)) {
|
||||
var searchPolygons = window.plugin.polyCounts2.multiPolygonToSearchPolygons(drawnItem);
|
||||
$.each(searchPolygons, function (index, searchItem) {
|
||||
searchItems.push(searchItem);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Process portals
|
||||
$.each(window.portals, function (guid, portal) {
|
||||
var point = portal.getLatLng();
|
||||
var found = false;
|
||||
$.each(searchItems, function (index, searchItem) {
|
||||
switch (searchItem.type) {
|
||||
case 'circle':
|
||||
if (window.plugin.polyCounts2.pointIsInCircle(point, searchItem)) {
|
||||
found = true;
|
||||
return false; // Breaks the loop
|
||||
}
|
||||
break;
|
||||
case 'polygon':
|
||||
if (window.plugin.polyCounts2.pointIsInPolygon(point, searchItem)) {
|
||||
found = true;
|
||||
return false; // Breaks the loop
|
||||
}
|
||||
break;
|
||||
};
|
||||
});
|
||||
if (found) {
|
||||
window.plugin.portalsJSON.processPortal(portal);
|
||||
}
|
||||
});
|
||||
|
||||
// Export data
|
||||
var jsonData = JSON.stringify(Array.from(portalsData.values()), null, 2);
|
||||
var blob = new Blob([jsonData], { type: 'application/json' });
|
||||
var url = URL.createObjectURL(blob);
|
||||
|
@ -103,7 +131,6 @@ function wrapper(plugin_info) {
|
|||
|
||||
exportTime = new Date();
|
||||
}
|
||||
|
||||
function downloadFile(data, filename) {
|
||||
var link = document.createElement('a');
|
||||
link.href = 'data:text/json;charset=utf-8,' + encodeURIComponent(data);
|
||||
|
|
Loading…
Reference in New Issue