xref: /plugin/openlayersmap/script.js (revision efdc19dc4598ed4dae8fc0887f2774d295727c3e)
1/*
2 * Copyright (c) 2008-2013 Mark C. Prins <mprins@users.sf.net>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/**
18 * @fileoverview Javascript voor OpenLayers plugin.
19 *
20 * @requires {lib/OpenLayers.js} or a full openlayers build
21 * @author Mark C. Prins <mprins@users.sf.net>
22 *
23 */
24
25/**
26 * Openlayers selectcontrol.
27 *
28 * @type {OpenLayers.Control.SelectFeature}
29 * @private
30 */
31var selectControl;
32
33/**
34 * handle feature select event.
35 *
36 * @param {OpenLayers.Feature.Vector}
37 *            feature the selected feature
38 */
39function onFeatureSelect(feature) {
40	var selectedFeature = feature;
41	// 'this' is selectFeature control
42	var pPos = selectedFeature.geometry.getBounds().getCenterLonLat();
43	// != OpenLayers.Geometry.Point
44	if (selectedFeature.geometry.CLASS_NAME === "OpenLayers.Geometry.LineString") {
45		try {
46			// for lines make the popup show at the cursor position
47			pPos = feature.layer.map.getLonLatFromViewPortPx(this.handlers.feature.evt.xy);
48		} catch (anErr) {
49			OpenLayers.Console.warn("unable to get event position; reverting to boundingbox center.");
50			pPos = selectedFeature.geometry.getBounds().getCenterLonLat();
51		}
52	}
53
54	var pContent = '<div class="spacer">&nbsp;</div>';
55	if (feature.data.rowId !== undefined) {
56		pContent += '<span class="rowId">' + feature.data.rowId + ': </span>';
57	}
58	if (feature.data.name !== undefined) {
59		pContent += '<span class="txt">' + feature.data.name + '</span>';
60	}
61	if (feature.data.ele !== undefined) {
62		pContent += '<div class="ele">elevation: ' + feature.data.ele + '</div>';
63	}
64	if (feature.data.type !== undefined) {
65		pContent += '<div>' + feature.data.type + '</div>';
66	}
67	if (feature.data.time !== undefined) {
68		pContent += '<div class="time">time: ' + feature.data.time + '</div>';
69	}
70	if (feature.data.description !== undefined) {
71		pContent += '<div class="desc">' + feature.data.description + '</div>';
72	}
73
74	if (pContent.length > 0) {
75		// only show when there is something to show...
76		var popup = new OpenLayers.Popup.FramedCloud("olPopup", pPos, null, pContent, null, true, function() {
77			selectControl.unselect(selectedFeature);
78		});
79		feature.popup = popup;
80		feature.layer.map.addPopup(popup);
81	}
82}
83
84/**
85 * handle feature unselect event. remove & destroy the popup.
86 *
87 * @param {OpenLayers.Feature.Vector}
88 *            feature the un-selected feature
89 */
90function onFeatureUnselect(feature) {
91	if (feature.popup !== null) {
92		feature.layer.map.removePopup(feature.popup);
93		feature.popup.destroy();
94		feature.popup = null;
95	}
96}
97/**
98 * Test for css support in the browser by sniffing for a css class we added
99 * using javascript added by the action plugin; this is an edge case because
100 * browsers that support javascript generally support css as well.
101 *
102 * @returns {Boolean} true when the browser supports css (and implicitly
103 *          javascript)
104 */
105function olTestCSSsupport() {
106	return (jQuery('.olCSSsupported').length > 0);
107}
108
109/**
110 * Creates a DocumentFragment to insert into the dom.
111 *
112 * @param mapid
113 *            id for the map div
114 * @param width
115 *            width for the map div
116 * @param height
117 *            height for the map div
118 * @returns a {DocumentFragment} element that can be injected into the dom
119 */
120function olCreateMaptag(mapid, width, height) {
121	var mEl = '<div id="' + mapid + '-olContainer" class="olContainer olWebOnly">' + '<div id="' + mapid
122			+ '-olToolbar" class="olToolbar"></div>' + '<div class="clearer"></div>' + '<div id="' + mapid
123			+ '" tabindex="0" style="width:' + width + ';height:' + height + ';" class="olMap">'
124			+ '<a class="olAccesskey" href="" accesskey="1" onclick="document.getElementById(&quot;' + mapid
125			+ '&quot;).focus(); return false;" title="' + OpenLayers.i18n("activate_map") + '">'
126			+ OpenLayers.i18n("activate_map") + '</a>' + '</div>' + '<div id="' + mapid + '-olStatusBar" style="width:'
127			+ width + ';"class="olStatusBarContainer">' + '<div id="' + mapid
128			+ '-statusbar-scale" class="olStatusBar olStatusBarScale">scale</div>'
129			// + '<div id="' + mapid + '-statusbar-link" class="olStatusBar
130			// olStatusBarPermalink">' + '<a href="" id="' + mapid +
131			// '-statusbar-link-ref">link</a></div>'
132			+ '<div id="' + mapid + '-statusbar-mouseposition" class="olStatusBar olStatusBarMouseposition"></div>'
133			+ '<div id="' + mapid + '-statusbar-projection" class="olStatusBar olStatusBarProjection">proj</div>'
134			+ '<div id="' + mapid + '-statusbar-text" class="olStatusBar olStatusBarText">txt</div>' + '</div></div>',
135	// fragment
136	frag = document.createDocumentFragment(),
137	// temp node
138	temp = document.createElement('div');
139	temp.innerHTML = mEl;
140	while (temp.firstChild) {
141		frag.appendChild(temp.firstChild);
142	}
143	return frag;
144}
145
146/**
147 * Create the map based on the params given.
148 *
149 * @param {Object}
150 *            mapOpts MapOptions hash {id:'olmap', width:500px, height:500px,
151 *            lat:6710200, lon:506500, zoom:13, toolbar:1, statusbar:1,
152 *            controls:1, poihoverstyle:1, baselyr:'', kmlfile:'', gpxfile:'',
153 *            geojsonfile, summary:''}
154 * @param {Array}
155 *            OLmapPOI array with POI's [ {lat:6710300,lon:506000,txt:'instap
156 *            punt',angle:180,opacity:.9,img:'', rowId:n},... ]);
157 *
158 * @return {OpenLayers.Map} the created map
159 */
160function createMap(mapOpts, OLmapPOI) {
161	if (!olEnable) {
162		return;
163	}
164	if (!olTestCSSsupport()) {
165		olEnable = false;
166		return;
167	}
168
169	var DocBase = DOKU_BASE;
170
171	OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
172	// OpenLayers.Layer.Vector.prototype.renderers = ["SVG", "VML"];
173
174	// find map element location
175	var cleartag = document.getElementById(mapOpts.id + '-clearer');
176	if (cleartag === null) {
177		return;
178	}
179	// create map element and add to document
180	var fragment = olCreateMaptag(mapOpts.id, mapOpts.width, mapOpts.height);
181	cleartag.parentNode.insertBefore(fragment, cleartag);
182
183	/** dynamic map extent. */
184	var extent = new OpenLayers.Bounds(),
185
186	/** map. */
187	m = new OpenLayers.Map({
188		div : mapOpts.id,
189		projection : 'EPSG:900913',
190		displayProjection : new OpenLayers.Projection("EPSG:4326"),
191		numZoomLevels : 22,
192		controls : [],
193		theme : null,
194		tileManager : new OpenLayers.TileManager()
195	});
196
197	if (osmEnable) {
198		/* add OSM map layers */
199		m.addLayer(new OpenLayers.Layer.OSM();
200
201		m.addLayer(new OpenLayersMap.Layer.OCM());
202		/* open cycle map */
203		m.addLayer(new OpenLayers.Layer.OCM("transport", [
204				"http://a.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png",
205				"http://b.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png",
206				"http://c.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png" ], {
207			visibility : mapOpts.baselyr === "transport"
208		}));
209		m.addLayer(new OpenLayers.Layer.OCM("landscape", [
210				"http://a.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png",
211				"http://b.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png",
212				"http://c.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png" ], {
213			visibility : mapOpts.baselyr === "landscape"
214		}));
215
216		m.addLayer(new OpenLayersMap.Layer.CloudMade());
217		m.addLayer(new OpenLayersMap.Layer.CloudMade("cloudmade fresh", [
218				"http://a.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png",
219				"http://b.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png",
220				"http://c.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png" ], {
221			visibility : mapOpts.baselyr === "cloudmade fresh"
222		}));
223
224		m.addLayer(new OpenLayers.Layer.OSM(
225				"hike and bike map", "http://toolserver.org/tiles/hikebike/${z}/${x}/${y}.png", {
226					visibility : mapOpts.baselyr === "hike and bike map",
227					tileOptions : {
228						crossOriginKeyword : null
229					}
230				}));
231	}
232	/*
233	 * add MapQuest map layers, see:
234	 * http://developer.mapquest.com/web/products/open/map
235	 */
236	if (mqEnable) {
237		m.addLayer(new OpenLayersMap.Layer.MapQuest());
238		m.addLayer(new OpenLayersMap.Layer.MapQuest("mapquest sat", [
239				"http://otile1.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg",
240				"http://otile2.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg",
241				"http://otile3.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg",
242				"http://otile4.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg" ], {
243			// note that global coverage is provided at zoom levels 0-11. Zoom
244			// Levels 12+ are provided only in the United States (lower 48).
245			numZoomLevels : 12,
246			visibility : mapOpts.baselyr === "mapquest sat"
247		}));
248
249	}
250
251	if (gEnable) {
252		/* load google maps */
253		try {
254			m.addLayer(new OpenLayers.Layer.Google("google relief", {
255				type : google.maps.MapTypeId.TERRAIN,
256				// transitionEffect : "resize",
257				numZoomLevels : 16,
258				animationEnabled : true,
259				visibility : mapOpts.baselyr === "google relief"
260			}));
261			m.addLayer(new OpenLayers.Layer.Google("google sat", {
262				type : google.maps.MapTypeId.SATELLITE,
263				// transitionEffect : "resize",
264				// numZoomLevels : 22,
265				animationEnabled : true,
266				visibility : mapOpts.baselyr === "google sat"
267			}));
268			m.addLayer(new OpenLayers.Layer.Google("google hybrid", {
269				type : google.maps.MapTypeId.HYBRID,
270				// transitionEffect : "resize",
271				// numZoomLevels : 20,
272				animationEnabled : true,
273				visibility : mapOpts.baselyr === "google hybrid"
274			}));
275			m.addLayer(new OpenLayers.Layer.Google("google road", {
276				// transitionEffect : "resize",
277				// numZoomLevels : 20,
278				animationEnabled : true,
279				visibility : mapOpts.baselyr === "google road"
280			}));
281		} catch (ol_err1) {
282			Openlayers.Console.userError('Error loading Google maps' + ol_err1);
283		}
284	}
285
286	if (bEnable && bApiKey !== '') {
287		try {
288			/* add Bing tiles */
289			m.addLayer(new OpenLayers.Layer.Bing({
290				key : bApiKey,
291				type : "Road",
292				name : "bing road",
293				visibility : mapOpts.baselyr === "bing road",
294				wrapDateLine : true,
295				attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">'
296						+ 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}'
297						+ '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>'
298			}));
299			m.addLayer(new OpenLayers.Layer.Bing({
300				key : bApiKey,
301				type : "Aerial",
302				name : "bing sat",
303				visibility : mapOpts.baselyr === "bing sat",
304				wrapDateLine : true,
305				attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">'
306						+ 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}'
307						+ '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>'
308			}));
309			m.addLayer(new OpenLayers.Layer.Bing({
310				key : bApiKey,
311				type : "AerialWithLabels",
312				name : "bing hybrid",
313				visibility : mapOpts.baselyr === "bing hybrid",
314				wrapDateLine : true,
315				attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">'
316						+ 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}'
317						+ '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>'
318			}));
319		} catch (ol_errBing) {
320			Openlayers.Console.userError('Error loading Bing maps: ' + ol_errBing);
321		}
322	}
323
324	m.setCenter(new OpenLayers.LonLat(mapOpts.lon, mapOpts.lat).transform(m.displayProjection, m.projection),
325			mapOpts.zoom);
326	extent.extend(m.getExtent());
327
328	// change/set alternative baselyr
329	try {
330		m.setBaseLayer(((m.getLayersByName(mapOpts.baselyr))[0]));
331	} catch (ol_err4) {
332		m.setBaseLayer(m.layers[0]);
333	}
334
335	m.addControls([ new OpenLayers.Control.ScaleLine({
336		geodesic : true
337	}), new OpenLayers.Control.KeyboardDefaults({
338		observeElement : mapOpts.id
339	}), new OpenLayers.Control.Navigation(), ]);
340
341	if (mapOpts.controls === 1) {
342		/* add base controls to map */
343		m.addControls([ new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.Graticule({
344			visible : false
345		}), new OpenLayersMap.Control.OverviewMap(), new OpenLayers.Control.PanZoomBar() ]);
346
347		// add hillshade, since this is off by default only add when we have a
348		// layerswitcher
349		m.addLayer(new OpenLayers.Layer.OSM("Hillshade", "http://toolserver.org/~cmarqu/hill/${z}/${x}/${y}.png", {
350			isBaseLayer : false,
351			transparent : true,
352			visibility : false,
353			displayOutsideMaxExtent : true,
354			attribution : '',
355			tileOptions : {
356				crossOriginKeyword : null
357			}
358		}));
359	}
360
361	if (mapOpts.statusbar === 1) {
362		// statusbar control: permalink
363		// m.addControl(new OpenLayers.Control.Permalink(mapOpts.id +
364		// '-statusbar-link-ref'));
365
366		// statusbar control: mouse pos.
367		m.addControl(new OpenLayers.Control.MousePosition({
368			'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-mouseposition')
369		}));
370		// statusbar control: scale
371		m.addControl(new OpenLayers.Control.Scale(mapOpts.id + '-statusbar-scale'));
372		// statusbar control: attribution
373		m.addControl(new OpenLayers.Control.Attribution({
374			'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-text')
375		}));
376		// statusbar control: projection
377		OpenLayers.Util.getElement(mapOpts.id + '-statusbar-projection').innerHTML = m.displayProjection;
378	} else {
379		OpenLayers.Util.getElement(mapOpts.id + '-olStatusBar').display = 'none';
380	}
381
382	if (mapOpts.toolbar === 1) {
383		// add buttons + panel
384		var /* zoom in btn */
385		zoomin = new OpenLayers.Control.ZoomBox({
386			title : OpenLayers.i18n("zoom_in")
387		}), /* zoom out btn */
388		zoomout = new OpenLayers.Control.ZoomBox({
389			out : true,
390			title : OpenLayers.i18n("zoom_out"),
391			displayClass : "olControlZoomOut"
392		}), /* pan btn */
393		pan = new OpenLayers.Control.DragPan({
394			title : OpenLayers.i18n("move")
395		}), /* do "nothing" button... */
396		info = new OpenLayers.Control.Button({
397			type : OpenLayers.Control.TYPE_TOOL,
398			displayClass : "olControlFeatureInfo",
399			title : OpenLayers.i18n("info")
400		}), /* navigation history btns */
401		nav = new OpenLayers.Control.NavigationHistory();
402		m.addControl(nav);
403		var panel = new OpenLayers.Control.Panel({
404			defaultControl : pan,
405			displayClass : "olToolbar",
406			"div" : OpenLayers.Util.getElement(mapOpts.id + "-olToolbar")
407		});
408		panel.addControls([ zoomin, zoomout, pan, info, nav.next, nav.previous ]);
409		m.addControl(panel);
410	} else {
411		OpenLayers.Util.getElement(mapOpts.id + '-olToolbar').display = 'none';
412	}
413
414	if (OLmapPOI.length > 0) {
415		var markers = new OpenLayers.Layer.Vector("POI", {
416			styleMap : new OpenLayers.StyleMap({
417				"default" : {
418					externalGraphic : "${img}",
419					graphicHeight : 16,
420					graphicWidth : 16,
421					graphicXOffset : 0,
422					graphicYOffset : -8,
423					graphicOpacity : "${opacity}",
424					rotation : "${angle}",
425					backgroundGraphic : DocBase + "lib/plugins/openlayersmap/icons/marker_shadow.png",
426					backgroundXOffset : 0,
427					backgroundYOffset : -4,
428					backgroundRotation : "${angle}",
429					pointRadius : 10,
430					labelXOffset : 8,
431					labelYOffset : 8,
432					labelAlign : "lb",
433					label : "${label}",
434					// fontColor : "",
435					fontFamily : "monospace",
436					fontSize : "12px",
437					fontWeight : "bold"
438				},
439				"select" : {
440					cursor : "crosshair",
441					externalGraphic : DocBase + "lib/plugins/openlayersmap/icons/marker-red.png",
442					graphicHeight : 16,
443					graphicWidth : 16,
444					graphicXOffset : 0,
445					graphicYOffset : -8,
446					graphicOpacity : 1.0,
447					rotation : "${angle}"
448				}
449			}),
450			isBaseLayer : false,
451			rendererOptions : {
452				yOrdering : true
453			}
454		});
455		m.addLayer(markers);
456		var features = [];
457		for ( var j = 0; j < OLmapPOI.length; j++) {
458			var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(OLmapPOI[j].lon, OLmapPOI[j].lat)
459					.transform(m.displayProjection, m.projection), {
460				angle : OLmapPOI[j].angle,
461				opacity : OLmapPOI[j].opacity,
462				img : DocBase + "lib/plugins/openlayersmap/icons/" + OLmapPOI[j].img,
463				label : OLmapPOI[j].rowId
464			});
465			feat.data = {
466				name : OLmapPOI[j].txt,
467				rowId : OLmapPOI[j].rowId
468			};
469			features.push(feat);
470		}
471		markers.addFeatures(features);
472		extent.extend(markers.getDataExtent());
473		m.zoomToExtent(extent);
474	}
475
476	/* GPX layer */
477	if (mapOpts.gpxfile.length > 0) {
478		var layerGPX = new OpenLayers.Layer.Vector("GPS route", {
479			protocol : new OpenLayers.Protocol.HTTP({
480				url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.gpxfile,
481				format : new OpenLayers.Format.GPX({
482					extractWaypoints : true,
483					extractTracks : true,
484					extractStyles : true,
485					extractAttributes : true,
486					handleHeight : true,
487					maxDepth : 3
488				})
489			}),
490			style : {
491				strokeColor : "#0000FF",
492				strokeWidth : 3,
493				strokeOpacity : 0.7,
494				pointRadius : 4,
495				fillColor : "#0099FF",
496				fillOpacity : 0.7
497			// , label:"${name}"
498			},
499			projection : new OpenLayers.Projection("EPSG:4326"),
500			strategies : [ new OpenLayers.Strategy.Fixed() ]
501		});
502		m.addLayer(layerGPX);
503		layerGPX.events.register('loadend', m, function() {
504			extent.extend(layerGPX.getDataExtent());
505			m.zoomToExtent(extent);
506		});
507	}
508
509	/* GeoJSON layer */
510	if (mapOpts.geojsonfile.length > 0) {
511		var layerGJS = new OpenLayers.Layer.Vector("json data", {
512			protocol : new OpenLayers.Protocol.HTTP({
513				url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.geojsonfile,
514				format : new OpenLayers.Format.GeoJSON({
515					ignoreExtraDims : true
516				})
517			}),
518			style : {
519				strokeColor : "#FF00FF",
520				strokeWidth : 3,
521				strokeOpacity : 0.7,
522				pointRadius : 4,
523				fillColor : "#FF99FF",
524				fillOpacity : 0.7
525			// , label:"${name}"
526			},
527			projection : new OpenLayers.Projection("EPSG:4326"),
528			strategies : [ new OpenLayers.Strategy.Fixed() ]
529		});
530		m.addLayer(layerGJS);
531		layerGJS.events.register('loadend', m, function() {
532			extent.extend(layerGJS.getDataExtent());
533			m.zoomToExtent(extent);
534		});
535	}
536
537	/* KML layer */
538	if (mapOpts.kmlfile.length > 0) {
539		var layerKML = new OpenLayers.Layer.Vector("KML file", {
540			protocol : new OpenLayers.Protocol.HTTP({
541				url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.kmlfile,
542				format : new OpenLayers.Format.KML({
543					extractStyles : true,
544					extractAttributes : true,
545					maxDepth : 3
546				})
547			}),
548			style : {
549				label : "${name}"
550			},
551			projection : new OpenLayers.Projection("EPSG:4326"),
552			strategies : [ new OpenLayers.Strategy.Fixed() ]
553		});
554		m.addLayer(layerKML);
555		layerKML.events.register('loadend', m, function() {
556			extent.extend(layerKML.getDataExtent());
557			m.zoomToExtent(extent);
558		});
559	}
560
561	// selectcontrol for layers
562	if ((m.getLayersByClass('OpenLayers.Layer.GML').length > 0)
563			|| m.getLayersByClass('OpenLayers.Layer.Vector').length > 0) {
564		selectControl = new OpenLayers.Control.SelectFeature((m.getLayersByClass('OpenLayers.Layer.Vector')).concat(m
565				.getLayersByClass('OpenLayers.Layer.GML')), {
566			hover : mapOpts.poihoverstyle,
567			onSelect : onFeatureSelect,
568			onUnselect : onFeatureUnselect
569		});
570		m.addControl(selectControl);
571		selectControl.activate();
572	}
573	return m;
574}
575
576var olTimerId = -1;
577
578/** init. */
579function olInit() {
580	// TODO: check is this is still needed now that we have jQuery
581	if (navigator.userAgent.indexOf('MSIE') !== -1) {
582		if (olTimerId === -1) {
583			olTimerId = setTimeout("olInit()", 3000);
584			olEnable = false;
585		} else {
586			clearTimeout(olTimerId);
587			olEnable = true;
588		}
589	}
590
591	if (olEnable) {
592		var _i = 0;
593		// create the maps in the page
594		for (_i = 0; _i < olMapData.length; _i++) {
595			olMaps[olMapData[_i].mapOpts.id] = createMap(olMapData[_i].mapOpts, olMapData[_i].poi);
596		}
597		// hide the table(s) with POI by giving it a print-only style
598		var tbls = jQuery('.olPOItableSpan');
599		for (_i = 0; _i < tbls.length; _i++) {
600			tbls[_i].className += ' olPrintOnly';
601		}
602		// hide the static map image(s) by giving it a print only style
603		var statImgs = jQuery('.olStaticMap');
604		for (_i = 0; _i < statImgs.length; _i++) {
605			statImgs[_i].className += ' olPrintOnly';
606		}
607	}
608}
609
610/**
611 * ol api flag.
612 *
613 * @type {Boolean}
614 */
615var olEnable = false,
616/**
617 * An array with data for each map in the page.
618 *
619 * @type {Array}
620 */
621olMapData = [],
622/**
623 * Holds a reference to all of the maps on this page with the map's id as key.
624 * Can be used as an extension point.
625 *
626 * @type {Object}
627 */
628olMaps = new Object(),
629/**
630 * MapQuest tiles flag.
631 *
632 * @type {Boolean}
633 */
634mqEnable = false,
635/**
636 * google map api flag.
637 *
638 * @type {Boolean}
639 */
640gEnable = false,
641/**
642 * Bing tiles flag.
643 *
644 * @type {Boolean}
645 */
646bEnable = false,
647/**
648 * Bing API key.
649 *
650 * @type {String}
651 */
652bApiKey = '',
653/**
654 * OSM tiles flag.
655 *
656 * @type {Boolean}
657 */
658osmEnable = true,
659/**
660 * CSS support flag.
661 *
662 * @type {Boolean}
663 */
664olCSSEnable = true;
665/**
666 * yahoo map api flag.
667 *
668 * @type {Boolean}
669 */
670// yEnable = false;
671/* register olInit to run with onload event. */
672jQuery(olInit);
673