[Mapbender-commits] r4616 - in trunk/mapbender: conf http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Sep 11 09:15:54 EDT 2009


Author: christoph
Date: 2009-09-11 09:15:53 -0400 (Fri, 11 Sep 2009)
New Revision: 4616

Modified:
   trunk/mapbender/conf/session.conf
   trunk/mapbender/http/javascripts/mod_box1.js
   trunk/mapbender/http/javascripts/mod_changeEPSG.js
   trunk/mapbender/http/javascripts/mod_setBBOX1.php
Log:
http://trac.osgeo.org/mapbender/ticket/530

Modified: trunk/mapbender/conf/session.conf
===================================================================
--- trunk/mapbender/conf/session.conf	2009-09-11 09:21:45 UTC (rev 4615)
+++ trunk/mapbender/conf/session.conf	2009-09-11 13:15:53 UTC (rev 4616)
@@ -8,6 +8,8 @@
 Mapbender::session()->set("mb_user_name",$name);
 Mapbender::session()->set("mb_user_ip",$_SERVER['REMOTE_ADDR']);
 Mapbender::session()->set("mb_myBBOX",$_REQUEST["mb_myBBOX"]);
+Mapbender::session()->set("mb_myBBOXEpsg",$_REQUEST["mb_myBBOXEpsg"]);
+
 Mapbender::session()->set("mb_myKml",$_REQUEST["kml_id"]);
 Mapbender::session()->set("mb_myPOI",$_REQUEST["mb_myPOI"]);
 Mapbender::session()->set("mb_myPOI2SCALE",$_REQUEST["mb_myPOI2SCALE"]);

Modified: trunk/mapbender/http/javascripts/mod_box1.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_box1.js	2009-09-11 09:21:45 UTC (rev 4615)
+++ trunk/mapbender/http/javascripts/mod_box1.js	2009-09-11 13:15:53 UTC (rev 4616)
@@ -7,7 +7,6 @@
 var mb_isActive = false;
 var mb_isBF = false;
 var mb_zF = false;
-var mb_boxMapObj = null;
 
 var mb_offset_top = 0;
 var mb_offset_right = 0;
@@ -15,7 +14,7 @@
 var mb_offset_left = 0;
 
 function  mod_box_start(e){
-	mb_boxMapObj = getMapObjByName(mb_isBF);
+	var mb_boxMapObj = getMapObjByName(mb_isBF);
 	mb_isActive = true;
 	mb_boxMapObj.getMousePos(e);
 	mb_start_x = clickX;
@@ -30,22 +29,29 @@
 	return false;
 }
 function mod_box_run(e){
-	if(mb_isActive){
-		mb_boxMapObj.getMousePos(e);
-		var width = mb_boxMapObj.width;
-		var height = mb_boxMapObj.height;
-
-		if (((clickX>width) || (clickY>height) || (clickX<=0) ||(clickY<=0))){
-			isActive = false;  
-			mod_box_stop(e);
+	var targetId = $.browser.msie ? window.event.srcElement.id : e.target.id;
+	if(mb_isActive && targetId.substr(0, mb_isBF.length) === mb_isBF){
+		var mb_boxMapObj = getMapObjByName(mb_isBF);
+		var pos = mb_boxMapObj.getMousePosition(e);
+		if (pos !== null) {
+			var width = mb_boxMapObj.width;
+			var height = mb_boxMapObj.height;
+			var clickX = pos.x;
+			var clickY = pos.y;
+	
+			if (((clickX>width) || (clickY>height) || (clickX<=0) ||(clickY<=0))){
+//				isActive = false;  
+//				mod_box_stop(e);
+			}
+			else{
+				mb_end_x=clickX;
+				mb_end_y=clickY;
+				evalExtent();
+			}
+			return false;
 		}
-		else{
-			mb_end_x=clickX;
-			mb_end_y=clickY;
-			evalExtent();
-		}
-		return false;
 	}
+	return true;
 }
 function mod_box_stop(e){
 	mb_hideElement("l_top");
@@ -60,7 +66,10 @@
 }
 function mb_drawBox(left,top,right,bottom){
 	//Look if we have the Box elements
-	mb_boxMapObj = Mapbender.modules[mb_isBF];
+	var mb_boxMapObj = getMapObjByName(mb_isBF);
+	if (mb_boxMapObj === null) {
+		return false;
+	}
 	var map_el = mb_boxMapObj.getDomElement();
 	if(!map_el.ownerDocument.getElementById(mb_boxMapObj.elementName+"_l_top")){
 		//create Box Elements
@@ -72,7 +81,7 @@
 		el_top.style.height = "0px";
 		el_top.style.overflow = "hidden";
 		el_top.style.zIndex = "10";
-		el_top.style.visibility = "hidden";
+		el_top.style.visibility = "visible";
 		el_top.style.cursor = "crosshair";
 		el_top.style.backgroundColor = "#ff0000";
 		
@@ -100,6 +109,7 @@
 	mb_displayElement("l_bottom");
 }
 function mb_arrangeBox(name, left, top, right, bottom){
+	var mb_boxMapObj = getMapObjByName(mb_isBF);
 	var map_el = mb_boxMapObj.getDomElement();
 	var el = map_el.ownerDocument.getElementById(mb_boxMapObj.elementName+"_"+name).style;
 	el.height = Math.abs(bottom - top);
@@ -108,12 +118,14 @@
 	el.left = left + "px";
 }
 function mb_displayElement(name){
+	var mb_boxMapObj = getMapObjByName(mb_isBF);
 	var map_el = mb_boxMapObj.getDomElement();
-	var el = map_el.ownerDocument.getElementById(mb_boxMapObj.elementName+"_"+name).style.visibility = "visible";
+	map_el.ownerDocument.getElementById(mb_boxMapObj.elementName+"_"+name).style.visibility = "visible";
 }
 function mb_hideElement(name) {
+	var mb_boxMapObj = getMapObjByName(mb_isBF);
 	var map_el = mb_boxMapObj.getDomElement();
-	var el = map_el.ownerDocument.getElementById(mb_boxMapObj.elementName+"_"+name).style.visibility = "hidden";
+	map_el.ownerDocument.getElementById(mb_boxMapObj.elementName+"_"+name).style.visibility = "hidden";
 }
 function evalExtent(){
 	if(mb_start_x>mb_end_x){

Modified: trunk/mapbender/http/javascripts/mod_changeEPSG.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_changeEPSG.js	2009-09-11 09:21:45 UTC (rev 4615)
+++ trunk/mapbender/http/javascripts/mod_changeEPSG.js	2009-09-11 13:15:53 UTC (rev 4616)
@@ -41,135 +41,177 @@
 var exists = false;
 
 eventAfterMapRequest.register(function () {
-	mod_changeEPSG_setBox();
-});
-
-function mod_changeEPSG_setBox(){
 	$("#"+options.id+" option").each(function () {
 		if (this.value == mb_mapObj[0].epsg) {
 			isEPSG = true;
 			$(this).attr("selected", "selected");
 		}
 	});
-}
+});
 
 $(this).change(function () {
 	var srsValue = $("#"+options.id).get(0).value;
 	if (srsValue === "") {
 		return;
 	}
-	
-	var srsArray = [];
-	for (var i = 0; i < mb_mapObj.length; i++) {
-		var currentSrs = {
-			"frameName" : mb_mapObj[i].elementName,
-			"epsg" : mb_mapObj[i].epsg,
-			"extent" : mb_mapObj[i].extent.toString(),
-			"width" : mb_mapObj[i].width,
-			"height" : mb_mapObj[i].height
-		};
-		srsArray.push(currentSrs);
-	}
-	for (var i = 0; i < wms.length; i++) {
-		var ext = wms[i].getBoundingBoxBySrs(mb_mapObj[0].epsg);
-		if (ext === null) {
-			continue;
+	Mapbender.modules[options.id].setSrs({
+		srs: srsValue
+	});	
+});
+
+var ChangeEpsg = function () {
+	/**
+	 * Method: setSrs
+	 * 
+	 * Description:
+	 * Sets the SRS for all maps and WMS in the current application.
+	 * The new bounding boxes are calculated with PostGIS! 
+	 * After this, the maps are immediately requested in the new SRS.
+	 * 
+	 * Parameters:
+	 * options.srs      - (String) An SRS identifier, for example "EPSG:4326"
+	 * options.callback - (Function) A callback function. Should include the 
+	 */
+	this.setSrs = function (options) {
+		var srsValue;
+		if (typeof options === "object" && typeof options.srs === "string") {
+			srsValue = options.srs;
 		}
-		var currentSrs = {
-			"wms" : wms[i].wms_id,
-			"epsg" : mb_mapObj[0].epsg,
-			"extent" : ext.toString(),
-			"width" : mb_mapObj[0].width,
-			"height" : mb_mapObj[0].height
-		};
-		srsArray.push(currentSrs);
-	}
+		if (typeof srsValue === "undefined") {
+			new Mb_exception("setSrs: must specify an SRS.");
+			return;
+		}
 
-	var req = new Mapbender.Ajax.Request({
-		url: "../php/mod_changeEPSG_server.php",
-		method: "changeEpsg",
-		parameters: {
-			srs: srsArray,
-			newSrs: srsValue
-		},
-		callback: function (obj, success, message) {
-			if (!success) {
-				new Mapbender.Exception(message);
-				return;
+		var srsArray = [];
+		//
+		// calculate extents for all maps...
+		// 
+		for (var i = 0; i < mb_mapObj.length; i++) {
+			var currentSrs = {
+				"frameName" : mb_mapObj[i].elementName,
+				"epsg" : mb_mapObj[i].epsg,
+				"extent" : mb_mapObj[i].extent.toString(),
+				"width" : mb_mapObj[i].width,
+				"height" : mb_mapObj[i].height
+			};
+			srsArray.push(currentSrs);
+		}
+		//
+		// ... and all WMS.
+		// 
+		for (var i = 0; i < wms.length; i++) {
+			var ext = wms[i].getBoundingBoxBySrs(mb_mapObj[0].epsg);
+			if (ext === null) {
+				continue;
 			}
-			
-			var newExtent = obj;
-			
-			for (var i = 0; i < newExtent.length; i++) {
-				if (newExtent[i].wms) {
-					for (var j = 0; j < wms.length; j++) {
-						if (parseInt(wms[j].wms_id, 10) === parseInt(newExtent[i].wms, 10)) {
-							wms[j].setBoundingBoxBySrs(
-								newExtent[i].newSrs,
-								new Extent(
+			var currentSrs = {
+				"wms" : wms[i].wms_id,
+				"epsg" : mb_mapObj[0].epsg,
+				"extent" : ext.toString(),
+				"width" : mb_mapObj[0].width,
+				"height" : mb_mapObj[0].height
+			};
+			srsArray.push(currentSrs);
+		}
+	
+		//
+		// perform transformation
+		//
+		var req = new Mapbender.Ajax.Request({
+			url: "../php/mod_changeEPSG_server.php",
+			method: "changeEpsg",
+			parameters: {
+				srs: srsArray,
+				newSrs: srsValue
+			},
+			callback: function (obj, success, message) {
+				if (!success) {
+					new Mapbender.Exception(message);
+					return;
+				}
+				
+				var newExtent = obj;
+				
+				for (var i = 0; i < newExtent.length; i++) {
+					if (newExtent[i].wms) {
+						for (var j = 0; j < wms.length; j++) {
+							if (parseInt(wms[j].wms_id, 10) === parseInt(newExtent[i].wms, 10)) {
+								wms[j].setBoundingBoxBySrs(
+									newExtent[i].newSrs,
+									new Extent(
+										parseFloat(newExtent[i].minx),
+										parseFloat(newExtent[i].miny),
+										parseFloat(newExtent[i].maxx),
+										parseFloat(newExtent[i].maxy)
+									)
+								);
+								break;
+							}
+						}
+						continue;
+					}
+	
+					//
+					// use the previous extent of the overview
+					//
+					if(newExtent[i].frameName == options.target){
+		
+						var map = Mapbender.modules[options.target];
+						
+						var goback = false;
+						for (var ii = 0; ii < map.mb_MapHistoryObj.length; ii++) {
+							if (map.mb_MapHistoryObj[ii].epsg == newExtent[i].newSrs) {
+								exists = ii;
+								goback = true;
+							}
+						}
+		
+						if (goback) {
+							map.setSrs({
+								srs: newExtent[i].newSrs, 
+								extent: map.mb_MapHistoryObj[exists].extent,
+								displayWarning: false
+							});
+						}
+						else{
+							map.setSrs({
+								srs: newExtent[i].newSrs, 
+								extent: new Mapbender.Extent(
 									parseFloat(newExtent[i].minx),
-									parseFloat(newExtent[i].miny),
+									parseFloat(newExtent[i].miny), 
 									parseFloat(newExtent[i].maxx),
 									parseFloat(newExtent[i].maxy)
-								)
-							);
-							break;
+								),
+								displayWarning: false
+							});
 						}
 					}
-					continue;
-				}
-
-				//
-				// use the previous extent of the overview
-				//
-				if(newExtent[i].frameName == options.target){
-	
-					var map = Mapbender.modules[options.target];
-					
-					var goback = false;
-					for (var ii = 0; ii < map.mb_MapHistoryObj.length; ii++) {
-						if (map.mb_MapHistoryObj[ii].epsg == newExtent[i].newSrs) {
-							exists = ii;
-							goback = true;
-						}
-					}
-	
-					if (goback) {
+					else {
+						var map = Mapbender.modules[newExtent[i].frameName];
 						map.setSrs({
 							srs: newExtent[i].newSrs, 
-							extent: map.mb_MapHistoryObj[exists].extent,
-							displayWarning: false
-						});
-					}
-					else{
-						map.setSrs({
-							srs: newExtent[i].newSrs, 
 							extent: new Mapbender.Extent(
 								parseFloat(newExtent[i].minx),
 								parseFloat(newExtent[i].miny), 
 								parseFloat(newExtent[i].maxx),
 								parseFloat(newExtent[i].maxy)
 							),
-							displayWarning: false
+							displayWarning: true
 						});
 					}
 				}
-				else {
-					var map = Mapbender.modules[newExtent[i].frameName];
-					map.setSrs({
-						srs: newExtent[i].newSrs, 
-						extent: new Mapbender.Extent(
-							parseFloat(newExtent[i].minx),
-							parseFloat(newExtent[i].miny), 
-							parseFloat(newExtent[i].maxx),
-							parseFloat(newExtent[i].maxy)
-						),
-						displayWarning: true
-					});
+				if (typeof options.callback === "function") {
+					options.callback();
 				}
-				map.setMapRequest();
-			}
-		} 
-	});
-	req.send();
-});
+				for (var i = 0; i < mb_mapObj.length; i++) {
+					mb_mapObj[i].setMapRequest();
+				}
+
+			} 
+		});
+		req.send();
+	};
+};
+
+Mapbender.modules[options.id] = $.extend(new ChangeEpsg(), Mapbender.modules[options.id]);
+

Modified: trunk/mapbender/http/javascripts/mod_setBBOX1.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_setBBOX1.php	2009-09-11 09:21:45 UTC (rev 4615)
+++ trunk/mapbender/http/javascripts/mod_setBBOX1.php	2009-09-11 13:15:53 UTC (rev 4616)
@@ -18,31 +18,72 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
-echo "var mod_setBBOX_target = '".$e_target[0]."';";
+echo "var targetString = '".$e_target[0]."';";
 ?>
 eventInit.register(function () {
-	mod_setBBOX_init();
+	var targetArray = targetString.split(",");
+	var bboxString = "<?php echo Mapbender::session()->get("mb_myBBOX") ?>";
+	var srs = "<?php echo Mapbender::session()->get("mb_myBBOXEpsg") ?>";
+
+	//
+	// the user wants to set an SRS that is different from the 
+	// application's SRS!
+	//
+	if (typeof Mapbender.modules[targetArray[0]] === "object" 
+		&& srs !== "" && srs !== Mapbender.modules[targetArray[0]].epsg) {
+		if (typeof Mapbender.modules.changeEPSG !== "object") {
+			new Mb_exception("setBBOX requires changeEPSG!");
+			return;
+		}
+		Mapbender.modules.changeEPSG.setSrs({
+			srs: srs,
+			callback: function () {
+				setBbox(targetArray, bboxString);
+			}
+		});
+	}
+	//
+	// the user doesn't want to change the SRS.
+	//
+	else {
+		setBbox(targetArray, bboxString);
+	}
 });
-function mod_setBBOX_init(){
-	var my_target = mod_setBBOX_target.split(",");
-	var myBBOX = "<?php echo Mapbender::session()->get("mb_myBBOX") ?>";
-	for(var i=0; i<my_target.length; i++){
-		if(myBBOX != ""){
-			var mapObj = getMapObjByName(my_target);
-			if (mapObj) {
-				var coord = myBBOX.split(","); 
-				var newExtent = new Mapbender.Extent(parseFloat(coord[0]),parseFloat(coord[1]),parseFloat(coord[2]),parseFloat(coord[3]));
 
-				// if the restrictedExtent attribute exists, it has been 
-				// configured by the user in the element variable.
-				// This is an indicator, that the administrator wants to
-				// set the restricted extent coming from request variables.
-				if (mapObj.restrictedExtent) {
-					mapObj.setRestrictedExtent(newExtent);
-				}
-				mapObj.calculateExtent(newExtent);				
+var setBbox = function (targetArray, bboxString) { 
 
-			}
+	for (var i = 0; i < targetArray.length; i++) {
+		var currentTarget = targetArray[i];
+		
+		var mapObj = getMapObjByName(currentTarget);
+		if (mapObj === null) {
+			var e = new Mb_exception("setBBOX: unknown map object: " + currentTarget);
+			continue;
 		}
+
+		if (bboxString === "") {
+			var e = new Mb_exception("setBBOX: no bounding box found.");
+			continue;
+		}
+		else {
+			var coord = bboxString.split(","); 
+			var newExtent = new Mapbender.Extent(
+				parseFloat(coord[0]),
+				parseFloat(coord[1]),
+				parseFloat(coord[2]),
+				parseFloat(coord[3])
+			);
+		}
+
+		// if the restrictedExtent attribute exists, it has been 
+		// configured by the user in the element variable.
+		// This is an indicator, that the administrator wants to
+		// set the restricted extent coming from request variables.
+		if (mapObj.restrictedExtent) {
+			mapObj.setRestrictedExtent(newExtent);
+		}
+		mapObj.calculateExtent(newExtent);		
+		mapObj.setMapRequest();		
 	}
-}
+};
+



More information about the Mapbender_commits mailing list