1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
////////////////////////////////////////////////////////////////////////////////
///////////////////// Map loader (OpenLayers or Leaflet) ///////////////////////
////////////////////////////////////////////////////////////////////////////////
function map_load(callbacks)
{
var pending = 1;
var head = document.getElementsByTagName("head")[0];
/* Allow selecting between libraries at run-time if an array is provided */
mapprops.libraries=Array.isArray(mapprops.library);
if(mapprops.libraries)
{
if(location.search.length>1 &&
location.search.match(/library=(leaflet|openlayers2|openlayers)/) &&
mapprops.library.indexOf(RegExp.$1)!=-1)
mapprops.library=RegExp.$1;
else
mapprops.library=mapprops.library[0];
}
/* Call the callbacks when everything is loaded. */
function call_callbacks()
{
if(!--pending)
eval(callbacks);
}
/* Javascript loader */
function load_js(url, urls)
{
var script = document.createElement("script");
script.src = url;
script.type = "text/javascript";
pending++;
if( urls === undefined )
script.onload = call_callbacks;
else
script.onload = function() { load_js(urls); call_callbacks(); };
head.appendChild(script);
}
/* CSS loader */
function load_css(url, urls)
{
var link = document.createElement("link");
link.href = url;
link.type = "text/css";
link.rel = "stylesheet";
head.appendChild(link);
if( urls !== undefined )
load_css(urls)
}
/* Load the external library and local code */
if(mapprops.library == "leaflet")
{
load_css("/javascript/leaflet/leaflet.css");
load_js ("/javascript/leaflet/leaflet.js");
load_js(location.pathname.replace(/\.html.*/,".leaflet.js"));
}
else if(mapprops.library == "openlayers")
{
load_css("../openlayers/ol.css", "../openlayers/ol-layerswitcher.css");
load_js ("../openlayers/ol.js", "../openlayers/ol-layerswitcher.js");
load_js(location.pathname.replace(/\.html.*/,".openlayers.js"));
}
else if(mapprops.library == "openlayers2")
{
load_js("/javascript/openlayers/OpenLayers.js");
load_js(location.pathname.replace(/\.html.*/,".openlayers2.js"));
}
call_callbacks();
}
|