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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jul 4 05:48:17 PDT 2014


Author: hwbllmnn
Date: 2014-07-04 05:48:17 -0700 (Fri, 04 Jul 2014)
New Revision: 8987

Modified:
   trunk/mapbender/http/javascripts/mod_box1.js
   trunk/mapbender/http/javascripts/mod_selArea.js
Log:
fixed mode switching from/to zoom to box tool


Modified: trunk/mapbender/http/javascripts/mod_box1.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_box1.js	2014-07-04 12:17:02 UTC (rev 8986)
+++ trunk/mapbender/http/javascripts/mod_box1.js	2014-07-04 12:48:17 UTC (rev 8987)
@@ -1,18 +1,18 @@
 /*
  * License:
  * Copyright (c) 2009, Open Source Geospatial Foundation
- * This program is dual licensed under the GNU General Public License 
- * and Simplified BSD license.  
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
  * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
  */
 
 Mapbender.Box = function (options) {
 	var map = (typeof options.target !== "undefined") ?
 		getMapObjByName(options.target) : null;
-	
+
 	var color = (typeof options.color !== "undefined") ?
 		options.color : "#ff0000";
-	
+
 	var isActive = false;
 	var top = 0;
 	var topSuffix = "_l_top";
@@ -26,22 +26,24 @@
 	var right = 0;
 	var rightSuffix = "_l_right";
 	var rightNode;
-	
+
 	var startPos = null;
 	var stopPos = null;
-	
+
 	var exists = false;
 	var that = this;
-	
+
+    var mousemove = function(e) {
+	that.run(e);
+	return false;
+    };
+
 	this.start = function (e) {
 		if (!map) {
 			return;
 		}
-		$(map.getDomElement()).mousemove(function (e) {
-			that.run(e);
-			return false;
-		});
-		
+		$(map.getDomElement()).mousemove(mousemove);
+
 		isActive = true;
 		var click = map.getMousePosition(e);
 		startPos = new Point(click.x, click.y);
@@ -52,7 +54,7 @@
 		right = click.x;
 
 	};
-	
+
 	this.run = function (e) {
 		var pos = map.getMousePosition(e);
 		if (pos !== null) {
@@ -76,23 +78,23 @@
 				top = startPos.y;
 				bottom = stopPos.y;
 			}
-			
+
 			if (!startPos.equals(stopPos)) {
 				this.draw();
 			}
 		}
 		return true;
 	};
-	
+
 	this.stop = function (e, callback) {
-		$(map.getDomElement()).unbind("mousemove");
+		$(map.getDomElement()).unbind("mousemove", mousemove);
 
 		hideElement(topNode);
 		hideElement(leftNode);
 		hideElement(rightNode);
 		hideElement(bottomNode);
-		
-		
+
+
 		if (isActive) {
 			isActive = false;
 			if (typeof callback === "function") {
@@ -100,9 +102,9 @@
 			}
 			return getExtent();
 		}
-		isActive = false;		
+		isActive = false;
 	};
-	
+
 	var arrangeBox = function (node, left, top, right, bottom) {
 		var el = node.style;
 		el.height = Math.abs(bottom - top) + "px";
@@ -110,11 +112,11 @@
 		el.top = top + "px";
 		el.left = left + "px";
 	};
-	
+
 	var displayElement = function (node) {
 		node.style.visibility = "visible";
 	};
-	
+
 	var hideElement = function (node) {
 		node.style.visibility = "hidden";
 	};
@@ -146,16 +148,16 @@
 		topNode.style.visibility = "visible";
 		topNode.style.cursor = "crosshair";
 		topNode.style.backgroundColor = color;
-		
+
 		leftNode = topNode.cloneNode(false);
 		rightNode = topNode.cloneNode(false);
 		bottomNode = topNode.cloneNode(false);
-		
+
 		topNode.id = map.elementName + topSuffix;
 		leftNode.id = map.elementName + leftSuffix;
 		rightNode.id = map.elementName + rightSuffix;
 		bottomNode.id = map.elementName + bottomSuffix;
-		
+
 		map_el.appendChild(topNode);
 		map_el.appendChild(leftNode);
 		map_el.appendChild(rightNode);
@@ -163,20 +165,20 @@
 
 		exists = true;
 	};
-	
+
 	this.draw = function (extent) {
 		if (!map) {
 			return;
 		}
-		if (typeof extent === "object" 
+		if (typeof extent === "object"
 			&& extent.constructor === Mapbender.Extent) {
-			
+
 			left = extent.min.x;
 			right = extent.max.x;
 			bottom = extent.min.y;
 			top = extent.max.y;
 		}
-		
+
 		arrangeBox(topNode, left, top, right, top + 2);
 		arrangeBox(leftNode, left, top, left + 2, bottom);
 		arrangeBox(rightNode, right - 2, top, right, bottom);
@@ -184,7 +186,7 @@
 		displayElement(topNode);
 		displayElement(leftNode);
 		displayElement(rightNode);
-		displayElement(bottomNode);		
+		displayElement(bottomNode);
 	};
 
 	var getExtent = function () {
@@ -195,7 +197,7 @@
 		var x2 = stopPos.x;
 		var y1 = startPos.y;
 		var y2 = stopPos.y;
-		
+
 		var minx = x2;
 		var maxx = x1;
 		if(x1 < x2){
@@ -216,9 +218,9 @@
 			var posMax = map.convertPixelToReal(new Point(maxx,maxy));
 			return new Mapbender.Extent(posMin, posMax);
 		}
-		return posMin;      
+		return posMin;
 	};
-	
+
 	if (!domElementsExist()) {
 		createDomElements();
 	}
@@ -226,6 +228,6 @@
 		topNode = document.getElementById(map.elementName + topSuffix);
 		leftNode = document.getElementById(map.elementName + leftSuffix);
 		rightNode = document.getElementById(map.elementName + rightSuffix);
-		bottomNode = document.getElementById(map.elementName + bottomSuffix);		
+		bottomNode = document.getElementById(map.elementName + bottomSuffix);
 	}
 };

Modified: trunk/mapbender/http/javascripts/mod_selArea.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_selArea.js	2014-07-04 12:17:02 UTC (rev 8986)
+++ trunk/mapbender/http/javascripts/mod_selArea.js	2014-07-04 12:48:17 UTC (rev 8987)
@@ -3,83 +3,87 @@
  *
  * Description:
  * Zoom by rectangle
- * 
+ *
  * Files:
  *  - http/javascripts/mod_selArea.js
  *
  * SQL:
- * > <SQL for element> 
- * > 
- * > <SQL for element var> 
+ * > <SQL for element>
+ * >
+ * > <SQL for element var>
  *
  * Help:
  * http://www.mapbender.org/SelArea1
  *
  * Maintainer:
  * http://www.mapbender.org/User:Christoph_Baudson
- * 
+ *
  * License:
  * Copyright (c) 2009, Open Source Geospatial Foundation
- * This program is dual licensed under the GNU General Public License 
- * and Simplified BSD license.  
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
  * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
  */
 
 var that = this;
 
 Mapbender.events.init.register(function () {
-	
-	var box;
-	var map = Mapbender.modules[options.target];
-	
-	var button = new Mapbender.Button({
-		domElement: that,
-		over: options.src.replace(/_off/, "_over"),
-		on: options.src.replace(/_off/, "_on"),
-		off: options.src,
-		name: options.id,
-		go: function () {
-			if (!map) {
-				new Mb_exception(options.id + ": " + 
-					options.target + " is not a map!");
-				return;
-			}
-			
-			box = new Mapbender.Box({
-				target: options.target
-			});
-			$(map.getDomElement()).css(
-				"cursor", "crosshair"
-			).mousedown(function (e) {
-				box.start(e);
-				return false;
-			}).mouseup(function (e) {
-				box.stop(e, function (extent) {
-					if (typeof extent === "undefined") {
-						return false;
-					}
-					if (extent.constructor === Mapbender.Extent) {
-						var xt = map.calculateExtent(extent);
-						map.setMapRequest();
-					}
-					else if (extent.constructor === Mapbender.Point) {
-						map.setCenter(extent);
-						map.setMapRequest();
-					}
-				});
-				return false;
-			});
-		},
-		stop: function () {
-			if (!map) {
-				return;
-			}
-			$(map.getDomElement())
-				.css("cursor", "default")
-				.unbind("mousedown")
-				.unbind("mouseup")
-				.unbind("mousemove");
-			box = null;
-		}
-	});
+
+    var box;
+    var map = Mapbender.modules[options.target];
+
+    var mouseup = function(e) {
+        box.stop(e, function (extent) {
+            if (typeof extent === "undefined") {
+                return false;
+            }
+            if (extent.constructor === Mapbender.Extent) {
+                var xt = map.calculateExtent(extent);
+                map.setMapRequest();
+            }
+            else if (extent.constructor === Mapbender.Point) {
+                map.setCenter(extent);
+                map.setMapRequest();
+            }
+        });
+        return false;
+    };
+
+    var mousedown = function (e) {
+        box.start(e);
+        return false;
+    };
+
+    var button = new Mapbender.Button({
+        domElement: that,
+        over: options.src.replace(/_off/, "_over"),
+        on: options.src.replace(/_off/, "_on"),
+        off: options.src,
+        name: options.id,
+        go: function () {
+            if (!map) {
+                new Mb_exception(options.id + ": " +
+                                 options.target + " is not a map!");
+                return;
+            }
+
+            box = new Mapbender.Box({
+                target: options.target
+            });
+            $(map.getDomElement()).css(
+                "cursor", "crosshair"
+            ).mousedown(mousedown)
+            .mouseup(mouseup);
+        },
+        stop: function () {
+            if (!map) {
+                return;
+            }
+            $(map.getDomElement())
+            .css("cursor", "default")
+            .unbind("mousedown", mousedown)
+            .unbind("mouseup", mouseup);
+            box = null;
+        }
+    });
 });
\ No newline at end of file



More information about the Mapbender_commits mailing list