xref: /plugin/openlayersmap/script.js (revision 75c98788cf03f8e50d6f5ca279a7248b14e72482)
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
218	// OpenLayers.Layer.Vector.prototype.renderers = ["SVG2", "VML", "Canvas"];
219
220	// http://mapbox.com/documentation/adding-tiles-your-site/openlayers-themes
221	// OpenLayers.ImgPath = '';
222
223	// find map element location
224	var cleartag = document.getElementById(mapOpts.id + '-clearer');
225	if (cleartag === null) {
226		return;
227	}
228	// create map element and add to document
229	var fragment = olCreateMaptag(mapOpts.id, mapOpts.width, mapOpts.height);
230	cleartag.parentNode.insertBefore(fragment, cleartag);
231
232	/** dynamic map extent. */
233	var extent = new OpenLayers.Bounds(),
234
235	/** map. */
236	m = new OpenLayers.Map(mapOpts.id, {
237		projection : new OpenLayers.Projection('EPSG:900913'),
238		displayProjection : new OpenLayers.Projection('EPSG:4326'),
239		units : 'm',
240		maxResolution : 156543.0339,
241		maxExtent : new OpenLayers.Bounds(-20037508.34, -20037508.34,
242				20037508.34, 20037508.34),
243		numZoomLevels : 19,
244		// panDuration : 100,
245		controls : [ /* new OpenLayers.Control.LoadingPanel(), */
246		new OpenLayers.Control.KeyboardDefaults(),
247				new OpenLayers.Control.Navigation({
248					dragPanOptions : {
249						enableKinetic : true
250					}
251				}), new OpenLayers.Control.ScaleLine({
252					geodesic : true
253				}) ],
254		theme : null
255	});
256	if (osmEnable) {
257		/* add OSM map layers */
258		m.addLayer(new OpenLayers.Layer.OSM("OpenStreetMap"), {
259			transitionEffect : 'resize',
260			visibility : false
261		});
262
263		m
264				.addLayer(
265						new OpenLayers.Layer.OSM(
266								"t@h",
267								[
268										"http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
269										"http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
270										"http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png" ]),
271						{
272							transitionEffect : 'resize',
273							visibility : false
274						});
275
276		m
277				.addLayer(
278						new OpenLayers.Layer.OSM(
279								"cycle map",
280								[
281										// "http://andy.sandbox.cloudmade.com/tiles/cycle/${z}/${x}/${y}.png",
282										"http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
283										"http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
284										"http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png" ]),
285						{
286							transitionEffect : 'resize',
287							attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, '
288									+ 'Tiles <a href="http://opencyclemap.org/" target="_blank">OpenCycleMap</a>'
289									+ '<img src="http://opencyclemap.org/favicon.ico" heigth="16" width="16"/>',
290							visibility : false
291						});
292
293		m
294				.addLayer(new OpenLayers.Layer.OSM(
295						"cloudmade map",
296						"http://tile.cloudmade.com/2f59745a6b525b4ebdb100891d5b6711/3/256/${z}/${x}/${y}.png",
297						{
298							transitionEffect : 'resize',
299							visibility : false
300						}));
301
302		m.addLayer(new OpenLayers.Layer.OSM("hike and bike map",
303				"http://toolserver.org/tiles/hikebike/${z}/${x}/${y}.png", {
304					transitionEffect : 'resize',
305					visibility : false
306				}));
307	}
308	/*
309	 * add MapQuest map layers, see:
310	 * http://developer.mapquest.com/web/products/open/map
311	 */
312	if (mqEnable) {
313		m
314				.addLayer(new OpenLayers.Layer.OSM(
315						"mapquest road",
316						[
317								"http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
318								"http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
319								"http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
320								"http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png" ],
321						{
322							transitionEffect : 'resize',
323							attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, '
324									+ 'Tiles <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>'
325									+ '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" heigth="14" width="14" alt="logo"/>',
326							visibility : false
327						}));
328		// note that global coverage is provided at zoom levels 0-11. Zoom
329		// Levels 12+ are provided only in the United States (lower 48).
330		m
331				.addLayer(new OpenLayers.Layer.OSM(
332						"mapquest aerial",
333						[
334								"http://oatile1.mqcdn.com/naip/${z}/${x}/${y}.jpg",
335								"http://oatile2.mqcdn.com/naip/${z}/${x}/${y}.jpg",
336								"http://oatile3.mqcdn.com/naip/${z}/${x}/${y}.jpg",
337								"http://oatile4.mqcdn.com/naip/${z}/${x}/${y}.jpg" ],
338						{
339							transitionEffect : 'resize',
340							attribution : 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>'
341									+ '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" heigth="16" width="16">',
342							visibility : false,
343							numZoomLevels : 12
344						}));
345	}
346
347	/* open aerial map layers */
348	/*
349	 * turn this off; project is asleep:
350	 * https://sourceforge.net/tracker/?func=detail&aid=2897327&group_id=239475&atid=1110186
351	 * m.addLayer(new OpenLayers.Layer.XYZ("OpenAerialMap",
352	 * "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/${z}/${x}/${y}.jpg",
353	 * {name: "OpenStreetMap", attribution: "Data CC-By by <a
354	 * href='http://www.openaerialmap.org/licensing/'>OpenAerialMap</a>",
355	 * sphericalMercator: true, transitionEffect: 'resize'} ));
356	 */
357
358	/* controle of google/yahoo/ve api's beschikbaar zijn.. */
359	if (gEnable) {
360		try {
361			m.addLayer(new OpenLayers.Layer.Google("google relief", {
362				type : google.maps.MapTypeId.TERRAIN,
363				// transitionEffect : 'resize',
364				numZoomLevels : 16,
365				animationEnabled : true,
366				visibility : false
367			}));
368			m.addLayer(new OpenLayers.Layer.Google("google sat", {
369				type : google.maps.MapTypeId.SATELLITE,
370				// transitionEffect : 'resize',
371				// numZoomLevels : 22,
372				animationEnabled : true,
373				visibility : false
374			}));
375			m.addLayer(new OpenLayers.Layer.Google("google hybrid", {
376				type : google.maps.MapTypeId.HYBRID,
377				// transitionEffect : 'resize',
378				// numZoomLevels : 20,
379				animationEnabled : true,
380				visibility : false
381			}));
382			m.addLayer(new OpenLayers.Layer.Google("google normal", {
383				// transitionEffect : 'resize',
384				// numZoomLevels : 20,
385				animationEnabled : true,
386				visibility : false
387			}));
388		} catch (ol_err1) {
389			Openlayers.Console.userError('Error loading Google maps' + ol_err1);
390		}
391	}
392
393	// if (yEnable) {
394	// try {
395	// m.addLayer(new OpenLayers.Layer.Yahoo("yahoo", {
396	// 'type' : YAHOO_MAP_HYB,
397	// 'sphericalMercator' : true,
398	// transitionEffect : resize
399	// }));
400	// } catch (ol_err2) {
401	// }
402	// }
403
404	if (veEnable) {
405		try {
406			m.addLayer(new OpenLayers.Layer.VirtualEarth("ve", {
407				type : VEMapStyle.Hybrid,
408				sphericalMercator : true,
409				transitionEffect : 'resize',
410				visibility : false
411			}));
412		} catch (ol_err3) {
413		}
414	}
415	m.setCenter(new OpenLayers.LonLat(mapOpts.lon, mapOpts.lat).transform(
416			m.displayProjection, m.projection), mapOpts.zoom);
417	extent.extend(m.getExtent());
418
419	// change/set alternative baselyr
420	try {
421		m.setBaseLayer(((m.getLayersByName(mapOpts.baselyr))[0]));
422	} catch (ol_err4) {
423		m.setBaseLayer(m.layers[0]);
424	}
425
426	if (mapOpts.controls === 1) {
427		/* add base controls to map */
428		m.addControl(new OpenLayers.Control.LayerSwitcher({
429			roundedCorner : false,
430			roundedCornerColor : null
431		}));
432		m.addControl(new OpenLayers.Control.PanZoomBar());
433		m.addControl(new OpenLayers.Control.Graticule({
434			visible : false
435		}));
436
437		// add overlays
438		m.addLayer(new OpenLayers.Layer.OSM("Hillshade",
439				"http://toolserver.org/~cmarqu/hill/${z}/${x}/${y}.png", {
440					transitionEffect : 'resize',
441					isBaseLayer : false,
442					transparent : true,
443					visibility : false,
444					displayOutsideMaxExtent : true,
445					attribution : ''
446				}));
447
448		m.addControl(new OpenLayers.Control.OverviewMap({
449			size : new OpenLayers.Size(120, 120),
450			mapOptions : {
451				theme : null
452			},
453			layers : [ m.baseLayer.clone() ]
454		}));
455	}
456
457	if (mapOpts.statusbar === 1) {
458		// statusbar control: permalink
459		m.addControl(new OpenLayers.Control.Permalink(mapOpts.id
460				+ '-statusbar-link-ref'));
461		// statusbar control: mouse pos.
462		// TODO kijken naar afronding met aNumber.toFixed(0)
463		m.addControl(new OpenLayers.Control.MousePosition({
464			'div' : OpenLayers.Util.getElement(mapOpts.id
465					+ '-statusbar-mouseposition')
466		}));
467		// statusbar control: scale
468		m.addControl(new OpenLayers.Control.Scale(mapOpts.id
469				+ '-statusbar-scale'));
470		// statusbar control: attribution
471		m.addControl(new OpenLayers.Control.Attribution({
472			'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-text')
473		}));
474		// statusbar control: projection
475		OpenLayers.Util.getElement(mapOpts.id + '-statusbar-projection').innerHTML = m.displayProjection;
476	} else {
477		OpenLayers.Util.getElement(mapOpts.id + '-olStatusBar').display = 'none';
478	}
479
480	if (mapOpts.toolbar === 1) {
481		// add buttons + panel
482		var zoomin = new OpenLayers.Control.ZoomBox({
483			title : "Zoom in"
484		}), /**/zoomout = new OpenLayers.Control.ZoomBox({
485			out : true,
486			title : "Zoom uit",
487			displayClass : "olControlZoomOut"
488		}), /**/pan = new OpenLayers.Control.DragPan({
489			title : "Verschuif"
490		}), /* do "nothing" button... */info = new OpenLayers.Control.Button({
491			type : OpenLayers.Control.TYPE_TOOL,
492			displayClass : "olControlFeatureInfo"
493		/* , trigger : selectControl.activate() */
494		}), /* navigation history */
495		nav = new OpenLayers.Control.NavigationHistory();
496		m.addControl(nav);
497		var panel = new OpenLayers.Control.Panel({
498			defaultControl : pan,
499			displayClass : "olToolbar",
500			"div" : OpenLayers.Util.getElement(mapOpts.id + "-olToolbar")
501		});
502		panel
503				.addControls([ zoomin, zoomout, pan, info, nav.next,
504						nav.previous ]);
505		// panel.addControls([ nav.next, nav.previous ]);
506		m.addControl(panel);
507	} else {
508		OpenLayers.Util.getElement(mapOpts.id + '-olToolbar').display = 'none';
509	}
510
511	if (OLmapPOI.length > 0) {
512		var markers = new OpenLayers.Layer.Vector(
513				"POI",
514				{
515					styleMap : new OpenLayers.StyleMap(
516							{
517								"default" : {
518									externalGraphic : "${img}",
519									graphicHeight : 16,
520									graphicWidth : 16,
521									graphicXOffset : 0,
522									graphicYOffset : -8,
523									graphicOpacity : "${opacity}",
524									rotation : "${angle}",
525									backgroundGraphic : DocBase
526											+ "lib/plugins/openlayersmap/icons/marker_shadow.png",
527									backgroundXOffset : 0,
528									backgroundYOffset : -4,
529									backgroundRotation : "${angle}",
530									pointRadius : 10,
531									labelXOffset : 8,
532									labelYOffset : 8,
533									labelAlign : "lb",
534									label : "${label}",
535									// fontColor : "",
536									fontFamily : "monospace",
537									fontSize : "12px",
538									fontWeight : "bold"
539								},
540								"select" : {
541									cursor : "crosshair",
542									externalGraphic : DocBase
543											+ "lib/plugins/openlayersmap/icons/marker-red.png",
544									graphicHeight : 16,
545									graphicWidth : 16,
546									graphicXOffset : 0,
547									graphicYOffset : -8,
548									graphicOpacity : 1.0,
549									rotation : "${angle}"
550								}
551							}),
552					isBaseLayer : false,
553					rendererOptions : {
554						yOrdering : true
555					}
556				});
557
558		m.addLayer(markers);
559		var features = [];
560		var lonLat;
561		for ( var j = 0; j < OLmapPOI.length; j++) {
562			var feat = new OpenLayers.Feature.Vector(
563					new OpenLayers.Geometry.Point(OLmapPOI[j].lon,
564							OLmapPOI[j].lat).transform(m.displayProjection,
565							m.projection), {
566						angle : OLmapPOI[j].angle,
567						opacity : OLmapPOI[j].opacity,
568						img : DocBase + "lib/plugins/openlayersmap/icons/"
569								+ OLmapPOI[j].img,
570						label : OLmapPOI[j].rowId
571					});
572			feat.data = {
573				name : OLmapPOI[j].txt,
574				rowId : OLmapPOI[j].rowId
575			};
576			features.push(feat);
577		}
578		markers.addFeatures(features);
579		extent.extend(markers.getDataExtent());
580		m.zoomToExtent(extent);
581	}
582
583	/* GPX layer */
584	if (mapOpts.gpxfile.length > 0) {
585		var layerGPX = new OpenLayers.Layer.GML("GPS route", DocBase
586				+ "lib/exe/fetch.php?media=" + mapOpts.gpxfile, {
587			format : OpenLayers.Format.GPX,
588			formatOptions : {
589				extractWaypoints : true,
590				extractTracks : true,
591				extractStyles : true,
592				extractAttributes : true,
593				handleHeight : true,
594				maxDepth : 3
595			},
596			style : {
597				strokeColor : "#0000FF",
598				strokeWidth : 3,
599				strokeOpacity : 0.7,
600				pointRadius : 4,
601				fillColor : "#0099FF",
602				fillOpacity : 0.7
603			/*
604			 * , label:"${name}"
605			 */},
606			projection : new OpenLayers.Projection("EPSG:4326")
607		});
608		m.addLayer(layerGPX);
609		layerGPX.events.register('loadend', m, function() {
610			extent.extend(layerGPX.getDataExtent());
611			m.zoomToExtent(extent);
612		});
613
614	}
615
616	/* KML layer */
617	if (mapOpts.kmlfile.length > 0) {
618		var layerKML = new OpenLayers.Layer.GML("KML file", DocBase
619				+ "lib/exe/fetch.php?media=" + mapOpts.kmlfile, {
620			format : OpenLayers.Format.KML,
621			formatOptions : {
622				extractStyles : true,
623				extractAttributes : true,
624				maxDepth : 3
625			},
626			style : {
627				label : "${name}"
628			},
629			projection : new OpenLayers.Projection("EPSG:4326")
630		});
631		m.addLayer(layerKML);
632		layerKML.events.register('loadend', m, function() {
633			extent.extend(layerKML.getDataExtent());
634			m.zoomToExtent(extent);
635		});
636	}
637
638	// selectcontrol for layers
639	if ((m.getLayersByClass('OpenLayers.Layer.GML').length > 0)
640			|| m.getLayersByClass('OpenLayers.Layer.Vector').length > 0) {
641		selectControl = new OpenLayers.Control.SelectFeature((m
642				.getLayersByClass('OpenLayers.Layer.Vector')).concat(m
643				.getLayersByClass('OpenLayers.Layer.GML')), {
644			hover : mapOpts.poihoverstyle,
645			onSelect : onFeatureSelect,
646			onUnselect : onFeatureUnselect
647		});
648		m.addControl(selectControl);
649		selectControl.activate();
650	}
651
652	return m;
653}
654
655/**
656 * ol api flag.
657 *
658 * @type {Boolean}
659 */
660var olEnable = false,
661/**
662 * MapQuest tiles flag.
663 *
664 * @type {Boolean}
665 */
666mqEnable = false,
667/**
668 * google map api flag.
669 *
670 * @type {Boolean}
671 */
672gEnable = false,
673/**
674 * virtual earth map api flag.
675 *
676 * @type {Boolean}
677 */
678veEnable = false,
679/**
680 * OSM tiles flag.
681 *
682 * @type {Boolean}
683 */
684osmEnable = true;
685/**
686 * yahoo map api flag.
687 *
688 * @type {Boolean}
689 */
690// yEnable = false;
691/* register olInit to run with onload event. */
692addInitEvent(olInit);
693