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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jan 17 11:27:56 EST 2007


Author: nimix
Date: 2007-01-17 11:27:55 -0500 (Wed, 17 Jan 2007)
New Revision: 1014

Modified:
   trunk/mapbender/http/javascripts/mod_measure.php
Log:
add aproximated measuring for epsg 4326

Modified: trunk/mapbender/http/javascripts/mod_measure.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_measure.php	2007-01-17 15:56:40 UTC (rev 1013)
+++ trunk/mapbender/http/javascripts/mod_measure.php	2007-01-17 16:27:55 UTC (rev 1014)
@@ -114,12 +114,30 @@
 function mod_measure_start(e){
 	mb_getMousePos(e,mod_measure_target);
 	var realWorldPos = makeClickPos2RealWorldPos(mod_measure_target,clickX,clickY);
-	mod_measure_RX[mod_measure_RX.length] = Math.round(realWorldPos[0] * 100)/100;
-	mod_measure_RY[mod_measure_RY.length] = Math.round(realWorldPos[1] * 100)/100;
+	if(mod_measure_epsg=="EPSG:4326"){
+		mod_measure_RX[mod_measure_RX.length] = realWorldPos[0];
+		mod_measure_RY[mod_measure_RY.length] = realWorldPos[1];
+	}
+	else{
+		mod_measure_RX[mod_measure_RX.length] = Math.round(realWorldPos[0] * 100)/100;
+		mod_measure_RY[mod_measure_RY.length] = Math.round(realWorldPos[1] * 100)/100;
+	}
 	if(mod_measure_RX.length > 1){
-		var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-2] - mod_measure_RX[mod_measure_RX.length-1]);
-		var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-2] - mod_measure_RY[mod_measure_RY.length-1]);
-		var dist = Math.round(Math.sqrt(Math.pow(dist_x,2) + Math.pow(dist_y,2))*100)/100;
+		var dist;
+		if(mod_measure_epsg=="EPSG:4326"){
+			//convert coordinates to radian
+			var lon_from=(mod_measure_RX[mod_measure_RX.length-2]*Math.PI)/180;
+			var lat_from=(mod_measure_RY[mod_measure_RY.length-2]*Math.PI)/180;
+			var lon_to=(mod_measure_RX[mod_measure_RX.length-1]*Math.PI)/180;
+			var lat_to=(mod_measure_RY[mod_measure_RY.length-1]*Math.PI)/180;
+			dist=6371229*Math.acos(Math.sin(lat_from)*Math.sin(lat_to)+Math.cos(lat_from)*Math.cos(lat_to)*Math.cos(lon_from-lon_to));
+			dist=Math.round(dist*100)/100;
+		}
+		else{
+			var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-2] - mod_measure_RX[mod_measure_RX.length-1]);
+			var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-2] - mod_measure_RY[mod_measure_RY.length-1]);
+			dist = Math.round(Math.sqrt(Math.pow(dist_x,2) + Math.pow(dist_y,2))*100)/100;
+		}
 		mod_measure_Dist[mod_measure_Dist.length] = dist;
 		var totalDist = mod_measure_TotalDist[mod_measure_TotalDist.length-1] + dist;
 		mod_measure_TotalDist[mod_measure_TotalDist.length] = Math.round(totalDist * 100)/100;
@@ -179,10 +197,22 @@
 function mod_measure_run(e){
 	mb_getMousePos(e,mod_measure_target);
 	var pos = makeClickPos2RealWorldPos(mod_measure_target,clickX,clickY);
-	var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-1] - pos[0]);
-	var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-1] - pos[1]);
-	if(isNaN(dist_x) == false && clickX > 0 && clickX < mod_measure_width && clickY > 0 && clickY < mod_measure_height){
-		var str_display = "<span style='font-family:"+mod_measure_font+";font-size:"+mod_measure_fontsize+";color:"+mod_measure_color2+";'>"+(Math.round(Math.sqrt(Math.pow(dist_x,2) + Math.pow(dist_y,2))*100)/100)+" m</span>";
+	var dist;
+	if(mod_measure_epsg=="EPSG:4326"){
+		//convert coordinates to radian
+		var lon_from=(pos[0]*Math.PI)/180;
+		var lat_from=(pos[1]*Math.PI)/180;
+		var lon_to=(mod_measure_RX[mod_measure_RX.length-1]*Math.PI)/180;
+		var lat_to=(mod_measure_RY[mod_measure_RY.length-1]*Math.PI)/180;
+		dist=6371229*Math.acos(Math.sin(lat_from)*Math.sin(lat_to)+Math.cos(lat_from)*Math.cos(lat_to)*Math.cos(lon_from-lon_to));
+	}
+	else{
+		var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-1] - pos[0]);
+		var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-1] - pos[1]);
+		dist=Math.sqrt(dist_x*dist_x+dist_y*dist_y);
+	}
+	if(isNaN(dist) == false && clickX > 0 && clickX < mod_measure_width && clickY > 0 && clickY < mod_measure_height){
+		var str_display = "<span style='font-family:"+mod_measure_font+";font-size:"+mod_measure_fontsize+";color:"+mod_measure_color2+";'>"+(Math.round(dist*100)/100)+" m</span>";
 		writeTag(mod_measure_target,"measure_display",str_display);
 		mb_arrangeElement(mod_measure_target,"measure_display",clickX +2, clickY - 10);
 	}
@@ -195,10 +225,21 @@
 	mod_measure_RX[mod_measure_RX.length] = mod_measure_RX[0];
 	mod_measure_RY[mod_measure_RY.length] = mod_measure_RY[0];
 	if(mod_measure_RX.length > 1){
-		// circumference
-		var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-2] - mod_measure_RX[mod_measure_RX.length-1]);
-		var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-2] - mod_measure_RY[mod_measure_RY.length-1]);
-		var dist = Math.round(Math.sqrt(Math.pow(dist_x,2) + Math.pow(dist_y,2))*100)/100;
+		var dist;
+		if(mod_measure_epsg=="EPSG:4326"){
+			//convert coordinates to radian
+			var lon_from=(mod_measure_RX[mod_measure_RX.length-2]*Math.PI)/180;
+			var lat_from=(mod_measure_RY[mod_measure_RY.length-2]*Math.PI)/180;
+			var lon_to=(mod_measure_RX[mod_measure_RX.length-1]*Math.PI)/180;
+			var lat_to=(mod_measure_RY[mod_measure_RY.length-1]*Math.PI)/180;
+			dist=6371229*Math.acos(Math.sin(lat_from)*Math.sin(lat_to)+Math.cos(lat_from)*Math.cos(lat_to)*Math.cos(lon_from-lon_to));
+			dist=Math.round(dist*100)/100;
+		}
+		else{
+			var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-2] - mod_measure_RX[mod_measure_RX.length-1]);
+			var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-2] - mod_measure_RY[mod_measure_RY.length-1]);
+			dist = Math.round(Math.sqrt(Math.pow(dist_x,2) + Math.pow(dist_y,2))*100)/100;
+		}
 		mod_measure_Dist[mod_measure_Dist.length] = dist;
 		var totalDist = mod_measure_TotalDist[mod_measure_TotalDist.length-1] + dist;
 		mod_measure_TotalDist[mod_measure_TotalDist.length] = Math.round(totalDist * 100)/100;



More information about the Mapbender_commits mailing list