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