[Mapbender-commits] r6615 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jul 22 10:53:28 EDT 2010


Author: verenadiewald
Date: 2010-07-22 14:53:28 +0000 (Thu, 22 Jul 2010)
New Revision: 6615

Modified:
   trunk/mapbender/http/javascripts/map_obj.js
Log:
new functions setCrs, transformExtent, some changes for new get api in functions zoom and setSrs

Modified: trunk/mapbender/http/javascripts/map_obj.js
===================================================================
--- trunk/mapbender/http/javascripts/map_obj.js	2010-07-22 14:51:34 UTC (rev 6614)
+++ trunk/mapbender/http/javascripts/map_obj.js	2010-07-22 14:53:28 UTC (rev 6615)
@@ -288,7 +288,7 @@
      * converts the extent of the mapobject so that the maximum	extent will be displayed
      */
     this.calculateExtent = function(ext){
-		var relation_px_x = this.getWidth() / this.getHeight();
+    	var relation_px_x = this.getWidth() / this.getHeight();
         var relation_px_y = this.getHeight() / this.getWidth();
         var relation_bbox_x = ext.extentx / ext.extenty;
         var oldMin = ext.getSouthWest();
@@ -366,8 +366,75 @@
         return ignoredWms;
     };
     
+    this.transformExtent = function (options) {
+    	if (typeof options !== 'object') {
+    		return false;
+    	}	
+    	
+    	if (this.epsg !== options.crs) {
+	    	var source = new Proj4js.Proj(options.crs);
+			var dest = new Proj4js.Proj(this.epsg);
+	    	
+			var intervalId = setInterval(function() {
+				if(source.readyToUse && dest.readyToUse) {
+					clearInterval(intervalId);
+					var o = {
+						source : source,
+						dest : dest,
+						extent : options.extent
+					};
+					
+					that.extent.setCrs(o);
+					that.calculateExtent(that.extent);
+		        	that.setMapRequest();
+		        } 
+			}, 200);
+    	}
+    };
+    
+    this.setCrs = function (options) {
+    	if (typeof options !== 'object') {
+    		return false;
+    	}
+    	
+    	if (this.epsg !== options.crs) {
+    		var source = new Proj4js.Proj(this.epsg);
+    		var dest = new Proj4js.Proj(options.crs);
+    		
+    		var intervalId = setInterval(function() {
+    			if(source.readyToUse && dest.readyToUse) {
+    				var o = {
+    					source : source,
+    					dest : dest
+    				};
+    				clearInterval(intervalId);
+    				setCrsMap(o);
+    				setCrsWms(o);
+    				checkSupportedWms({
+        				srs : options.crs
+        			});
+    	    		that.epsg = options.crs;
+    	    		srsHasChanged = true;
+    	    		that.calculateExtent(that.extent);
+    	        	that.setMapRequest();
+    	        	options.callback();
+    	        } 
+    		}, 200);
+    	}
+    };
+    
+    var setCrsMap = function (options) {
+    	that.extent.setCrs(options);
+    };
+    
+    var setCrsWms = function (options) {
+    	for (j = 0; j < that.wms.length; j++) {
+    		that.wms[j].setCrs(options);
+		}
+    };
+    
     this.setSrs = function(options){
-        if (typeof options.srs !== "string") {
+    	if (typeof options.srs !== "string") {
             new Mb_exception("Mapbender.Map.setSrs: SRS is not a string: " + options.srs);
             return null;
         }
@@ -376,50 +443,59 @@
             return null;
         }
         if (this.epsg !== options.srs) {
-            // check which WMS support the new SRS
-            undoIgnoreWms();
-            for (var i = 0; i < this.wms.length; i++) {
-                var found = false;
-                for (var j = 0; j < this.wms[i].gui_epsg.length; j++) {
-                    if (options.srs === this.wms[i].gui_epsg[j] && this.wms[i].gui_epsg_supported[j]) {
-                        found = true;
-                        break;
-                    }
+            // actually set the new values and return extent
+        	checkSupportedWms(options);
+            this.epsg = options.srs;
+            srsHasChanged = true;
+            return this.calculateExtent(options.extent);
+        }
+		return this.extent;
+    };
+    
+    var checkSupportedWms = function (o) {
+        var defaultOptions = {
+        	displayWarning : false,
+        	srs : null
+        };
+        var options = $.extend(defaultOptions, o);
+    	// check which WMS support the new SRS
+        undoIgnoreWms();
+        for (var i = 0; i < that.wms.length; i++) {
+            var found = false;
+            for (var j = 0; j < that.wms[i].gui_epsg.length; j++) {
+                if (options.srs === that.wms[i].gui_epsg[j] && that.wms[i].gui_epsg_supported[j]) {
+                    found = true;
+                    break;
                 }
-                if (!found) {
-                    ignoreWms(this.wms[i]);
-                }
             }
-            var ignoredWms = getIgnoredWms();
+            if (!found) {
+                ignoreWms(that.wms[i]);
+            }
+        }
+        var ignoredWms = getIgnoredWms();
+        
+        // ...and optionally display a message
+        if (options.displayWarning && ignoredWms.length > 0) {
+        
+            var msg = mapMsgObj.srsNotSupported + ": <br><br>";
             
-            // ...and optionally display a message
-            if (options.displayWarning && ignoredWms.length > 0) {
-            
-                var msg = mapMsgObj.srsNotSupported + ": <br><br>";
-                
-                for (var key in ignoredWms) {
-                    msg += "<b>" + ignoredWms[key].title + "</b><br>";
-                }
-                try {
-                    Mapbender.modules.dialogManager.openDialog({
-                        content: msg,
-                        modal: false,
-                        effectShow: 'puff'
-                    });
-                } 
-                catch (e) {
-                    new Mb_warning(e.message + ". " + msg);
-                }
+            for (var key in ignoredWms) {
+                msg += "<b>" + ignoredWms[key].title + "</b><br>";
             }
-            
-            // actually set the new values and return extent
-            this.epsg = options.srs;
-            
+            try {
+                Mapbender.modules.dialogManager.openDialog({
+                    content: msg,
+                    modal: false,
+                    effectShow: 'puff'
+                });
+            } 
+            catch (e) {
+                new Mb_warning(e.message + ". " + msg);
+            }
         }
-		srsHasChanged = true;
-        return this.calculateExtent(options.extent);
-    };
+    }; 
     
+    
     this.setWms = function(wms_index){
         this.wms = [];
         var index = 0;
@@ -706,10 +782,21 @@
      * @param {float} x center to x-position
      * @param {float} y center to y-position
      */
-    this.zoom = function(in_, factor, x, y){
-        this.setExtent(this.calculateExtentAfterZoom(in_, factor, x, y));
-        this.setMapRequest();
-    };
+    this.zoom = function(in_, factor, x, y, crs){
+    	if (crs) {
+    		if (this.epsg !== crs) {
+	    		var zoomPoint = new Mapbender.Point(x, y);
+	    		var newPoint = zoomPoint.transform(crs, this.epsg, function (p) {
+	    			that.setExtent(that.calculateExtentAfterZoom(in_, factor, p.x, p.y));
+		            that.setMapRequest();
+	    		});
+	    	}
+    	}
+    	else {
+    		this.setExtent(this.calculateExtentAfterZoom(in_, factor, x, y));
+            this.setMapRequest();
+    	}
+	};
     
     this.convertPixelToReal = function(aPoint, referenceExtent){
     	var arrayBBox;



More information about the Mapbender_commits mailing list