diff --git a/plugins/zaprange.user.js b/plugins/zaprange.user.js index e6bafaff..8f72383b 100644 --- a/plugins/zaprange.user.js +++ b/plugins/zaprange.user.js @@ -2,7 +2,7 @@ // @id iitc-plugin-zaprange@zaso // @name IITC plugin: Zaprange // @category Layer -// @version 0.1.1.@@DATETIMEVERSION@@ +// @version 0.1.2.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ @@ -16,84 +16,101 @@ @@PLUGINSTART@@ -// PLUGIN START //////////////////////////////////////////////////////// +// PLUGIN START /////////////////////////////////////////////////////// -// use own namespace for plugin -window.plugin.zaprange = function() {}; + // use own namespace for plugin + window.plugin.zaprange = function() {}; + window.plugin.zaprange.zapLayers = {}; + window.plugin.zaprange.MIN_MAP_ZOOM = 16; -window.plugin.zaprange.zapLayers = {}; -window.plugin.zaprange.MIN_MAP_ZOOM = 15; + window.plugin.zaprange.portalAdded = function(data) { + data.portal.on('add', function() { + window.plugin.zaprange.draw(this.options.guid, this.options.details.controllingTeam.team); + }); - -window.plugin.zaprange.portalAdded = function(data) { - data.portal.on('add', function() { - window.plugin.zaprange.draw(this.options.guid); - }); - - data.portal.on('remove', function() { - window.plugin.zaprange.remove(this.options.guid); - }); -} - -window.plugin.zaprange.remove = function(guid) { - var previousLayer = window.plugin.zaprange.zapLayers[guid]; - if(previousLayer) { - window.plugin.zaprange.zapCircleHolderGroup.removeLayer(previousLayer); - delete window.plugin.zaprange.zapLayers[guid]; + data.portal.on('remove', function() { + window.plugin.zaprange.remove(this.options.guid, this.options.details.controllingTeam.team); + }); } -} -window.plugin.zaprange.draw = function(guid) { - var d = window.portals[guid]; - var dd = d.options.details; - - if(dd.controllingTeam.team !== "NEUTRAL") { - var coo = d._latlng; - var latlng = new L.LatLng(coo.lat,coo.lng); - var portalLevel = parseInt(getPortalLevel(dd)); - var optCircle = {color:'red',opacity:0.7,fill:true,fillColor:'red',fillOpacity:0.1,weight:1,clickable:false, dashArray: [10,6]}; - var range = (5*portalLevel)+35; - - var circle = new L.Circle(latlng, range, optCircle); - window.plugin.zaprange.zapLayers[guid] = circle; - circle.addTo(window.plugin.zaprange.zapCircleHolderGroup); - } -} - -window.plugin.zaprange.showOrHide = function() { - var ctrl = $('.leaflet-control-layers-selector + span:contains("Portal Attack Range")').parent(); - if (map.getZoom() >= window.plugin.zaprange.MIN_MAP_ZOOM) { - // show the layer - if(!window.plugin.zaprange.zapLayerHolderGroup.hasLayer(window.plugin.zaprange.zapCircleHolderGroup)) { - window.plugin.zaprange.zapLayerHolderGroup.addLayer(window.plugin.zaprange.zapCircleHolderGroup); + window.plugin.zaprange.remove = function(guid, faction) { + var previousLayer = window.plugin.zaprange.zapLayers[guid]; + if(previousLayer) { + if(faction === 'ENLIGHTENED') { + window.plugin.zaprange.zapCircleEnlHolderGroup.removeLayer(previousLayer); + } else { + window.plugin.zaprange.zapCircleResHolderGroup.removeLayer(previousLayer); + } + delete window.plugin.zaprange.zapLayers[guid]; } - ctrl.removeClass('disabled').attr('title', ''); - } else { - // hide the layer - if(window.plugin.zaprange.zapLayerHolderGroup.hasLayer(window.plugin.zaprange.zapCircleHolderGroup)) { - window.plugin.zaprange.zapLayerHolderGroup.removeLayer(window.plugin.zaprange.zapCircleHolderGroup); - } - ctrl.addClass('disabled').attr('title', 'Zoom in to show those.'); } -} -var setup = function() { - // this layer is added to tha layer chooser, to be toggled on/off - window.plugin.zaprange.zapLayerHolderGroup = new L.LayerGroup(); + window.plugin.zaprange.draw = function(guid, faction) { + var d = window.portals[guid]; - // this layer is added into the above layer, and removed from it when we zoom out too far - window.plugin.zaprange.zapCircleHolderGroup = new L.LayerGroup(); + if(faction !== "NEUTRAL") { + var coo = d._latlng; + var latlng = new L.LatLng(coo.lat,coo.lng); + var portalLevel = parseInt(getPortalLevel(d.options.details)); + var optCircle = {color:'red',opacity:0.7,fillColor:'red',fillOpacity:0.1,weight:1,clickable:false, dashArray: [10,6]}; + var range = (5*portalLevel)+35; - window.plugin.zaprange.zapLayerHolderGroup.addLayer(window.plugin.zaprange.zapCircleHolderGroup); + var circle = new L.Circle(latlng, range, optCircle); - window.addLayerGroup('Portal Attack Range', window.plugin.zaprange.zapLayerHolderGroup, true); - window.addHook('portalAdded', window.plugin.zaprange.portalAdded); + if(faction === 'ENLIGHTENED') { + circle.addTo(window.plugin.zaprange.zapCircleEnlHolderGroup); + } else { + circle.addTo(window.plugin.zaprange.zapCircleResHolderGroup); + } + window.plugin.zaprange.zapLayers[guid] = circle; + } + } - map.on('zoomend', window.plugin.zaprange.showOrHide); + window.plugin.zaprange.showOrHide = function() { + if(map.getZoom() >= window.plugin.zaprange.MIN_MAP_ZOOM) { + // show the layer + if(!window.plugin.zaprange.zapLayerEnlHolderGroup.hasLayer(window.plugin.zaprange.zapCircleEnlHolderGroup)) { + window.plugin.zaprange.zapLayerEnlHolderGroup.addLayer(window.plugin.zaprange.zapCircleEnlHolderGroup); + $('.leaflet-control-layers-list span:contains("Zaprange Enlightened")').parent('label').removeClass('disabled').attr('title', ''); + } + if(!window.plugin.zaprange.zapLayerResHolderGroup.hasLayer(window.plugin.zaprange.zapCircleResHolderGroup)) { + window.plugin.zaprange.zapLayerResHolderGroup.addLayer(window.plugin.zaprange.zapCircleResHolderGroup); + $('.leaflet-control-layers-list span:contains("Zaprange Resistance")').parent('label').removeClass('disabled').attr('title', ''); + } + } else { + // hide the layer + if(window.plugin.zaprange.zapLayerEnlHolderGroup.hasLayer(window.plugin.zaprange.zapCircleEnlHolderGroup)) { + window.plugin.zaprange.zapLayerEnlHolderGroup.removeLayer(window.plugin.zaprange.zapCircleEnlHolderGroup); + $('.leaflet-control-layers-list span:contains("Zaprange Enlightened")').parent('label').addClass('disabled').attr('title', 'Zoom in to show those.'); + } + if(window.plugin.zaprange.zapLayerResHolderGroup.hasLayer(window.plugin.zaprange.zapCircleResHolderGroup)) { + window.plugin.zaprange.zapLayerResHolderGroup.removeLayer(window.plugin.zaprange.zapCircleResHolderGroup); + $('.leaflet-control-layers-list span:contains("Zaprange Resistance")').parent('label').addClass('disabled').attr('title', 'Zoom in to show those.'); + } + } + } - window.plugin.zaprange.showOrHide(); + var setup = function() { + // this layer is added to the layer chooser, to be toggled on/off + window.plugin.zaprange.zapLayerEnlHolderGroup = new L.LayerGroup(); + window.plugin.zaprange.zapLayerResHolderGroup = new L.LayerGroup(); -} + // this layer is added into the above layer, and removed from it when we zoom out too far + window.plugin.zaprange.zapCircleEnlHolderGroup = new L.LayerGroup(); + window.plugin.zaprange.zapCircleResHolderGroup = new L.LayerGroup(); + + window.plugin.zaprange.zapLayerEnlHolderGroup.addLayer(window.plugin.zaprange.zapCircleEnlHolderGroup); + window.plugin.zaprange.zapLayerResHolderGroup.addLayer(window.plugin.zaprange.zapCircleResHolderGroup); + + window.addLayerGroup('Zaprange Enlightened', window.plugin.zaprange.zapLayerEnlHolderGroup, true); + window.addLayerGroup('Zaprange Resistance', window.plugin.zaprange.zapLayerResHolderGroup, true); + + window.addHook('portalAdded', window.plugin.zaprange.portalAdded); + + map.on('zoomend', window.plugin.zaprange.showOrHide); + + window.plugin.zaprange.showOrHide(); + } // PLUGIN END //////////////////////////////////////////////////////////