Drawn layers can be counted

This patch adds the ability to count the number of the drawn fields
This commit is contained in:
Edoardo Morandi
2015-11-13 13:14:39 +01:00
parent b7361c0e05
commit fef32042bd

View File

@ -31,9 +31,35 @@ plugin.layerCount.onBtnClick = function(ev) {
layer = plugin.layerCount.layer;
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);
btn.classList.remove("active");
} 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);
btn.classList.add("active");
setTimeout(function(){
@ -84,7 +110,7 @@ plugin.layerCount.pnpoly = function(latlngs, point) {
plugin.layerCount.calculate = function(ev) {
var point = ev.latlng;
var fields = window.fields;
var layersRes = layersEnl = 0;
var layersRes = layersEnl = layersDrawn = 0;
for(var guid in fields) {
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)
var content = "Res: " + layersRes + " + Enl: " + layersEnl + " = " + (layersRes + layersEnl) + " fields";
else if(layersRes != 0)
@ -108,6 +142,9 @@ plugin.layerCount.calculate = function(ev) {
else
var content = "No fields";
if (layersDrawn != 0)
content += "; draw: " + layersDrawn + " field(s)";
plugin.layerCount.tooltip.innerHTML = content;
return false;