diff --git a/images/btn-layer-count.svg b/images/btn-layer-count.svg new file mode 100644 index 00000000..225ce50e --- /dev/null +++ b/images/btn-layer-count.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/plugins/layer-count.css b/plugins/layer-count.css new file mode 100644 index 00000000..471bdbe5 --- /dev/null +++ b/plugins/layer-count.css @@ -0,0 +1,39 @@ +.leaflet-control-layer-count a +{ + background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIzMCI+Cgk8ZyBzdHlsZT0iZmlsbDojMDAwMDAwO2ZpbGwtb3BhY2l0eTowLjQ7c3Ryb2tlOm5vbmUiPgoJCTxwYXRoIGQ9Ik0gNiwyNCAyNCwyNCAxNSw2IHoiLz4KCQk8cGF0aCBkPSJNIDYsMjQgMjQsMjQgMTUsMTIgeiIvPgoJCTxwYXRoIGQ9Ik0gNiwyNCAyNCwyNCAxNSwxOCB6Ii8+Cgk8L2c+Cjwvc3ZnPgo="); +} +.leaflet-control-layer-count a.active +{ + background-color: #BBB; +} +.leaflet-control-layer-count-tooltip +{ + background-color: rgba(255, 255, 255, 0.6); + display: none; + height: 24px; + left: 30px; + line-height: 24px; + margin-left: 15px; + margin-top: -12px; + padding: 0 10px; + position: absolute; + top: 50%; + white-space: nowrap; + width: auto; +} +.leaflet-control-layer-count a.active .leaflet-control-layer-count-tooltip +{ + display: block; +} +.leaflet-control-layer-count-tooltip:before +{ + border-color: transparent rgba(255, 255, 255, 0.6); + border-style: solid; + border-width: 12px 12px 12px 0; + content: ""; + display: block; + height: 0; + left: -12px; + position: absolute; + width: 0; +} diff --git a/plugins/layer-count.user.js b/plugins/layer-count.user.js new file mode 100644 index 00000000..e7b0b998 --- /dev/null +++ b/plugins/layer-count.user.js @@ -0,0 +1,138 @@ +// ==UserScript== +// @id layer-count@fkloft +// @name IITC plugin: layer count +// @category Info +// @version 0.1.0.@@DATETIMEVERSION@@ +// @namespace https://github.com/jonatkins/ingress-intel-total-conversion +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description [@@BUILDNAME@@-@@BUILDDATE@@] Allow users to count nested fields +// @include https://www.ingress.com/intel* +// @include http://www.ingress.com/intel* +// @match https://www.ingress.com/intel* +// @match http://www.ingress.com/intel* +// @grant none +// ==/UserScript== + +@@PLUGINSTART@@ + +// PLUGIN START //////////////////////////////////////////////////////// + +// use own namespace for plugin +plugin.layerCount = {} + +plugin.layerCount.onBtnClick = function(ev) { + var btn = plugin.layerCount.button, + tooltip = plugin.layerCount.tooltip, + layer = plugin.layerCount.layer; + + if(btn.classList.contains("active")) { + map.off("click", plugin.layerCount.calculate); + btn.classList.remove("active"); + } else { + map.on("click", plugin.layerCount.calculate); + btn.classList.add("active"); + setTimeout(function(){ + tooltip.textContent = "Click on map"; + }, 10); + } +}; + +plugin.layerCount.latLngE6ToGooglePoint = function(point) { + return new google.maps.LatLng(point.latE6/1E6, point.lngE6/1E6); +} + +/* +pnpoly Copyright (c) 1970-2003, Wm. Randolph Franklin + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the following conditions: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following + disclaimers. + 2. Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other + materials provided with the distribution. + 3. The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without + specific prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +plugin.layerCount.pnpoly = function(latlngs, point) { + var length = latlngs.length, c = false; + + for(var i = 0, j = length - 1; i < length; j = i++) { + if(((latlngs[i].lat > point.lat) != (latlngs[j].lat > point.lat)) && + (point.lng < latlngs[i].lng + + (latlngs[j].lng - latlngs[i].lng) * (point.lat - latlngs[i].lat) + / (latlngs[j].lat - latlngs[i].lat))) { + c = !c; + } + } + + return c; +} + +plugin.layerCount.calculate = function(ev) { + // TODO: find a geodesic implementation + var point = ev.latlng; + var fields = window.fields; + var layersRes = layersEnl = 0; + + for(var guid in fields) { + var field = fields[guid]; + + if(plugin.layerCount.pnpoly(field._latlngs, point)) { + if(field.options.data.team == "ENLIGHTENED") + layersEnl++; + else + layersRes++; + } + } + + if(layersRes != 0 && layersEnl != 0) + var content = "Res: " + layersRes + " + Enl: " + layersEnl + " = " + (layersRes + layersEnl) + " fields"; + else if(layersRes != 0) + var content = "Res: " + layersRes + " field(s)"; + else if(layersEnl != 0) + var content = "Enl: " + layersEnl + " field(s)"; + else + var content = "No fields"; + + plugin.layerCount.tooltip.innerHTML = content; + + return false; +}; + +var setup = function() { + $('