Drawn layers can be counted
This patch adds the ability to count the number of the drawn fields
This commit is contained in:
@ -31,9 +31,35 @@ plugin.layerCount.onBtnClick = function(ev) {
|
|||||||
layer = plugin.layerCount.layer;
|
layer = plugin.layerCount.layer;
|
||||||
|
|
||||||
if(btn.classList.contains("active")) {
|
if(btn.classList.contains("active")) {
|
||||||
|
if(window.plugin.drawTools !== undefined) {
|
||||||
|
for (var layerId in window.plugin.drawTools.drawnItems._layers) {
|
||||||
|
var layer = window.plugin.drawTools.drawnItems._layers[layerId];
|
||||||
|
if (layer instanceof L.GeodesicPolygon) {
|
||||||
|
L.DomUtil.addClass(layer._path, "leaflet-clickable");
|
||||||
|
layer._path.setAttribute("pointer-events", layer.options.pointerEventsBackup);
|
||||||
|
layer.options.pointerEvents = layer.options.pointerEventsBackup;
|
||||||
|
layer.options.clickable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
map.off("click", plugin.layerCount.calculate);
|
map.off("click", plugin.layerCount.calculate);
|
||||||
btn.classList.remove("active");
|
btn.classList.remove("active");
|
||||||
} else {
|
} else {
|
||||||
|
console.log("inactive");
|
||||||
|
if(window.plugin.drawTools !== undefined) {
|
||||||
|
for (var layerId in window.plugin.drawTools.drawnItems._layers) {
|
||||||
|
var layer = window.plugin.drawTools.drawnItems._layers[layerId];
|
||||||
|
if (layer instanceof L.GeodesicPolygon) {
|
||||||
|
layer.options.pointerEventsBackup = layer.options.pointerEvents;
|
||||||
|
layer.options.pointerEvents = null;
|
||||||
|
layer.options.clickable = false;
|
||||||
|
L.DomUtil.removeClass(layer._path, "leaflet-clickable");
|
||||||
|
layer._path.setAttribute("pointer-events", "none");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
map.on("click", plugin.layerCount.calculate);
|
map.on("click", plugin.layerCount.calculate);
|
||||||
btn.classList.add("active");
|
btn.classList.add("active");
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
@ -84,7 +110,7 @@ plugin.layerCount.pnpoly = function(latlngs, point) {
|
|||||||
plugin.layerCount.calculate = function(ev) {
|
plugin.layerCount.calculate = function(ev) {
|
||||||
var point = ev.latlng;
|
var point = ev.latlng;
|
||||||
var fields = window.fields;
|
var fields = window.fields;
|
||||||
var layersRes = layersEnl = 0;
|
var layersRes = layersEnl = layersDrawn = 0;
|
||||||
|
|
||||||
for(var guid in fields) {
|
for(var guid in fields) {
|
||||||
var field = fields[guid];
|
var field = fields[guid];
|
||||||
@ -99,6 +125,14 @@ plugin.layerCount.calculate = function(ev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (window.plugin.drawTools) {
|
||||||
|
for(var layerId in window.plugin.drawTools.drawnItems._layers) {
|
||||||
|
var field = window.plugin.drawTools.drawnItems._layers[layerId];
|
||||||
|
if(field instanceof L.GeodesicPolygon && plugin.layerCount.pnpoly(field._latlngs, point))
|
||||||
|
layersDrawn++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(layersRes != 0 && layersEnl != 0)
|
if(layersRes != 0 && layersEnl != 0)
|
||||||
var content = "Res: " + layersRes + " + Enl: " + layersEnl + " = " + (layersRes + layersEnl) + " fields";
|
var content = "Res: " + layersRes + " + Enl: " + layersEnl + " = " + (layersRes + layersEnl) + " fields";
|
||||||
else if(layersRes != 0)
|
else if(layersRes != 0)
|
||||||
@ -108,6 +142,9 @@ plugin.layerCount.calculate = function(ev) {
|
|||||||
else
|
else
|
||||||
var content = "No fields";
|
var content = "No fields";
|
||||||
|
|
||||||
|
if (layersDrawn != 0)
|
||||||
|
content += "; draw: " + layersDrawn + " field(s)";
|
||||||
|
|
||||||
plugin.layerCount.tooltip.innerHTML = content;
|
plugin.layerCount.tooltip.innerHTML = content;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user