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