xref: /plugin/openlayersmap/script.js (revision b83d5dc13db5b7761cfca725c006dbc3c10d767b)
1/*
2 * Copyright (c) 2008-2011 Mark C. Prins <mc.prins@gmail.com>
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 <mc.prins@gmail.com>
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 *            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
48					.getLonLatFromViewPortPx(this.handlers.feature.evt.xy);
49		} catch (anErr) {
50			OpenLayers.Console
51					.warn("unable to get event position; reverting to boundingbox center.");
52			pPos = selectedFeature.geometry.getBounds().getCenterLonLat();
53		}
54	}
55
56	var pContent = '<div clas="spacer">&nbsp;</div>';
57	if (feature.data.rowId !== undefined) {
58		pContent += '<span class="rowId">' + feature.data.rowId + ': </span>';
59	}
60	if (feature.data.name !== undefined) {
61		pContent += '<span class="txt">' + feature.data.name + '</span>';
62	}
63	if (feature.data.ele !== undefined) {
64		pContent += "<div>elevation: " + feature.data.ele + "</div>";
65	}
66	if (feature.data.type !== undefined) {
67		pContent += "<div>" + feature.data.type + "></div>";
68	}
69	if (feature.data.time !== undefined) {
70		pContent += "<div>time: " + feature.data.time + "</div>";
71	}
72	if (feature.data.description !== undefined) {
73		pContent += "<div>" + feature.data.description + "</div>";
74	}
75
76	if (pContent.length > 0) {
77		// only show when there is something to show...
78		var popup = new OpenLayers.Popup.FramedCloud("olPopup", pPos, null,
79				pContent, null, true, function() {
80					selectControl.unselect(selectedFeature);
81				});
82		feature.popup = popup;
83		feature.layer.map.addPopup(popup);
84	}
85}
86
87/**
88 * handle feature unselect event. remove & destroy the popup.
89 *
90 * @param {OpenLayers.Feature.Vector}
91 *            the un-selected feature
92 */
93function onFeatureUnselect(feature) {
94	if (feature.popup !== null) {
95		feature.layer.map.removePopup(feature.popup);
96		feature.popup.destroy();
97		feature.popup = null;
98	}
99}
100/**
101 * Test for css support in the browser by sniffing for a css class we added using
102 * javascript added by the action plugin; this is an edge case because browsers
103 * that support javascript generally support css as well.
104 *
105 * @returns {Boolean} true when the browser supports css (and implicitly
106 *          javascript)
107 */
108function olTestCSSsupport() {
109	//return (((getElementsByClass('olCSSsupported', null, null))).length > 0);
110	return (jQuery('.olCSSsupported').length > 0);
111}
112
113/**
114 * creates a DocumentFragment to insert into the dom.
115 *
116 * @param mapid
117 *            id for the map div
118 * @param width
119 *            width for the map div
120 * @param height
121 *            height for the map div
122 * @returns a {DocumentFragment} element that can be injected into the dom
123 */
124function olCreateMaptag(mapid, width, height) {
125	var mEl = '<div id="'
126			+ mapid
127			+ '-olContainer" class="olContainer olWebOnly">'
128			+ '<div id="'
129			+ mapid
130			+ '-olToolbar" class="olToolbar"></div>'
131			+ '<div class="clearer"></div>'
132			+ '<div id="'
133			+ mapid
134			+ '" style="width:'
135			+ width
136			+ ';height:'
137			+ height
138			+ ';" class="olMap"></div>'
139			+ '<div id="'
140			+ mapid
141			+ '-olStatusBar" class="olStatusBarContainer">'
142			+ '<div id="'
143			+ mapid
144			+ '-statusbar-scale" class="olStatusBar olStatusBarScale">scale</div>'
145			+ '<div id="'
146			+ mapid
147			+ '-statusbar-link" class="olStatusBar olStatusBarPermalink"><a href="" id="'
148			+ mapid
149			+ '-statusbar-link-ref">map link</a></div>'
150			+ '<div id="'
151			+ mapid
152			+ '-statusbar-mouseposition" class="olStatusBar olStatusBarMouseposition"></div>'
153			+ '<div id="'
154			+ mapid
155			+ '-statusbar-projection" class="olStatusBar olStatusBarProjection">proj</div>'
156			+ '<div id="' + mapid
157			+ '-statusbar-text" class="olStatusBar olStatusBarText">txt</div>'
158			+ '</div>\n</div>',
159	// fragment
160	frag = document.createDocumentFragment(),
161	// temp node
162	temp = document.createElement('div');
163	temp.innerHTML = mEl;
164	while (temp.firstChild) {
165		frag.appendChild(temp.firstChild);
166	}
167	return frag;
168}
169
170/**
171 * create the map based on the params given.
172 *
173 * @param {Object}mapOpts
174 *            MapOptions hash {id:'olmap', width:500px, height:500px,
175 *            lat:6710200, lon:506500, zoom:13, toolbar:1, statusbar:1,
176 *            controls:1, poihoverstyle:1, baselyr:'', kmlfile:'', gpxfile:'',
177 *            summary:''}
178 * @param {Array}OLmapPOI
179 *            array with POI's [ {lat:6710300,lon:506000,txt:'instap
180 *            punt',angle:180,opacity:.9,img:'', rowId:n},... ]);
181 *
182 */
183function createMap(mapOpts, OLmapPOI) {
184	if (!olEnable) {
185		return;
186	}
187	if (!olTestCSSsupport()) {
188		olEnable = false;
189		return;
190	}
191
192	var DocBase = DOKU_BASE;
193
194	OpenLayers.IMAGE_RELOAD_ATTEMPTS = 4;
195	OpenLayers.Util.onImageLoadErrorColor = 'pink';
196	OpenLayers.Util.onImageLoadError = function() {
197		/* transparent gif */
198		// IE 8 complains w/ stack overflow... this.src =
199		// "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";
200		this.src = DocBase + "lib/plugins/openlayersmap/lib/img/blank.gif";
201	};
202
203	// OpenLayers.Layer.Vector.prototype.renderers = ["SVG2", "VML", "Canvas"];
204
205	// find map element location
206	var cleartag = document.getElementById(mapOpts.id + '-clearer');
207	if (cleartag === null) {
208		return;
209	}
210	// create map element and add to document
211	var fragment = olCreateMaptag(mapOpts.id, mapOpts.width, mapOpts.height);
212	cleartag.parentNode.insertBefore(fragment, cleartag);
213
214	/** dynamic map extent. */
215	var extent = new OpenLayers.Bounds(),
216
217	/** map. */
218	m = new OpenLayers.Map(mapOpts.id, {
219		projection : new OpenLayers.Projection('EPSG:900913'),
220		displayProjection : new OpenLayers.Projection('EPSG:4326'),
221		units : 'm',
222		maxResolution : 156543.0339,
223		maxExtent : new OpenLayers.Bounds(-20037508.34, -20037508.34,
224				20037508.34, 20037508.34),
225		numZoomLevels : 19,
226		// panDuration : 100,
227		controls : [ /* new OpenLayers.Control.LoadingPanel(), */
228		new OpenLayers.Control.KeyboardDefaults(),
229				new OpenLayers.Control.Navigation({
230					dragPanOptions : {
231						enableKinetic : true
232					}
233				}), new OpenLayers.Control.ScaleLine({
234					geodesic : true
235				}) ],
236		theme : null
237	});
238	if (osmEnable) {
239		/* add OSM map layers */
240		m.addLayer(new OpenLayers.Layer.OSM("OpenStreetMap"), {
241			transitionEffect : 'resize',
242			visibility : false
243		});
244
245		m
246				.addLayer(
247						new OpenLayers.Layer.OSM(
248								"t@h",
249								[
250										"http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
251										"http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
252										"http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png" ]),
253						{
254							transitionEffect : 'resize',
255							visibility : false
256						});
257
258		m
259				.addLayer(
260						new OpenLayers.Layer.OSM(
261								"cycle map",
262								[
263										// "http://andy.sandbox.cloudmade.com/tiles/cycle/${z}/${x}/${y}.png",
264										"http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
265										"http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
266										"http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png" ]),
267						{
268							transitionEffect : 'resize',
269							attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, '
270									+ 'Tiles <a href="http://opencyclemap.org/" target="_blank">OpenCycleMap</a>'
271									+ '<img src="http://opencyclemap.org/favicon.ico" heigth="16" width="16"/>',
272							visibility : false
273						});
274
275		m
276				.addLayer(new OpenLayers.Layer.OSM(
277						"cloudmade map",
278						"http://tile.cloudmade.com/2f59745a6b525b4ebdb100891d5b6711/3/256/${z}/${x}/${y}.png",
279						{
280							transitionEffect : 'resize',
281							visibility : false
282						}));
283
284		m.addLayer(new OpenLayers.Layer.OSM("hike and bike map",
285				"http://toolserver.org/tiles/hikebike/${z}/${x}/${y}.png", {
286					transitionEffect : 'resize',
287					visibility : false
288				}));
289	}
290	/*
291	 * add MapQuest map layers, see:
292	 * http://developer.mapquest.com/web/products/open/map
293	 */
294	if (mqEnable) {
295		m
296				.addLayer(new OpenLayers.Layer.OSM(
297						"mapquest road",
298						[
299								"http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
300								"http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
301								"http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
302								"http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png" ],
303						{
304							transitionEffect : 'resize',
305							attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, '
306									+ 'Tiles <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>'
307									+ '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" heigth="14" width="14" alt="logo"/>',
308							visibility : false
309						}));
310		// note that global coverage is provided at zoom levels 0-11. Zoom
311		// Levels 12+ are provided only in the United States (lower 48).
312		m
313				.addLayer(new OpenLayers.Layer.OSM(
314						"mapquest sat",
315						[
316								"http://oatile1.mqcdn.com/naip/${z}/${x}/${y}.jpg",
317								"http://oatile2.mqcdn.com/naip/${z}/${x}/${y}.jpg",
318								"http://oatile3.mqcdn.com/naip/${z}/${x}/${y}.jpg",
319								"http://oatile4.mqcdn.com/naip/${z}/${x}/${y}.jpg" ],
320						{
321							transitionEffect : 'resize',
322							attribution : 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>'
323									+ '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" heigth="16" width="16">',
324							visibility : false,
325							numZoomLevels : 12
326						}));
327	}
328
329	/* open aerial map layers */
330	/*
331	 * turn this off; project is asleep:
332	 * https://sourceforge.net/tracker/?func=detail&aid=2897327&group_id=239475&atid=1110186
333	 * m.addLayer(new OpenLayers.Layer.XYZ("OpenAerialMap",
334	 * "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/${z}/${x}/${y}.jpg",
335	 * {name: "OpenStreetMap", attribution: "Data CC-By by <a
336	 * href='http://www.openaerialmap.org/licensing/'>OpenAerialMap</a>",
337	 * sphericalMercator: true, transitionEffect: 'resize'} ));
338	 */
339
340	if (gEnable) {
341		/* load google maps */
342		try {
343			m.addLayer(new OpenLayers.Layer.Google("google relief", {
344				type : google.maps.MapTypeId.TERRAIN,
345				// transitionEffect : 'resize',
346				numZoomLevels : 16,
347				animationEnabled : true,
348				visibility : false
349			}));
350			m.addLayer(new OpenLayers.Layer.Google("google sat", {
351				type : google.maps.MapTypeId.SATELLITE,
352				// transitionEffect : 'resize',
353				// numZoomLevels : 22,
354				animationEnabled : true,
355				visibility : false
356			}));
357			m.addLayer(new OpenLayers.Layer.Google("google hybrid", {
358				type : google.maps.MapTypeId.HYBRID,
359				// transitionEffect : 'resize',
360				// numZoomLevels : 20,
361				animationEnabled : true,
362				visibility : false
363			}));
364			m.addLayer(new OpenLayers.Layer.Google("google road", {
365				// transitionEffect : 'resize',
366				// numZoomLevels : 20,
367				animationEnabled : true,
368				visibility : false
369			}));
370		} catch (ol_err1) {
371			Openlayers.Console.userError('Error loading Google maps' + ol_err1);
372		}
373	}
374
375	// if (yEnable) {
376	// try {
377	// m.addLayer(new OpenLayers.Layer.Yahoo("yahoo", {
378	// 'type' : YAHOO_MAP_HYB,
379	// 'sphericalMercator' : true,
380	// transitionEffect : resize
381	// }));
382	// } catch (ol_err2) {
383	// }
384	// }
385
386	if (veEnable) {
387		try {
388			m.addLayer(new OpenLayers.Layer.VirtualEarth("ve", {
389				type : VEMapStyle.Hybrid,
390				sphericalMercator : true,
391				transitionEffect : 'resize',
392				visibility : false
393			}));
394		} catch (ol_err3) {
395			Openlayers.Console.userError('Error loading Virtual Earth maps: '
396					+ ol_err3);
397		}
398	}
399
400	if (bEnable && bApiKey !== '') {
401		try {
402			/* add Bing tiles */
403			m.addLayer(new OpenLayers.Layer.Bing({
404				key : bApiKey,
405				type : "Road",
406				name : 'bing road',
407				transitionEffect : 'resize',
408				visibility : false
409			}));
410			m.addLayer(new OpenLayers.Layer.Bing({
411				key : bApiKey,
412				type : "Aerial",
413				name : 'bing sat',
414				transitionEffect : 'resize',
415				visibility : false
416			}));
417			m.addLayer(new OpenLayers.Layer.Bing({
418				key : bApiKey,
419				type : "AerialWithLabels",
420				name : "bing hybrid",
421				transitionEffect : 'resize',
422				visibility : false
423			}));
424		} catch (ol_errBing) {
425			Openlayers.Console.userError('Error loading Bing maps: '
426					+ ol_errBing);
427		}
428	}
429
430	m.setCenter(new OpenLayers.LonLat(mapOpts.lon, mapOpts.lat).transform(
431			m.displayProjection, m.projection), mapOpts.zoom);
432	extent.extend(m.getExtent());
433
434	// change/set alternative baselyr
435	try {
436		m.setBaseLayer(((m.getLayersByName(mapOpts.baselyr))[0]));
437	} catch (ol_err4) {
438		m.setBaseLayer(m.layers[0]);
439	}
440
441	if (mapOpts.controls === 1) {
442		/* add base controls to map */
443		m.addControl(new OpenLayers.Control.LayerSwitcher({
444			roundedCorner : false,
445			roundedCornerColor : null
446		}));
447		m.addControl(new OpenLayers.Control.PanZoomBar());
448		m.addControl(new OpenLayers.Control.Graticule({
449			visible : false
450		}));
451
452		// add hillshade, since this is off by default only add when we have a
453		// layerswitcher
454		m.addLayer(new OpenLayers.Layer.OSM("Hillshade",
455				"http://toolserver.org/~cmarqu/hill/${z}/${x}/${y}.png", {
456					transitionEffect : 'resize',
457					isBaseLayer : false,
458					transparent : true,
459					visibility : false,
460					displayOutsideMaxExtent : true,
461					attribution : ''
462				}));
463
464		m.addControl(new OpenLayers.Control.OverviewMap({
465			size : new OpenLayers.Size(140, 140),
466			mapOptions : {
467				theme : null
468			},
469			layers : [ m.baseLayer.clone() ],
470			minRectSize : 10
471		}));
472	}
473
474	if (mapOpts.statusbar === 1) {
475		// statusbar control: permalink
476		m.addControl(new OpenLayers.Control.Permalink(mapOpts.id
477				+ '-statusbar-link-ref'));
478		// statusbar control: mouse pos.
479		// TODO kijken naar afronding met aNumber.toFixed(0)
480		m.addControl(new OpenLayers.Control.MousePosition({
481			'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-mouseposition')
482		}));
483		// statusbar control: scale
484		m.addControl(new OpenLayers.Control.Scale(mapOpts.id + '-statusbar-scale'));
485		// statusbar control: attribution
486		m.addControl(new OpenLayers.Control.Attribution({
487			'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-text')
488		}));
489		// statusbar control: projection
490		OpenLayers.Util.getElement(mapOpts.id + '-statusbar-projection').innerHTML = m.displayProjection;
491	} else {
492		OpenLayers.Util.getElement(mapOpts.id + '-olStatusBar').display = 'none';
493	}
494
495	if (mapOpts.toolbar === 1) {
496		// add buttons + panel
497		var /* zoom in btn */
498		zoomin = new OpenLayers.Control.ZoomBox({
499			title : "Zoom in"
500		}), /* zoom out btn */
501		zoomout = new OpenLayers.Control.ZoomBox({
502			out : true,
503			title : "Zoom uit",
504			displayClass : "olControlZoomOut"
505		}), /* pan btn */pan = new OpenLayers.Control.DragPan({
506			title : "Verschuif"
507		}), /* do "nothing" button... */info = new OpenLayers.Control.Button({
508			type : OpenLayers.Control.TYPE_TOOL,
509			displayClass : "olControlFeatureInfo",
510			title : "Info"
511		}), /* navigation history btns */
512		nav = new OpenLayers.Control.NavigationHistory();
513		m.addControl(nav);
514		var panel = new OpenLayers.Control.Panel({
515			defaultControl : pan,
516			displayClass : "olToolbar",
517			"div" : OpenLayers.Util.getElement(mapOpts.id + "-olToolbar")
518		});
519		panel
520				.addControls([ zoomin, zoomout, pan, info, nav.next,
521						nav.previous ]);
522		// panel.addControls([ nav.next, nav.previous ]);
523		m.addControl(panel);
524	} else {
525		OpenLayers.Util.getElement(mapOpts.id + '-olToolbar').display = 'none';
526	}
527
528	if (OLmapPOI.length > 0) {
529		var markers = new OpenLayers.Layer.Vector(
530				"POI",
531				{
532					styleMap : new OpenLayers.StyleMap(
533							{
534								"default" : {
535									externalGraphic : "${img}",
536									graphicHeight : 16,
537									graphicWidth : 16,
538									graphicXOffset : 0,
539									graphicYOffset : -8,
540									graphicOpacity : "${opacity}",
541									rotation : "${angle}",
542									backgroundGraphic : DocBase
543											+ "lib/plugins/openlayersmap/icons/marker_shadow.png",
544									backgroundXOffset : 0,
545									backgroundYOffset : -4,
546									backgroundRotation : "${angle}",
547									pointRadius : 10,
548									labelXOffset : 8,
549									labelYOffset : 8,
550									labelAlign : "lb",
551									label : "${label}",
552									// fontColor : "",
553									fontFamily : "monospace",
554									fontSize : "12px",
555									fontWeight : "bold"
556								},
557								"select" : {
558									cursor : "crosshair",
559									externalGraphic : DocBase
560											+ "lib/plugins/openlayersmap/icons/marker-red.png",
561									graphicHeight : 16,
562									graphicWidth : 16,
563									graphicXOffset : 0,
564									graphicYOffset : -8,
565									graphicOpacity : 1.0,
566									rotation : "${angle}"
567								}
568							}),
569					isBaseLayer : false,
570					rendererOptions : {
571						yOrdering : true
572					}
573				});
574		m.addLayer(markers);
575		var features = [];
576		var lonLat;
577		for ( var j = 0; j < OLmapPOI.length; j++) {
578			var feat = new OpenLayers.Feature.Vector(
579					new OpenLayers.Geometry.Point(OLmapPOI[j].lon,
580							OLmapPOI[j].lat).transform(m.displayProjection,
581							m.projection), {
582						angle : OLmapPOI[j].angle,
583						opacity : OLmapPOI[j].opacity,
584						img : DocBase + "lib/plugins/openlayersmap/icons/"
585								+ OLmapPOI[j].img,
586						label : OLmapPOI[j].rowId
587					});
588			feat.data = {
589				name : OLmapPOI[j].txt,
590				rowId : OLmapPOI[j].rowId
591			};
592			features.push(feat);
593		}
594		markers.addFeatures(features);
595		extent.extend(markers.getDataExtent());
596		m.zoomToExtent(extent);
597	}
598
599	/* GPX layer */
600	if (mapOpts.gpxfile.length > 0) {
601		var layerGPX = new OpenLayers.Layer.GML("GPS route", DocBase
602				+ "lib/exe/fetch.php?media=" + mapOpts.gpxfile, {
603			format : OpenLayers.Format.GPX,
604			formatOptions : {
605				extractWaypoints : true,
606				extractTracks : true,
607				extractStyles : true,
608				extractAttributes : true,
609				handleHeight : true,
610				maxDepth : 3
611			},
612			style : {
613				strokeColor : "#0000FF",
614				strokeWidth : 3,
615				strokeOpacity : 0.7,
616				pointRadius : 4,
617				fillColor : "#0099FF",
618				fillOpacity : 0.7
619			/*
620			 * , label:"${name}"
621			 */},
622			projection : new OpenLayers.Projection("EPSG:4326")
623		});
624		m.addLayer(layerGPX);
625		layerGPX.events.register('loadend', m, function() {
626			extent.extend(layerGPX.getDataExtent());
627			m.zoomToExtent(extent);
628		});
629
630	}
631
632	/* KML layer */
633	if (mapOpts.kmlfile.length > 0) {
634		var layerKML = new OpenLayers.Layer.GML("KML file", DocBase
635				+ "lib/exe/fetch.php?media=" + mapOpts.kmlfile, {
636			format : OpenLayers.Format.KML,
637			formatOptions : {
638				extractStyles : true,
639				extractAttributes : true,
640				maxDepth : 3
641			},
642			style : {
643				label : "${name}"
644			},
645			projection : new OpenLayers.Projection("EPSG:4326")
646		});
647		m.addLayer(layerKML);
648		layerKML.events.register('loadend', m, function() {
649			extent.extend(layerKML.getDataExtent());
650			m.zoomToExtent(extent);
651		});
652	}
653
654	// selectcontrol for layers
655	if ((m.getLayersByClass('OpenLayers.Layer.GML').length > 0)
656			|| m.getLayersByClass('OpenLayers.Layer.Vector').length > 0) {
657		selectControl = new OpenLayers.Control.SelectFeature((m
658				.getLayersByClass('OpenLayers.Layer.Vector')).concat(m
659				.getLayersByClass('OpenLayers.Layer.GML')), {
660			hover : mapOpts.poihoverstyle,
661			onSelect : onFeatureSelect,
662			onUnselect : onFeatureUnselect
663		});
664		m.addControl(selectControl);
665		selectControl.activate();
666	}
667
668	return m;
669}
670
671var olTimerId = -1;
672/** init. */
673function olInit() {
674	if(navigator.userAgent.indexOf('MSIE')!= -1){
675		//console.log("need to sleep");
676		if(olTimerId==-1){
677			olTimerId = setTimeout ( "olInit()", 3000 );
678			olEnable = false;
679		} else {
680			//console.log("done sleeping");
681			clearTimeout ( olTimerId );
682			olEnable = true;
683		}
684	}
685
686	if (olEnable) {
687		var _i = 0;
688		// create the maps in the page
689		for(_i = 0; _i < olMapData.length; _i++){
690			//console.log(olMapData);
691			createMap(olMapData[_i].mapOpts,olMapData[_i].poi);
692		}
693
694		// hide the table(s) with POI by giving it a print-only style
695		//var tbls = getElementsByClass('olPOItableSpan', null, null);
696		var tbls = jQuery('.olPOItableSpan');
697		for (_i = 0; _i < tbls.length; _i++) {
698			tbls[_i].className += ' olPrintOnly';
699		}
700		// hide the static map image(s) by giving it a print only style
701		//var statImgs = getElementsByClass('olStaticMap', null, null);
702		var statImgs = jQuery('.olStaticMap');
703		for (_i = 0; _i < statImgs.length; _i++) {
704			statImgs[_i].className += ' olPrintOnly';
705		}
706	}
707}
708
709/**
710 * ol api flag.
711 *
712 * @type {Boolean}
713 */
714var olEnable = false,
715/**
716 * array with data for each map in the page.
717 * @type {Array}
718 */
719olMapData = new Array(),
720/**
721 * MapQuest tiles flag.
722 *
723 * @type {Boolean}
724 */
725mqEnable = false,
726/**
727 * google map api flag.
728 *
729 * @type {Boolean}
730 */
731gEnable = false,
732/**
733 * virtual earth map api flag.
734 *
735 * @type {Boolean}
736 */
737veEnable = false,
738/**
739 * Bing tiles flag.
740 *
741 * @type {Boolean}
742 */
743bEnable = false,
744/**
745 * Bing API key.
746 *
747 * @type {String}
748 */
749bApiKey = '',
750/**
751 * OSM tiles flag.
752 *
753 * @type {Boolean}
754 */
755osmEnable = true,
756/**
757 * CSS support flag.
758 *
759 * @type {Boolean}
760 */
761olCSSEnable = true;
762/**
763 * yahoo map api flag.
764 *
765 * @type {Boolean}
766 */
767// yEnable = false;
768
769
770/* register olInit to run with onload event. */
771//addInitEvent(olInit);
772jQuery(olInit);