[Mapbender-commits] r4267 - branches/google_dev/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 1 05:58:49 EDT 2009


Author: christoph
Date: 2009-07-01 05:58:49 -0400 (Wed, 01 Jul 2009)
New Revision: 4267

Modified:
   branches/google_dev/http/javascripts/mod_google.php
Log:


Modified: branches/google_dev/http/javascripts/mod_google.php
===================================================================
--- branches/google_dev/http/javascripts/mod_google.php	2009-06-30 15:14:11 UTC (rev 4266)
+++ branches/google_dev/http/javascripts/mod_google.php	2009-07-01 09:58:49 UTC (rev 4267)
@@ -24,6 +24,9 @@
 
 require(dirname(__FILE__)."/../include/dyn_php.php");
 
+//
+// Check if key is set in administration interface. If not, abort.
+//
 if (!$key) {
 	$e = new mb_exception("No key given for Google Maps API. Google Maps will not be available.");
 }
@@ -163,28 +166,70 @@
 	if (typeof TYPE === "undefined") {
 		var TYPE = "SATELLITE";
 	}
+
+	var setMapType = function (type) {
+		if (!type) {
+			$("#<?php echo $e_id;?>").selectedIndex = 0;
+			return;
+		}
+		$("#<?php echo $e_id;?>").value = type;
+	};
 	
-	eventInitMap.register(function () {
-		var map = getMapObjByName(mod_google_target);
-		
-		switch (TYPE) {
+	var getMapTypeFromString = function (str) {
+		switch (str) {
 			case "ROADMAP" : 
-				mapTypeId = google.maps.MapTypeId.ROADMAP;
+				return google.maps.MapTypeId.ROADMAP;
 				break;
 			case "SATELLITE" : 
-				mapTypeId = google.maps.MapTypeId.SATELLITE;
+				return google.maps.MapTypeId.SATELLITE;
 				break;
 			case "HYBRID" : 
-				mapTypeId = google.maps.MapTypeId.HYBRID;
+				return google.maps.MapTypeId.HYBRID;
 				break;
 			case "TERRAIN" : 
-				mapTypeId = google.maps.MapTypeId.TERRAIN;
+				return google.maps.MapTypeId.TERRAIN;
 				break;
 			default:
-				mapTypeId = google.maps.MapTypeId.SATELLITE;
+				return null;
 				break;
 		}
+	};
+	
+	eventInitMap.register(function () {
+		var map = getMapObjByName(mod_google_target);
+		
+		//
+		// set select box to default value
+		//
+		$("#<?php echo $e_id;?> option").each(function () {
+			if (this.value === TYPE) {
+				this.parentNode.value = this.value;
+			}
+		});
 
+		//
+		// bind onchange event to select box
+		//
+		$("#<?php echo $e_id;?>").change(function () {
+			var googleMapType = getMapTypeFromString(this.value);
+
+			if (googleMapType !== null) {
+				$("#" + map.google.id).css("visibility", "visible");
+				map.google.map.set_mapTypeId(googleMapType);
+				setMapType(googleMapType);
+			}
+			else {
+				$("#" + map.google.id).css("visibility", "hidden");
+				map.google.map.set_mapTypeId(null);
+			}
+		});
+
+
+		//
+		// set default values
+		//
+		mapTypeId = getMapTypeFromString(TYPE);
+
 		var googleOptions = {
 			mapTypeId: mapTypeId,
 			MIN_ZOOM_LEVEL : MIN_ZOOM_LEVEL,
@@ -193,6 +238,9 @@
 			ZOOM_LEVEL : ZOOM_LEVEL
 		};			
 
+		//
+		// initialize map
+		//
 		map.setGoogleMap(googleOptions);
 	});
 })();



More information about the Mapbender_commits mailing list