Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/web/www/routino/maploader.js
Parent Directory
|
Revision Log
Revision 2005 -
(show annotations)
(download)
(as text)
Sat Aug 31 14:30:44 2019 UTC (5 years, 6 months ago) by amb
File MIME type: application/javascript
File size: 1781 byte(s)
Sat Aug 31 14:30:44 2019 UTC (5 years, 6 months ago) by amb
File MIME type: application/javascript
File size: 1781 byte(s)
Add support for the latest version of OpenLayers (version 5.x) library as well as the older, incompatible, version.
1 | //////////////////////////////////////////////////////////////////////////////// |
2 | ///////////////////// Map loader (OpenLayers or Leaflet) /////////////////////// |
3 | //////////////////////////////////////////////////////////////////////////////// |
4 | |
5 | |
6 | function map_load(callbacks) |
7 | { |
8 | var pending = 1; |
9 | var head = document.getElementsByTagName("head")[0]; |
10 | |
11 | /* Call the callbacks when everything is loaded. */ |
12 | |
13 | function call_callbacks() |
14 | { |
15 | if(!--pending) |
16 | eval(callbacks); |
17 | } |
18 | |
19 | /* Javascript loader */ |
20 | |
21 | function load_js(url, urls) |
22 | { |
23 | var script = document.createElement("script"); |
24 | script.src = url; |
25 | script.type = "text/javascript"; |
26 | |
27 | pending++; |
28 | |
29 | if( urls === undefined ) |
30 | script.onload = call_callbacks; |
31 | else |
32 | script.onload = function() { load_js(urls); call_callbacks(); }; |
33 | |
34 | head.appendChild(script); |
35 | } |
36 | |
37 | /* CSS loader */ |
38 | |
39 | function load_css(url, urls) |
40 | { |
41 | var link = document.createElement("link"); |
42 | link.href = url; |
43 | link.type = "text/css"; |
44 | link.rel = "stylesheet"; |
45 | |
46 | head.appendChild(link); |
47 | |
48 | if( urls !== undefined ) |
49 | load_css(urls) |
50 | } |
51 | |
52 | /* Load the external library and local code */ |
53 | |
54 | if(mapprops.library == "leaflet") |
55 | { |
56 | load_css("../leaflet/leaflet.css"); |
57 | load_js ("../leaflet/leaflet.js"); |
58 | |
59 | load_js(location.pathname.replace(/\.html.*/,".leaflet.js")); |
60 | } |
61 | else if(mapprops.library == "openlayers") |
62 | { |
63 | load_css("../openlayers/ol.css", "../openlayers/ol-layerswitcher.css"); |
64 | load_js ("../openlayers/ol.js", "../openlayers/ol-layerswitcher.js"); |
65 | |
66 | load_js(location.pathname.replace(/\.html.*/,".openlayers.js")); |
67 | } |
68 | else if(mapprops.library == "openlayers2") |
69 | { |
70 | load_js("../openlayers2/OpenLayers.js"); |
71 | |
72 | load_js(location.pathname.replace(/\.html.*/,".openlayers2.js")); |
73 | } |
74 | |
75 | call_callbacks(); |
76 | } |