xref: /plugin/openlayersmap/script.js (revision 529d08d06f45b42397bef24e088bd04fd0e632a4)
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 OpenLayersMap.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 OpenLayersMap.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 OpenLayersMap.Control.Zoom() ]);
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		});
401		var panel = new OpenLayers.Control.Panel({
402			defaultControl : pan,
403			displayClass : "olToolbar",
404			"div" : OpenLayers.Util.getElement(mapOpts.id + "-olToolbar")
405		});
406		panel.addControls([ zoomin, zoomout, pan, info ]);
407		m.addControl(panel);
408	} else {
409		OpenLayers.Util.getElement(mapOpts.id + '-olToolbar').display = 'none';
410	}
411
412	if (OLmapPOI.length > 0) {
413		var markers = new OpenLayers.Layer.Vector("POI", {
414			styleMap : new OpenLayers.StyleMap({
415				"default" : {
416					externalGraphic : "${img}",
417					graphicHeight : 16,
418					graphicWidth : 16,
419					graphicXOffset : 0,
420					graphicYOffset : -8,
421					graphicOpacity : "${opacity}",
422					rotation : "${angle}",
423					backgroundGraphic : DocBase + "lib/plugins/openlayersmap/icons/marker_shadow.png",
424					backgroundXOffset : 0,
425					backgroundYOffset : -4,
426					backgroundRotation : "${angle}",
427					pointRadius : 10,
428					labelXOffset : 8,
429					labelYOffset : 8,
430					labelAlign : "lb",
431					label : "${label}",
432					// fontColor : "",
433					fontFamily : "monospace",
434					fontSize : "12px",
435					fontWeight : "bold"
436				},
437				"select" : {
438					cursor : "crosshair",
439					externalGraphic : DocBase + "lib/plugins/openlayersmap/icons/marker-red.png",
440					graphicHeight : 16,
441					graphicWidth : 16,
442					graphicXOffset : 0,
443					graphicYOffset : -8,
444					graphicOpacity : 1.0,
445					rotation : "${angle}"
446				}
447			}),
448			isBaseLayer : false,
449			rendererOptions : {
450				yOrdering : true
451			}
452		});
453		m.addLayer(markers);
454		var features = [];
455		for ( var j = 0; j < OLmapPOI.length; j++) {
456			var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(OLmapPOI[j].lon, OLmapPOI[j].lat)
457					.transform(m.displayProjection, m.projection), {
458				angle : OLmapPOI[j].angle,
459				opacity : OLmapPOI[j].opacity,
460				img : DocBase + "lib/plugins/openlayersmap/icons/" + OLmapPOI[j].img,
461				label : OLmapPOI[j].rowId
462			});
463			feat.data = {
464				name : OLmapPOI[j].txt,
465				rowId : OLmapPOI[j].rowId
466			};
467			features.push(feat);
468		}
469		markers.addFeatures(features);
470		extent.extend(markers.getDataExtent());
471		m.zoomToExtent(extent);
472	}
473
474	/* GPX layer */
475	if (mapOpts.gpxfile.length > 0) {
476		var layerGPX = new OpenLayers.Layer.Vector("GPS route", {
477			protocol : new OpenLayers.Protocol.HTTP({
478				url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.gpxfile,
479				format : new OpenLayers.Format.GPX({
480					extractWaypoints : true,
481					extractTracks : true,
482					extractStyles : true,
483					extractAttributes : true,
484					handleHeight : true,
485					maxDepth : 3
486				})
487			}),
488			style : {
489				strokeColor : "#0000FF",
490				strokeWidth : 3,
491				strokeOpacity : 0.7,
492				pointRadius : 4,
493				fillColor : "#0099FF",
494				fillOpacity : 0.7
495			// , label:"${name}"
496			},
497			projection : new OpenLayers.Projection("EPSG:4326"),
498			strategies : [ new OpenLayers.Strategy.Fixed() ]
499		});
500		m.addLayer(layerGPX);
501		layerGPX.events.register('loadend', m, function() {
502			extent.extend(layerGPX.getDataExtent());
503			m.zoomToExtent(extent);
504		});
505	}
506
507	/* GeoJSON layer */
508	if (mapOpts.geojsonfile.length > 0) {
509		var layerGJS = new OpenLayers.Layer.Vector("json data", {
510			protocol : new OpenLayers.Protocol.HTTP({
511				url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.geojsonfile,
512				format : new OpenLayers.Format.GeoJSON({
513					ignoreExtraDims : true
514				})
515			}),
516			style : {
517				strokeColor : "#FF00FF",
518				strokeWidth : 3,
519				strokeOpacity : 0.7,
520				pointRadius : 4,
521				fillColor : "#FF99FF",
522				fillOpacity : 0.7
523			// , label:"${name}"
524			},
525			projection : new OpenLayers.Projection("EPSG:4326"),
526			strategies : [ new OpenLayers.Strategy.Fixed() ]
527		});
528		m.addLayer(layerGJS);
529		layerGJS.events.register('loadend', m, function() {
530			extent.extend(layerGJS.getDataExtent());
531			m.zoomToExtent(extent);
532		});
533	}
534
535	/* KML layer */
536	if (mapOpts.kmlfile.length > 0) {
537		var layerKML = new OpenLayers.Layer.Vector("KML file", {
538			protocol : new OpenLayers.Protocol.HTTP({
539				url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.kmlfile,
540				format : new OpenLayers.Format.KML({
541					extractStyles : true,
542					extractAttributes : true,
543					maxDepth : 3
544				})
545			}),
546			style : {
547				label : "${name}"
548			},
549			projection : new OpenLayers.Projection("EPSG:4326"),
550			strategies : [ new OpenLayers.Strategy.Fixed() ]
551		});
552		m.addLayer(layerKML);
553		layerKML.events.register('loadend', m, function() {
554			extent.extend(layerKML.getDataExtent());
555			m.zoomToExtent(extent);
556		});
557	}
558
559	// selectcontrol for layers
560	if ((m.getLayersByClass('OpenLayers.Layer.GML').length > 0)
561			|| m.getLayersByClass('OpenLayers.Layer.Vector').length > 0) {
562		selectControl = new OpenLayers.Control.SelectFeature((m.getLayersByClass('OpenLayers.Layer.Vector')).concat(m
563				.getLayersByClass('OpenLayers.Layer.GML')), {
564			hover : mapOpts.poihoverstyle,
565			onSelect : onFeatureSelect,
566			onUnselect : onFeatureUnselect
567		});
568		m.addControl(selectControl);
569		selectControl.activate();
570	}
571	return m;
572}
573
574// var olTimerId = -1;
575
576/** init. */
577function olInit() {
578	// TODO: check is this is still needed now that we have jQuery
579	// if (navigator.userAgent.indexOf('MSIE') !== -1) {
580	// if (olTimerId === -1) {
581	// olTimerId = setTimeout("olInit()", 3000);
582	// olEnable = false;
583	// } else {
584	// clearTimeout(olTimerId);
585	// olEnable = true;
586	// }
587	// }
588
589	if (olEnable) {
590		var _i = 0;
591		// create the maps in the page
592		for (_i = 0; _i < olMapData.length; _i++) {
593			olMaps[olMapData[_i].mapOpts.id] = createMap(olMapData[_i].mapOpts, olMapData[_i].poi);
594		}
595		// hide the table(s) with POI by giving it a print-only style
596		var tbls = jQuery('.olPOItableSpan');
597		for (_i = 0; _i < tbls.length; _i++) {
598			tbls[_i].className += ' olPrintOnly';
599		}
600		// hide the static map image(s) by giving it a print only style
601		var statImgs = jQuery('.olStaticMap');
602		for (_i = 0; _i < statImgs.length; _i++) {
603			statImgs[_i].className += ' olPrintOnly';
604		}
605	}
606}
607
608/**
609 * ol api flag.
610 *
611 * @type {Boolean}
612 */
613var olEnable = false,
614/**
615 * An array with data for each map in the page.
616 *
617 * @type {Array}
618 */
619olMapData = [],
620/**
621 * Holds a reference to all of the maps on this page with the map's id as key.
622 * Can be used as an extension point.
623 *
624 * @type {Object}
625 */
626olMaps = new Object(),
627/**
628 * MapQuest tiles flag.
629 *
630 * @type {Boolean}
631 */
632mqEnable = false,
633/**
634 * google map api flag.
635 *
636 * @type {Boolean}
637 */
638gEnable = false,
639/**
640 * Bing tiles flag.
641 *
642 * @type {Boolean}
643 */
644bEnable = false,
645/**
646 * Bing API key.
647 *
648 * @type {String}
649 */
650bApiKey = '',
651/**
652 * OSM tiles flag.
653 *
654 * @type {Boolean}
655 */
656osmEnable = true,
657/**
658 * CSS support flag.
659 *
660 * @type {Boolean}
661 */
662olCSSEnable = true;
663/**
664 * yahoo map api flag.
665 *
666 * @type {Boolean}
667 */
668// yEnable = false;
669/* register olInit to run with onload event. */
670jQuery(olInit);
671