basemap-bing plugin: dynamic creation of bing map layer - in theory should reduce usage
This commit is contained in:
parent
231178123f
commit
aae16d2c1b
@ -2,7 +2,7 @@
|
||||
// @id iitc-plugin-bing-maps
|
||||
// @name IITC plugin: Bing maps
|
||||
// @category Map Tiles
|
||||
// @version 0.1.1.@@DATETIMEVERSION@@
|
||||
// @version 0.1.2.@@DATETIMEVERSION@@
|
||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||
// @updateURL @@UPDATEURL@@
|
||||
// @downloadURL @@DOWNLOADURL@@
|
||||
@ -23,7 +23,7 @@ window.plugin.mapBing = function() {};
|
||||
window.plugin.mapBing.setupBingLeaflet = function() {
|
||||
@@INCLUDERAW:external/Bing.js@@
|
||||
}
|
||||
|
||||
|
||||
|
||||
window.plugin.mapBing.setup = function() {
|
||||
window.plugin.mapBing.setupBingLeaflet();
|
||||
@ -37,12 +37,35 @@ window.plugin.mapBing.setup = function() {
|
||||
'AerialWithLabels': "Aerial with labels",
|
||||
};
|
||||
|
||||
// bing maps has an annual usage limit, which will likely be hit in 6 months at this time.
|
||||
// it seems that the usage is counted on initialising the L.BingLayer, when the metadata is retrieved.
|
||||
// so, we'll create some dummy layers and add those to the map, then, the first time a layer is added,
|
||||
// create the L.BingLayer. This will eliminate all usage for users who install but don't use the map,
|
||||
// and only create usage for the map layers actually selected in use
|
||||
|
||||
var bingMapContainers = [];
|
||||
|
||||
for (type in bingTypes) {
|
||||
var name = bingTypes[type];
|
||||
var bingMap = new L.BingLayer(bingApiKey, {type: type, maxZoom:20});
|
||||
layerChooser.addBaseLayer(bingMap, 'Bing '+name);
|
||||
|
||||
bingMapContainers[type] = new L.LayerGroup();
|
||||
layerChooser.addBaseLayer(bingMapContainers[type], 'Bing '+name);
|
||||
}
|
||||
|
||||
// now a leaflet event to catch base layer changes and create a L.BingLayer when needed
|
||||
map.on('baselayerchange', function(e) {
|
||||
for (type in bingMapContainers) {
|
||||
if (e.layer == bingMapContainers[type]) {
|
||||
if (bingMapContainers[type].getLayers().length == 0) {
|
||||
// dummy layer group is empty - create the bing layer
|
||||
console.log('basemap-bing: creating '+type+' layer');
|
||||
var bingMap = new L.BingLayer (bingApiKey, {type: type, maxZoom:20});
|
||||
bingMapContainers[type].addLayer(bingMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var setup = window.plugin.mapBing.setup;
|
||||
|
Loading…
x
Reference in New Issue
Block a user