yandex map layer: add dummy layers to the map immediately, then add the yandex layers once the external JS library has loaded

This commit is contained in:
Jon Atkins 2013-12-24 01:00:52 +00:00
parent b06deba743
commit fd33750d28

View File

@ -2,7 +2,7 @@
// @id iitc-plugin-basemap-yandex@jonatkins // @id iitc-plugin-basemap-yandex@jonatkins
// @name IITC plugin: Yandex maps // @name IITC plugin: Yandex maps
// @category Map Tiles // @category Map Tiles
// @version 0.1.0.@@DATETIMEVERSION@@ // @version 0.2.0.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL @@UPDATEURL@@ // @updateURL @@UPDATEURL@@
// @downloadURL @@DOWNLOADURL@@ // @downloadURL @@DOWNLOADURL@@
@ -22,21 +22,18 @@
// use own namespace for plugin // use own namespace for plugin
window.plugin.mapTileYandex = function() {}; window.plugin.mapTileYandex = function() {};
window.plugin.mapTileYandex.leafletSetup = function() {
window.plugin.mapTileYandex.setup = function() {
//a few options on language are available, including en-US. Oddly, the detail available on the maps varies
//depending on the language
var yandexApiJs = '//api-maps.yandex.ru/2.0-stable/?load=package.standard&lang=ru-RU'
load(yandexApiJs).thenRun(window.plugin.mapTileYandex.addLayer);
}
window.plugin.mapTileYandex.addLayer = function() {
//include Yandex.js start //include Yandex.js start
@@INCLUDERAW:external/Yandex.js@@ @@INCLUDERAW:external/Yandex.js@@
//include Yandex.js end //include Yandex.js end
}
window.plugin.mapTileYandex.setup = function() {
var yStyles = { var yStyles = {
'map': "Map", 'map': "Map",
'satellite': "Satellite", 'satellite': "Satellite",
@ -46,14 +43,32 @@ window.plugin.mapTileYandex.addLayer = function() {
}; };
var yOpt = {maxZoom: 18}; // we can't directly create the L.Yandex object, as we need to async load the yandex map API
// so we'll add empty layer groups, then in the callback we can add the yandex layers to the layer groups
var layers = {};
$.each(yStyles, function(key,value) { $.each(yStyles, function(key,value) {
var yMap = new L.Yandex(key, yOpt); layers[key] = new L.LayerGroup();
layerChooser.addBaseLayer(yMap, 'Yandex '+value); layerChooser.addBaseLayer(layers[key], 'Yandex '+value);
}); });
}; var callback = function() {
window.plugin.mapTileYandex.leafletSetup();
var yOpt = {maxZoom: 18};
$.each(layers, function(key,layer) {
var yMap = new L.Yandex(key, yOpt);
layer.addLayer(yMap);
});
}
//a few options on language are available, including en-US. Oddly, the detail available on the maps varies
//depending on the language
var yandexApiJs = '//api-maps.yandex.ru/2.0-stable/?load=package.standard&lang=ru-RU'
load(yandexApiJs).thenRun(callback);
}
var setup = window.plugin.mapTileYandex.setup; var setup = window.plugin.mapTileYandex.setup;