[Mapbender-commits] r6089 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu May 6 09:32:01 EDT 2010


Author: christoph
Date: 2010-05-06 09:31:58 -0400 (Thu, 06 May 2010)
New Revision: 6089

Modified:
   trunk/mapbender/http/plugins/mb_metadata_layerPreview.js
Log:
automatically select correct SRS and zoom to extent

Modified: trunk/mapbender/http/plugins/mb_metadata_layerPreview.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_layerPreview.js	2010-05-06 13:30:51 UTC (rev 6088)
+++ trunk/mapbender/http/plugins/mb_metadata_layerPreview.js	2010-05-06 13:31:58 UTC (rev 6089)
@@ -1,6 +1,6 @@
 
 var $metadataLayerPreview = $(this);
-$metadataLayerPreview.css('border','white');
+$metadataLayerPreview.css('border', 'white');
 
 var MetadataLayerPreviewApi =  function (o){
 
@@ -11,6 +11,43 @@
 
 	this.wmsId = null;
 
+	var changeEpsgAndZoomToExtent = function (layer, map) {
+		layer.gui_layer_visible = 1;
+		var len = layer.layer_epsg.length;
+		if (len === 0) {
+			// could not zoom to extent
+//			console.log("Could not zoom to extent");
+			return;
+		}
+		for (var j = 0;  j < len; j++) {
+			var currentEpsg = layer.layer_epsg[j];
+			if (currentEpsg.epsg === map.epsg) {
+				var newExtent = new Mapbender.Extent(
+					currentEpsg.minx,
+					currentEpsg.miny,
+					currentEpsg.maxx,
+					currentEpsg.maxy
+				);
+				map.calculateExtent(newExtent);
+//				console.log("Zooming to " + newExtent.toString());
+				return;
+			}
+		}
+		// current SRS is not supported, switch to a supported SRS
+		var newEpsg = layer.layer_epsg[0];
+		var newExtent = new Mapbender.Extent(
+			newEpsg.minx,
+			newEpsg.miny,
+			newEpsg.maxx,
+			newEpsg.maxy
+		);
+		map.setSrs({
+			srs: newEpsg.epsg,
+			extent: newExtent
+		});
+//		console.log("Changing SRS to " + newEpsg.epsg + " and zooming to " + newExtent.toString());
+	};
+
 	// enable layer,. disabling all others
 	this.layer = function(layer){
 		var layername = layer.layer_name;
@@ -18,29 +55,18 @@
 		if(layername === undefined){
 			return 'currentlayername';
 		}
-		$map = $('#'+options.map).mapbender();
-		var wms = $map.wms[$map.wms.length -1];
+		var map = $('#'+options.map).mapbender();
+		var wms = map.wms[map.wms.length -1];
 		for (var i in wms.objLayer){
 			if(wms.objLayer[i].layer_name == layername){
-				wms.objLayer[i].gui_layer_visible = 1;
-				for (var j = 0;  j < wms.objLayer[i].layer_epsg.length;j++){
-					var epsg = wms.objLayer[i].layer_epsg[j];
-					if($map.epsg == epsg.epsg){
-        				$map.calculateExtent(new Mapbender.Extent(
-							epsg.minx,
-							epsg.miny,
-							epsg.maxx,
-							epsg.maxy
-						));
-					}
-				}
+				changeEpsgAndZoomToExtent(wms.objLayer[i], map);
 			}
 			else{
 				wms.objLayer[i].gui_layer_visible = 0;
 			}	
 		}
-		$map.restateLayers(wms.wms_id);
-        $map.setMapRequest();
+		map.restateLayers(wms.wms_id);
+        map.setMapRequest();
 	};
 
 	// set wms, throwing out all others



More information about the Mapbender_commits mailing list