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