Move resonator layer back to layerGroup "portalsLayers",
to make it work with portal level filter. And modify cleanup code to work with this change.
This commit is contained in:
@ -81,15 +81,6 @@ window.setupMap = function() {
|
|||||||
map.addLayer(linksLayer, true);
|
map.addLayer(linksLayer, true);
|
||||||
addLayers['Links'] = linksLayer;
|
addLayers['Links'] = linksLayer;
|
||||||
|
|
||||||
resonatorsLayers = [];
|
|
||||||
for(var i = 1; i <= 8; i++) {
|
|
||||||
resonatorsLayers[i] = L.layerGroup([]);
|
|
||||||
map.addLayer(resonatorsLayers[i]);
|
|
||||||
var t = 'Level ' + i + ' Portal resonators';
|
|
||||||
addLayers[t] = resonatorsLayers[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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],
|
||||||
|
@ -143,19 +143,31 @@ window.cleanUp = function() {
|
|||||||
var minlvl = getMinPortalLevel();
|
var minlvl = getMinPortalLevel();
|
||||||
for(var i = 0; i < portalsLayers.length; i++) {
|
for(var i = 0; i < portalsLayers.length; i++) {
|
||||||
// i is also the portal level
|
// i is also the portal level
|
||||||
portalsLayers[i].eachLayer(function(portal) {
|
portalsLayers[i].eachLayer(function(item) {
|
||||||
// portal must be in bounds and have a high enough level. Also don’t
|
// portal must be in bounds and have a high enough level. Also don’t
|
||||||
// remove if it is selected.
|
// remove if it is selected.
|
||||||
var portalGuid = portal.options.guid;
|
var itemGuid = item.options.guid;
|
||||||
if(portalGuid == window.selectedPortal ||
|
switch(getTypeByGuid(itemGuid)){
|
||||||
(b.contains(portal.getLatLng()) && i >= minlvl)) return;
|
|
||||||
|
case TYPE_PORTAL:
|
||||||
|
if(itemGuid == window.selectedPortal ||
|
||||||
|
(b.contains(item.getLatLng()) && i >= minlvl)) return;
|
||||||
|
|
||||||
cnt[0]++;
|
cnt[0]++;
|
||||||
|
|
||||||
//remove attached resonators
|
//remove attached resonators
|
||||||
for(var j = 0; j <= 7; j++) removeByGuid( portalResonatorGuid(portalGuid,j) );
|
for(var j = 0; j <= 7; j++) removeByGuid( portalResonatorGuid(itemGuid,j) );
|
||||||
|
|
||||||
portalsLayers[i].removeLayer(portal);
|
portalsLayers[i].removeLayer(item);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_RESONATOR:
|
||||||
|
// remove all resonator if zoom level become
|
||||||
|
// lower than RESONATOR_DISPLAY_ZOOM_LEVEL
|
||||||
|
if (map.getZoom() < RESONATOR_DISPLAY_ZOOM_LEVEL)
|
||||||
|
portalsLayers[i].removeLayer(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
linksLayer.eachLayer(function(link) {
|
linksLayer.eachLayer(function(link) {
|
||||||
@ -168,14 +180,6 @@ window.cleanUp = function() {
|
|||||||
cnt[2]++;
|
cnt[2]++;
|
||||||
fieldsLayer.removeLayer(field);
|
fieldsLayer.removeLayer(field);
|
||||||
});
|
});
|
||||||
// remove all resonator if zoom level become
|
|
||||||
// lower than RESONATOR_DISPLAY_ZOOM_LEVEL
|
|
||||||
if (map.getZoom() < RESONATOR_DISPLAY_ZOOM_LEVEL){
|
|
||||||
for(var i = 1; i < resonatorsLayers.length; i++){
|
|
||||||
resonatorsLayers[i].clearLayers();
|
|
||||||
}
|
|
||||||
console.log('removed all resonators');
|
|
||||||
}
|
|
||||||
console.log('removed out-of-bounds: '+cnt[0]+' portals, '+cnt[1]+' links, '+cnt[2]+' fields');
|
console.log('removed out-of-bounds: '+cnt[0]+' portals, '+cnt[1]+' links, '+cnt[2]+' fields');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +203,7 @@ window.removeByGuid = function(guid) {
|
|||||||
break;
|
break;
|
||||||
case TYPE_RESONATOR:
|
case TYPE_RESONATOR:
|
||||||
if(!window.resonators[guid]) return;
|
if(!window.resonators[guid]) return;
|
||||||
resonatorsLayers[window.resonators[guid].options.pLevel].removeLayer(window.resonators[guid]);
|
portalsLayers[window.resonators[guid].options.pLevel].removeLayer(window.resonators[guid]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn('unknown GUID type: ' + guid);
|
console.warn('unknown GUID type: ' + guid);
|
||||||
@ -319,7 +323,7 @@ window.renderResonator = function(ent) {
|
|||||||
r.on('remove', function() { delete window.resonators[this.options.guid]; });
|
r.on('remove', function() { delete window.resonators[this.options.guid]; });
|
||||||
r.on('add', function() { window.resonators[this.options.guid] = this; });
|
r.on('add', function() { window.resonators[this.options.guid] = this; });
|
||||||
|
|
||||||
r.addTo(resonatorsLayers[parseInt(portalLevel)]);
|
r.addTo(portalsLayers[parseInt(portalLevel)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
main.js
2
main.js
@ -159,7 +159,7 @@ window.selectedPortal = null;
|
|||||||
window.portalRangeIndicator = null;
|
window.portalRangeIndicator = null;
|
||||||
window.portalAccessIndicator = null;
|
window.portalAccessIndicator = null;
|
||||||
window.mapRunsUserAction = false;
|
window.mapRunsUserAction = false;
|
||||||
var portalsLayers, linksLayer, fieldsLayer, resonatorsLayers;
|
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