add ability to filter by portal level. You can access the feature from the layer selector just as before. Fixes #8 and some of #12
This commit is contained in:
31
code/boot.js
31
code/boot.js
@ -54,18 +54,33 @@ window.setupMap = function() {
|
|||||||
var views = [cmMid, cmMin, osm, new L.Google('INGRESS'), new L.Google('ROADMAP'),
|
var views = [cmMid, cmMin, osm, new L.Google('INGRESS'), new L.Google('ROADMAP'),
|
||||||
new L.Google('SATELLITE'), new L.Google('HYBRID')];
|
new L.Google('SATELLITE'), new L.Google('HYBRID')];
|
||||||
|
|
||||||
portalsLayer = L.layerGroup([]);
|
|
||||||
linksLayer = L.layerGroup([]);
|
|
||||||
fieldsLayer = L.layerGroup([]);
|
|
||||||
window.map = new L.Map('map', $.extend(getPosition(),
|
window.map = new L.Map('map', $.extend(getPosition(),
|
||||||
{zoomControl: !(localStorage['iitc.zoom.buttons'] === 'false')}
|
{zoomControl: !(localStorage['iitc.zoom.buttons'] === 'false')}
|
||||||
));
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.addLayer(views[readCookie('ingress.intelmap.type')]);
|
map.addLayer(views[readCookie('ingress.intelmap.type')]);
|
||||||
} catch(e) { map.addLayer(views[0]); }
|
} catch(e) { map.addLayer(views[0]); }
|
||||||
map.addLayer(portalsLayer);
|
|
||||||
|
var addLayers = {};
|
||||||
|
|
||||||
|
portalsLayers = [];
|
||||||
|
for(var i = 0; i <= 8; i++) {
|
||||||
|
portalsLayers[i] = L.layerGroup([]);
|
||||||
|
map.addLayer(portalsLayers[i]);
|
||||||
|
var t = (i === 0 ? 'Unclaimed' : 'Level ' + i) + ' Portals';
|
||||||
|
addLayers[t] = portalsLayers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldsLayer = L.layerGroup([]);
|
||||||
map.addLayer(fieldsLayer, true);
|
map.addLayer(fieldsLayer, true);
|
||||||
|
addLayers['Fields'] = fieldsLayer;
|
||||||
|
|
||||||
|
linksLayer = L.layerGroup([]);
|
||||||
map.addLayer(linksLayer, true);
|
map.addLayer(linksLayer, true);
|
||||||
|
addLayers['Links'] = linksLayer;
|
||||||
|
|
||||||
map.addControl(new L.Control.Layers({
|
map.addControl(new L.Control.Layers({
|
||||||
'OSM Cloudmade Midnight': views[0],
|
'OSM Cloudmade Midnight': views[0],
|
||||||
'OSM Cloudmade Minimal': views[1],
|
'OSM Cloudmade Minimal': views[1],
|
||||||
@ -74,11 +89,7 @@ window.setupMap = function() {
|
|||||||
'Google Roads': views[4],
|
'Google Roads': views[4],
|
||||||
'Google Satellite': views[5],
|
'Google Satellite': views[5],
|
||||||
'Google Hybrid': views[6]
|
'Google Hybrid': views[6]
|
||||||
}, {
|
}, addLayers));
|
||||||
'Portals': portalsLayer,
|
|
||||||
'Links': linksLayer,
|
|
||||||
'Fields': fieldsLayer
|
|
||||||
}));
|
|
||||||
map.attributionControl.setPrefix('');
|
map.attributionControl.setPrefix('');
|
||||||
// listen for changes and store them in cookies
|
// listen for changes and store them in cookies
|
||||||
map.on('moveend', window.storeMapPosition);
|
map.on('moveend', window.storeMapPosition);
|
||||||
@ -179,7 +190,7 @@ function asyncLoadScript(a){return function(b,c){var d=document.createElement("s
|
|||||||
var LLGMAPS = 'http://breunigs.github.com/ingress-intel-total-conversion/leaflet_google.js';
|
var LLGMAPS = 'http://breunigs.github.com/ingress-intel-total-conversion/leaflet_google.js';
|
||||||
var JQUERY = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js';
|
var JQUERY = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js';
|
||||||
var LEAFLET = 'http://cdn.leafletjs.com/leaflet-0.5/leaflet.js';
|
var LEAFLET = 'http://cdn.leafletjs.com/leaflet-0.5/leaflet.js';
|
||||||
var AUTOLINK = 'https://raw.github.com/bryanwoods/autolink-js/master/autolink.js';
|
var AUTOLINK = 'http://raw.github.com/bryanwoods/autolink-js/master/autolink.js';
|
||||||
|
|
||||||
// after all scripts have loaded, boot the actual app
|
// after all scripts have loaded, boot the actual app
|
||||||
load(JQUERY, LEAFLET, AUTOLINK).then(LLGMAPS).thenRun(boot);
|
load(JQUERY, LEAFLET, AUTOLINK).then(LLGMAPS).thenRun(boot);
|
||||||
|
@ -16,7 +16,8 @@ window.debug.printStackTrace = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.debug.clearPortals = function() {
|
window.debug.clearPortals = function() {
|
||||||
portalsLayer.clearLayers();
|
for(var i = 0; i < portalsLayers.length; i++)
|
||||||
|
portalsLayers[i].clearLayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.debug.clearLinks = function() {
|
window.debug.clearLinks = function() {
|
||||||
|
@ -119,14 +119,17 @@ window.cleanUp = function() {
|
|||||||
var cnt = [0,0,0];
|
var cnt = [0,0,0];
|
||||||
var b = getPaddedBounds();
|
var b = getPaddedBounds();
|
||||||
var minlvl = getMinPortalLevel();
|
var minlvl = getMinPortalLevel();
|
||||||
portalsLayer.eachLayer(function(portal) {
|
for(var i = 0; i < portalsLayers.length; i++) {
|
||||||
// portal must be in bounds and have a high enough level. Also don’t
|
// i is also the portal level
|
||||||
// remove if it is selected.
|
portalsLayers[i].eachLayer(function(portal) {
|
||||||
if(portal.options.guid == window.selectedPortal ||
|
// portal must be in bounds and have a high enough level. Also don’t
|
||||||
(b.contains(portal.getLatLng()) && portal.options.level >= minlvl)) return;
|
// remove if it is selected.
|
||||||
cnt[0]++;
|
if(portal.options.guid == window.selectedPortal ||
|
||||||
portalsLayer.removeLayer(portal);
|
(b.contains(portal.getLatLng()) && i >= minlvl)) return;
|
||||||
});
|
cnt[0]++;
|
||||||
|
portalsLayers[i].removeLayer(portal);
|
||||||
|
});
|
||||||
|
}
|
||||||
linksLayer.eachLayer(function(link) {
|
linksLayer.eachLayer(function(link) {
|
||||||
if(b.intersects(link.getBounds())) return;
|
if(b.intersects(link.getBounds())) return;
|
||||||
cnt[1]++;
|
cnt[1]++;
|
||||||
@ -153,7 +156,9 @@ window.removeByGuid = function(guid) {
|
|||||||
case '11':
|
case '11':
|
||||||
case '12':
|
case '12':
|
||||||
if(!window.portals[guid]) return;
|
if(!window.portals[guid]) return;
|
||||||
portalsLayer.removeLayer(window.portals[guid]);
|
var p = window.portals[guid];
|
||||||
|
for(var i = 0; i < portalsLayers.length; i++)
|
||||||
|
portalsLayers[i].removeLayer(p);
|
||||||
break;
|
break;
|
||||||
case '9':
|
case '9':
|
||||||
if(!window.links[guid]) return;
|
if(!window.links[guid]) return;
|
||||||
@ -212,13 +217,24 @@ window.renderPortal = function(ent) {
|
|||||||
guid: ent[0]});
|
guid: ent[0]});
|
||||||
|
|
||||||
p.on('remove', function() { delete window.portals[this.options.guid]; });
|
p.on('remove', function() { delete window.portals[this.options.guid]; });
|
||||||
p.on('add', function() { window.portals[this.options.guid] = this; });
|
p.on('add', function() {
|
||||||
|
window.portals[this.options.guid] = this;
|
||||||
|
// handles the case where a selected portal gets removed from the
|
||||||
|
// map by hiding all portals with said level
|
||||||
|
if(window.selectedPortal != this.options.guid)
|
||||||
|
window.portalResetColor(this);
|
||||||
|
});
|
||||||
p.on('click', function() { window.renderPortalDetails(ent[0]); });
|
p.on('click', function() { window.renderPortalDetails(ent[0]); });
|
||||||
p.on('dblclick', function() {
|
p.on('dblclick', function() {
|
||||||
window.renderPortalDetails(ent[0]);
|
window.renderPortalDetails(ent[0]);
|
||||||
window.map.setView(latlng, 17);
|
window.map.setView(latlng, 17);
|
||||||
});
|
});
|
||||||
p.addTo(portalsLayer);
|
// portalLevel contains a float, need to round down
|
||||||
|
p.addTo(portalsLayers[parseInt(portalLevel)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.portalResetColor = function(portal) {
|
||||||
|
portal.setStyle({color: portal.options.fillColor});
|
||||||
}
|
}
|
||||||
|
|
||||||
// renders a link on the map from the given entity
|
// renders a link on the map from the given entity
|
||||||
|
@ -104,8 +104,7 @@ window.setPortalIndicators = function(d) {
|
|||||||
window.selectPortal = function(guid) {
|
window.selectPortal = function(guid) {
|
||||||
var update = selectedPortal === guid;
|
var update = selectedPortal === guid;
|
||||||
var oldPortal = portals[selectedPortal];
|
var oldPortal = portals[selectedPortal];
|
||||||
if(!update && oldPortal)
|
if(!update && oldPortal) portalResetColor(oldPortal);
|
||||||
oldPortal.setStyle({color: oldPortal.options.fillColor});
|
|
||||||
|
|
||||||
selectedPortal = guid;
|
selectedPortal = guid;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ window.requests.abort = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// gives user feedback about pending operations. Draws current status
|
// gives user feedback about pending operations. Draws current status
|
||||||
// to website.
|
// to website. Updates info in layer chooser.
|
||||||
window.renderUpdateStatus = function() {
|
window.renderUpdateStatus = function() {
|
||||||
var t = '<b>map status:</b> ';
|
var t = '<b>map status:</b> ';
|
||||||
if(mapRunsUserAction)
|
if(mapRunsUserAction)
|
||||||
@ -50,15 +50,20 @@ window.renderUpdateStatus = function() {
|
|||||||
t += ' <span style="color:red" class="help" title="Can only render so much before it gets unbearably slow. Not all entities are shown. Zoom in or increase the limit (search for MAX_DRAWN_*).">RENDER LIMIT</span> '
|
t += ' <span style="color:red" class="help" title="Can only render so much before it gets unbearably slow. Not all entities are shown. Zoom in or increase the limit (search for MAX_DRAWN_*).">RENDER LIMIT</span> '
|
||||||
|
|
||||||
if(window.failedRequestCount > 0)
|
if(window.failedRequestCount > 0)
|
||||||
t += ' ' + window.failedRequestCount + ' requests failed.'
|
t += ' <span style="color:red">' + window.failedRequestCount + ' requests failed</span>.'
|
||||||
|
|
||||||
t += '<br/>(';
|
t += '<br/>(';
|
||||||
var minlvl = getMinPortalLevel();
|
var minlvl = getMinPortalLevel();
|
||||||
if(minlvl === 0)
|
if(minlvl === 0)
|
||||||
t += 'showing all portals';
|
t += 'loading all portals';
|
||||||
else
|
else
|
||||||
t+= 'only showing portals with level '+minlvl+' and up';
|
t+= 'only loading portals with level '+minlvl+' and up';
|
||||||
t += ')</span>';
|
t += ')';
|
||||||
|
|
||||||
|
var portalSelection = $('.leaflet-control-layers-overlays label');
|
||||||
|
portalSelection.slice(0, minlvl+1).addClass('disabled').attr('title', 'Zoom in to show those.');
|
||||||
|
portalSelection.slice(minlvl, 8).removeClass('disabled').attr('title', '');
|
||||||
|
|
||||||
|
|
||||||
$('#updatestatus').html(t);
|
$('#updatestatus').html(t);
|
||||||
}
|
}
|
||||||
|
2
main.js
2
main.js
@ -149,7 +149,7 @@ window.selectedPortal = null;
|
|||||||
window.portalRangeIndicator = null;
|
window.portalRangeIndicator = null;
|
||||||
window.portalAccessIndicator = null;
|
window.portalAccessIndicator = null;
|
||||||
window.mapRunsUserAction = false;
|
window.mapRunsUserAction = false;
|
||||||
var portalsLayer, linksLayer, fieldsLayer;
|
var portalsLayers, linksLayer, fieldsLayer;
|
||||||
|
|
||||||
// contain references to all entities shown on the map. These are
|
// contain references to all entities shown on the map. These are
|
||||||
// automatically kept in sync with the items on *sLayer, so never ever
|
// automatically kept in sync with the items on *sLayer, so never ever
|
||||||
|
Reference in New Issue
Block a user