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:
Stefan Breunig
2013-02-08 17:39:37 +01:00
parent 9316d49e68
commit f5edc84635
7 changed files with 67 additions and 30 deletions

View File

@ -54,18 +54,33 @@ window.setupMap = function() {
var views = [cmMid, cmMin, osm, new L.Google('INGRESS'), new L.Google('ROADMAP'),
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(),
{zoomControl: !(localStorage['iitc.zoom.buttons'] === 'false')}
));
try {
map.addLayer(views[readCookie('ingress.intelmap.type')]);
} 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);
addLayers['Fields'] = fieldsLayer;
linksLayer = L.layerGroup([]);
map.addLayer(linksLayer, true);
addLayers['Links'] = linksLayer;
map.addControl(new L.Control.Layers({
'OSM Cloudmade Midnight': views[0],
'OSM Cloudmade Minimal': views[1],
@ -74,11 +89,7 @@ window.setupMap = function() {
'Google Roads': views[4],
'Google Satellite': views[5],
'Google Hybrid': views[6]
}, {
'Portals': portalsLayer,
'Links': linksLayer,
'Fields': fieldsLayer
}));
}, addLayers));
map.attributionControl.setPrefix('');
// listen for changes and store them in cookies
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 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 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
load(JQUERY, LEAFLET, AUTOLINK).then(LLGMAPS).thenRun(boot);

View File

@ -16,7 +16,8 @@ window.debug.printStackTrace = function() {
}
window.debug.clearPortals = function() {
portalsLayer.clearLayers();
for(var i = 0; i < portalsLayers.length; i++)
portalsLayers[i].clearLayers();
}
window.debug.clearLinks = function() {

View File

@ -119,14 +119,17 @@ window.cleanUp = function() {
var cnt = [0,0,0];
var b = getPaddedBounds();
var minlvl = getMinPortalLevel();
portalsLayer.eachLayer(function(portal) {
for(var i = 0; i < portalsLayers.length; i++) {
// i is also the portal level
portalsLayers[i].eachLayer(function(portal) {
// portal must be in bounds and have a high enough level. Also dont
// remove if it is selected.
if(portal.options.guid == window.selectedPortal ||
(b.contains(portal.getLatLng()) && portal.options.level >= minlvl)) return;
(b.contains(portal.getLatLng()) && i >= minlvl)) return;
cnt[0]++;
portalsLayer.removeLayer(portal);
portalsLayers[i].removeLayer(portal);
});
}
linksLayer.eachLayer(function(link) {
if(b.intersects(link.getBounds())) return;
cnt[1]++;
@ -153,7 +156,9 @@ window.removeByGuid = function(guid) {
case '11':
case '12':
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;
case '9':
if(!window.links[guid]) return;
@ -212,13 +217,24 @@ window.renderPortal = function(ent) {
guid: ent[0]});
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('dblclick', function() {
window.renderPortalDetails(ent[0]);
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

View File

@ -104,8 +104,7 @@ window.setPortalIndicators = function(d) {
window.selectPortal = function(guid) {
var update = selectedPortal === guid;
var oldPortal = portals[selectedPortal];
if(!update && oldPortal)
oldPortal.setStyle({color: oldPortal.options.fillColor});
if(!update && oldPortal) portalResetColor(oldPortal);
selectedPortal = guid;

View File

@ -34,7 +34,7 @@ window.requests.abort = function() {
}
// gives user feedback about pending operations. Draws current status
// to website.
// to website. Updates info in layer chooser.
window.renderUpdateStatus = function() {
var t = '<b>map status:</b> ';
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> '
if(window.failedRequestCount > 0)
t += ' ' + window.failedRequestCount + ' requests failed.'
t += ' <span style="color:red">' + window.failedRequestCount + ' requests failed</span>.'
t += '<br/>(';
var minlvl = getMinPortalLevel();
if(minlvl === 0)
t += 'showing all portals';
t += 'loading all portals';
else
t+= 'only showing portals with level '+minlvl+' and up';
t += ')</span>';
t+= 'only loading portals with level '+minlvl+' and up';
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);
}

View File

@ -149,7 +149,7 @@ window.selectedPortal = null;
window.portalRangeIndicator = null;
window.portalAccessIndicator = null;
window.mapRunsUserAction = false;
var portalsLayer, linksLayer, fieldsLayer;
var portalsLayers, linksLayer, fieldsLayer;
// contain references to all entities shown on the map. These are
// automatically kept in sync with the items on *sLayer, so never ever

View File

@ -70,6 +70,11 @@ a:hover {
z-index: 1000;
}
.leaflet-control-layers-overlays label.disabled {
text-decoration: line-through;
cursor: help;
}
.help {
cursor: help;
}