[Mapbender-commits] r5203 - branches/2.6/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Dec 17 06:03:54 EST 2009


Author: christoph
Date: 2009-12-17 06:03:54 -0500 (Thu, 17 Dec 2009)
New Revision: 5203

Modified:
   branches/2.6/http/javascripts/map_obj.js
Log:
getMousePosition from Trunk

Modified: branches/2.6/http/javascripts/map_obj.js
===================================================================
--- branches/2.6/http/javascripts/map_obj.js	2009-12-17 11:02:07 UTC (rev 5202)
+++ branches/2.6/http/javascripts/map_obj.js	2009-12-17 11:03:54 UTC (rev 5203)
@@ -89,50 +89,74 @@
 		var domElement = this.getDomElement();
 		domElement.style.height = this.height;
 	};
-	
-	this.getMousePosition = function (e) {
-		var clickX, clickY;
+	 
+  	this.getMousePosition = function (event) {
+		var pageX, pageY, offsetX, offsetY;
+		var e = event || window.event;
+		var target = e.target || e.srcElement;
+		
+		if (!e) {
+			return null;
+		}
 
-		if ($.browser.msie) {
-			clickX = parseInt(window.event.offsetX, 10);
-			clickY = parseInt(window.event.offsetY, 10);
+		// FIREFOX
+		if (typeof e.layerX !== "undefined") {
+			if (target.id === this.getDomElement().id) {
+				offsetX = e.layerX; 
+				offsetY = e.layerY; 
+				return new Point(offsetX, offsetY);
+			}
 		}
-		else{
-			clickX = e.pageX;
-			clickY = e.pageY;
+
+		// FIREFOX w/ other target
+		if (typeof e.pageX !== "undefined") { 
+			pageX = e.pageX; 
+			pageY = e.pageY; 
 		}
-
-		var currentPos = null;
-		if (this.type == "DIV" && !$.browser.msie) {
-			var mapDomElement = this.getDomElement();
-			currentPos = new Point(
-				clickX - parseInt(mapDomElement.style.left, 10), 
-				clickY - parseInt(mapDomElement.style.top, 10)
-			);
-			// if the mouse position is not on top of the map, return null
-			if (currentPos.x < 0 || currentPos.x > this.width || 
-				currentPos.y < 0 || currentPos.y > this.height) {
-				return null;
+		// IE
+		else if (typeof e.clientX !== "undefined") { 
+			pageX = e.clientX + ((
+						window.document.body && 
+						typeof window.document.body.scrollLeft !== "undefined"
+					) ?
+						window.document.body.scrollLeft : 0);
+			pageY = e.clientY + ((
+						window.document.body && 
+						typeof window.document.body.scrollTop !== "undefined"
+					) ?
+						window.document.body.scrollTop : 0);
+		}
+		var x = 0;
+		var t = (typeof(target)=='string') ? 
+			(document.getElementById ? 
+				document.getElementById(e) : 
+					(document.all ? document.all[e] : null)
+			) : target;
+		while (t) {
+			if ($(t).eq(0).attr("id") === this.getDomElement().id && typeof t.offsetLeft !== "undefined") {
+				x += t.offsetLeft;
 			}
+			t = (typeof t.offsetParent !== "undefined") ?
+				t.offsetParent : null;
 		}
-		else {
-			currentPos = new Point(
-				clickX, 
-				clickY
-			);
+		pageX -= x;
 
-			// sometimes there are divs within the map (like copyright)
-			// then offsetX and offsetY are not valid.
-			if (window.event.srcElement.tagName.toUpperCase() !== "IMG") {
-				var top = parseInt(window.event.srcElement.style.top, 10);
-				var left = parseInt(window.event.srcElement.style.left, 10);
-				currentPos = currentPos.plus(new Point(left,top));
+		var y = 0;
+		var t = (typeof(target)=='string') ? 
+			(document.getElementById ? 
+				document.getElementById(e) : 
+					(document.all ? document.all[e] : null)
+			) : target;
+		while (t) {
+			if ($(t).eq(0).attr("id") === this.getDomElement().id && typeof t.offsetTop !== "undefined") {
+				y += t.offsetTop;
 			}
-			
+			t = (typeof t.offsetParent !== "undefined") ?
+				t.offsetParent : null;
 		}
-		return currentPos;
+		pageY -= y; 
+		return new Point(pageX, pageY);
 	};
-	
 	/**
 	 * converts the extent of the mapobject so that the maximum	extent will be displayed
 	 */
@@ -870,7 +894,6 @@
 		
 		for (var ii = 0; ii < this.wms.length; ii++) {
 			var currentWms = this.wms[ii];
-		
 			try {
 				if (this.skipWmsIfSrsNotSupported && isIgnoredWms(currentWms)) {
 					continue;



More information about the Mapbender_commits mailing list