[Mapbender-commits] r5337 - in trunk/mapbender: http/javascripts lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jan 19 05:03:31 EST 2010


Author: christoph
Date: 2010-01-19 05:03:30 -0500 (Tue, 19 Jan 2010)
New Revision: 5337

Modified:
   trunk/mapbender/http/javascripts/geometry.js
   trunk/mapbender/http/javascripts/map_obj.js
   trunk/mapbender/http/javascripts/mod_digitize_tab.php
   trunk/mapbender/lib/backwards_compatibility_to_2.6.js
   trunk/mapbender/lib/basic.js
   trunk/mapbender/lib/customTreeModel.js
   trunk/mapbender/lib/extent.js
   trunk/mapbender/lib/list.js
   trunk/mapbender/lib/resultGeometryListModel.js
Log:
refactoring

Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/http/javascripts/geometry.js	2010-01-19 10:03:30 UTC (rev 5337)
@@ -318,8 +318,8 @@
 
 GeometryArray.prototype.getBBox = function(){
 	var q = this.get(0).get(0).get(0);
-	var min = cloneObject(q);
-	var max = cloneObject(q);
+	var min = Mapbender.cloneObject(q);
+	var max = Mapbender.cloneObject(q);
 	for(var i=0; i < this.count();i++){
 		var pos = this.get(i).getBBox();
 		if (pos[0].x < min.x) {min.x = pos[0].x;}
@@ -701,8 +701,8 @@
  */
 MultiGeometry.prototype.getBBox = function(){
 	var q = this.get(0).get(0);
-	var min = cloneObject(q);
-	var max = cloneObject(q);
+	var min = Mapbender.cloneObject(q);
+	var max = Mapbender.cloneObject(q);
 	for(var i=0; i<this.count();i++){
 		var pos = this.get(i).getBBox();
 		if (pos[0].x < min.x) {min.x = pos[0].x;}
@@ -1239,8 +1239,8 @@
  */
 Geometry.prototype.getBBox = function(){
 	var q = this.get(0);
-	var min = cloneObject(q);
-	var max = cloneObject(q);
+	var min = Mapbender.cloneObject(q);
+	var max = Mapbender.cloneObject(q);
 	
 	for (var j=0; j<this.count(); j++){
 		var pos = this.get(j);

Modified: trunk/mapbender/http/javascripts/map_obj.js
===================================================================
--- trunk/mapbender/http/javascripts/map_obj.js	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/http/javascripts/map_obj.js	2010-01-19 10:03:30 UTC (rev 5337)
@@ -384,7 +384,7 @@
                 // Now, this is a copy!
                 // Each map object has its own set of WMS.
                 // I expect some things to break :-)
-                this.wms[index] = cloneObject(wms[i]);
+                this.wms[index] = Mapbender.cloneObject(wms[i]);
                 this.wms[index].mapURL = false;
                 index++;
             }

Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php	2010-01-19 10:03:30 UTC (rev 5337)
@@ -412,7 +412,7 @@
 					if (firstPointSnapped) {
 						// reverse line!
 						// we can only add points to the end of the line, not insert them at the beginning
-						var oldLine = parent.cloneObject(d.getGeometry(i, -1));
+						var oldLine = parent.Mapbender.cloneObject(d.getGeometry(i, -1));
 						var newLine = d.getGeometry(i, -1);
 						var len = oldLine.count();
 						for (var j = len-1; j >= 0; j--) {
@@ -753,13 +753,13 @@
 
 	var oldPoint;
 	if (k == undefined) {
-		oldPoint = parent.cloneObject(d.getPoint(i,j,l));
+		oldPoint = parent.Mapbender.cloneObject(d.getPoint(i,j,l));
 	} 
 	else {
-		oldPoint = parent.cloneObject(d.getPoint(i,j,k,l));
+		oldPoint = parent.Mapbender.cloneObject(d.getPoint(i,j,k,l));
 	}
 	if (s.isSnapped()) {
-		var snappedPoint = parent.cloneObject(s.getSnappedPoint());
+		var snappedPoint = parent.Mapbender.cloneObject(s.getSnappedPoint());
 		if (!nonTransactionalEditable) {
 			updateAllPointsOfNonTransactionalLike(oldPoint, snappedPoint);
 		}

Modified: trunk/mapbender/lib/backwards_compatibility_to_2.6.js
===================================================================
--- trunk/mapbender/lib/backwards_compatibility_to_2.6.js	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/lib/backwards_compatibility_to_2.6.js	2010-01-19 10:03:30 UTC (rev 5337)
@@ -1,3 +1,97 @@
+var clickX;
+var clickY;
+
+// transparent GIF
+var mb_trans = new Image(); 
+mb_trans.src = "../img/transparent.gif";
+
+/*
+ * get the conjunction character of an URL
+ * @param {String} onlineresource
+ * @return the character & or ?
+ * @type String
+ */
+var mb_getConjunctionCharacter = Mapbender.getConjunctionChar;
+
+
+function mb_showHighlight(frameName,x,y){
+	var map = getMapObjByName(frameName);
+	if (map !== null) {
+		var p = map.convertRealToPixel(new Point(x, y));
+		
+		var map_el = map.getDomElement();
+		var $highlight = $("#" + map.elementName + "_highlight");
+		if($highlight.size() === 0) {
+			//create Box Elements
+			$highlight = $("<div id='" + map.elementName+ "_highlight' style='position:absolute;top:-10px;left:-10px;width:14px;height:14px;z-index:3;visibility:visible'><img src='../img/redball.gif'/></div>");
+			$(map_el).append($highlight);
+		}
+		$highlight.css("visibility", "visible");
+	}
+	mb_arrangeElement(map.frameName, map.elementName+ "_highlight" ,p.x-7, p.y-7);
+}
+
+function mb_hideHighlight(frameName){
+	var map = getMapObjByName(frameName);
+	if (map !== null) {
+		var map_el = map.getDomElement();
+		mb_arrangeElement(map.frameName, map.elementName + "_highlight", -20, -20);
+		$(map.elementName + "_highlight").css("visibility", "hidden");
+	}
+}
+
+var cloneObject = Mapbender.cloneObject;
+
+/**
+ * @deprecated 
+ * @param {Object} e
+ * @param {Object} fName
+ */
+function mb_getMousePos(e,fName){
+
+	var warning = new Mb_warning("The function mb_getMousePos is deprecated, use the map objects getMousePosition.");
+
+	if(fName){
+		if(ie){
+			clickX = window.frames[fName].event.clientX;
+			clickY = window.frames[fName].event.clientY;
+		}
+		else{
+			clickX = e.pageX;
+			clickY = e.pageY;
+		}
+	}
+	else{
+		if(ie){
+			clickX = event.clientX;
+			clickY = event.clientY;
+		}
+		else{
+			clickX = e.pageX;
+			clickY = e.pageY;
+		}
+	}
+	var pos = [clickX,clickY];
+	return pos;
+}
+
+function mb_arrangeElement(frameName, elName, left, top) {
+   if(frameName !== ""){
+      window.frames[frameName].document.getElementById(elName).style.top = String(top) + "px";
+      window.frames[frameName].document.getElementById(elName).style.left = String(left) + "px";
+   }
+   else{
+      try {
+	      var s = document.getElementById(elName);
+		  s.style.position = "absolute";
+		  s.style.top = String(top) + "px";
+	      s.style.left = String(left) + "px";   
+      }
+      catch (exc) {
+      }
+   }
+}
+
 var ie = $.browser.msie;
 var n6 = document.getElementById&&!document.all?1:0;
 var n4 = document.layers?1:0;
@@ -67,5 +161,3 @@
 		var error = new Mb_exception('map.php: mb_ajax_json:'+e);
 	}
 }
-
-

Modified: trunk/mapbender/lib/basic.js
===================================================================
--- trunk/mapbender/lib/basic.js	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/lib/basic.js	2010-01-19 10:03:30 UTC (rev 5337)
@@ -9,9 +9,52 @@
 	return (typeof $(obj).mapbender() !== "undefined");
 };
 
-//
-// mapbender jQuery plugin
-//
+/**
+ * Package: mapbender
+ *
+ * Description:
+ * This jQuery plugin grants access to the Mapbender API from a DOM element.
+ * You can supply various arguments to achieve different things:
+ * 
+ * Passing no arguments will return the API object of the Mapbender element
+ * associated with the DOM element, usage
+ * 
+ * var api = $("#myelement").mapbender();
+ * 
+ * Passing an object serves as a setter: the object is the new API object 
+ * associated with the DOM element, usage
+ * 
+ * $("#myelement").mapbender(new CustomApiObject());
+ * 
+ * Passing a string serves as an attribute getter. It returns the value of
+ * any public attribute of the API object, usage
+ * 
+ * $("#myelement").mapbender("aSpecificAttribute")
+ * 
+ * Passing a function executes the function in the scope of the API object.
+ * This is a shortcut to fetching the API object first, and then calling its
+ * method. By this, you don't need to check whether the API object exists, 
+ * if none exists, the function is simply not executed. Usage
+ * 
+ * $("#myelement").mapbender(function () {
+ * 		// this refers to the API object!!
+ * 		console.log(this.options);
+ * });
+ * 
+ * 
+ * Files:
+ *  - lib/basic.js
+ *
+ * Maintainer:
+ * http://www.mapbender.org/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.  
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+
 $.fn.mapbender = function () {
 	var id = this.attr("id");
 	
@@ -52,129 +95,65 @@
 				new Mb_exception("Module " + id + " is not present!");
 				return this;
 			}
-			return closure.call(module)
+			return closure.call(module);
 		});
 	}
 };
 
-
-var clickX;
-var clickY;
-
-// transparent GIF
-var mb_trans = new Image(); 
-mb_trans.src = "../img/transparent.gif";
-
-/*
- * get the conjunction character of an URL
- * @param {String} onlineresource
- * @return the character & or ?
- * @type String
+/**
+ * Method: cookiesEnables
+ * 
+ * Description:
+ * Checks whether cookies are enabled in the browser
  */
-function mb_getConjunctionCharacter(onlineresource){
-	var conChar;
-	if(onlineresource.indexOf("?") > -1){ 
-		if(onlineresource.charAt(onlineresource.length-1) == "?"){ 
-			conChar = "";
-		}else if(onlineresource.charAt(onlineresource.length-1) == "&"){
-			conChar = "";
-		}else{
-			conChar = "&";
-		}
-	}
-	if(onlineresource.indexOf("?") == -1){
-		conChar = "?";
-	} 
-	return conChar;  
-}
 
-function mb_showHighlight(frameName,x,y){
-	var map = getMapObjByName(frameName);
-	if (map !== null) {
-		var p = map.convertRealToPixel(new Point(x, y));
-		
-		var map_el = map.getDomElement();
-		var $highlight = $("#" + map.elementName + "_highlight");
-		if($highlight.size() === 0) {
-			//create Box Elements
-			$highlight = $("<div id='" + map.elementName+ "_highlight' style='position:absolute;top:-10px;left:-10px;width:14px;height:14px;z-index:3;visibility:visible'><img src='../img/redball.gif'/></div>");
-			$(map_el).append($highlight);
-		}
-		$highlight.css("visibility", "visible");
-	}
-	mb_arrangeElement(map.frameName, map.elementName+ "_highlight" ,p.x-7, p.y-7);
-}
+Mapbender.cookiesEnabled = function () {
+    var dt = new Date();
+    dt.setSeconds(dt.getSeconds() + 60);
+    document.cookie = "cookietest=1; expires=" + dt.toGMTString();
+    return document.cookie.indexOf("cookietest=") != -1;
+};
 
-function mb_hideHighlight(frameName){
-	var map = getMapObjByName(frameName);
-	if (map !== null) {
-		var map_el = map.getDomElement();
-		mb_arrangeElement(map.frameName, map.elementName + "_highlight", -20, -20);
-		$(map.elementName + "_highlight").css("visibility", "hidden");
-	}
-}
-
-function cloneObject (p, c) {
-	var c = c || {};
+/**
+ * Method: cloneObject
+ * 
+ * Description:
+ * Clone an object recursively. Make sure the object is not circular!
+ * 
+ * Parameters:
+ * p      - an object
+ */
+Mapbender.cloneObject = function (p, c) {
+	var d = c || {};
 	for (var i in p) {
 		if (typeof p[i] === 'object' && p[i] !== null) {
-			c[i] = (p[i].constructor === Array) ? [] : {};
-			cloneObject(p[i], c[i]);
+			d[i] = (p[i].constructor === Array) ? [] : {};
+			Mapbender.cloneObject(p[i], d[i]);
 		}
 		else {
-			c[i] = p[i];
+			d[i] = p[i];
 		}
 	}
-	return c;
-}
+	return d;
+};
 
-
 /**
- * @deprecated 
- * @param {Object} e
- * @param {Object} fName
+ * Method: getConjunctionChar
+ * 
+ * Description:
+ * returns the character necessary to append to a string 
+ * in order to attach more GET parameters
+ * 
+ * Parameters:
+ * url      - the online resource
  */
-function mb_getMousePos(e,fName){
-
-	var warning = new Mb_warning("The function mb_getMousePos is deprecated, use the map objects getMousePosition.");
-
-	if(fName){
-		if(ie){
-			clickX = window.frames[fName].event.clientX;
-			clickY = window.frames[fName].event.clientY;
+Mapbender.getConjunctionChar = function (url) {
+	if (url.indexOf("?") > -1) { 
+		var c = url.charAt(url.length - 1);
+		if(c == "&" || c == "?") {
+			return "";
 		}
-		else{
-			clickX = e.pageX;
-			clickY = e.pageY;
-		}
+		return "&";
 	}
-	else{
-		if(ie){
-			clickX = event.clientX;
-			clickY = event.clientY;
-		}
-		else{
-			clickX = e.pageX;
-			clickY = e.pageY;
-		}
-	}
-	var pos = [clickX,clickY];
-	return pos;
-}
-
-function mb_arrangeElement(frameName, elName, left, top) {
-   if(frameName !== ""){
-      window.frames[frameName].document.getElementById(elName).style.top = String(top) + "px";
-      window.frames[frameName].document.getElementById(elName).style.left = String(left) + "px";
-   }
-   else{
-      try {
-	      var s = document.getElementById(elName);
-		  s.style.position = "absolute";
-		  s.style.top = String(top) + "px";
-	      s.style.left = String(left) + "px";   
-      }
-      catch (exc) {
-      }
-   }
-}
\ No newline at end of file
+	return "?";
+};
\ No newline at end of file

Modified: trunk/mapbender/lib/customTreeModel.js
===================================================================
--- trunk/mapbender/lib/customTreeModel.js	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/lib/customTreeModel.js	2010-01-19 10:03:30 UTC (rev 5337)
@@ -66,7 +66,7 @@
 	 * @param {Object} item an object
 	 */
 	this.addCopy = function(item) {
-		this.add(cloneObject(item));
+		this.add(Mapbender.cloneObject(item));
 	};
 	/**
 	 * attaches the {@link List} aList to this {@link List}

Modified: trunk/mapbender/lib/extent.js
===================================================================
--- trunk/mapbender/lib/extent.js	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/lib/extent.js	2010-01-19 10:03:30 UTC (rev 5337)
@@ -117,7 +117,7 @@
 	};
 	
 	if (isExtent(minx)) {
-		this.set(cloneObject(minx.min), cloneObject(minx.max));
+		this.set(Mapbender.cloneObject(minx.min), Mapbender.cloneObject(minx.max));
 	}
 	else if (isPoint(minx) && isPoint(miny) && 
 		typeof maxx === "undefined" && 

Modified: trunk/mapbender/lib/list.js
===================================================================
--- trunk/mapbender/lib/list.js	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/lib/list.js	2010-01-19 10:03:30 UTC (rev 5337)
@@ -72,7 +72,7 @@
 	 * @param {Object} item an object
 	 */
 	this.addCopy = function(item) {
-		this.add(cloneObject(item));
+		this.add(Mapbender.cloneObject(item));
 	};
 	/**
 	 * attaches the {@link List} aList to this {@link List}

Modified: trunk/mapbender/lib/resultGeometryListModel.js
===================================================================
--- trunk/mapbender/lib/resultGeometryListModel.js	2010-01-19 10:02:44 UTC (rev 5336)
+++ trunk/mapbender/lib/resultGeometryListModel.js	2010-01-19 10:03:30 UTC (rev 5337)
@@ -102,7 +102,7 @@
 		if (geomArray.count() <= index) {
 			return false;
 		}
-		var feature = cloneObject(this.get(index));
+		var feature = Mapbender.cloneObject(this.get(index));
 		this.del(index);
 		this.events.deleted.trigger({
 			index: index,



More information about the Mapbender_commits mailing list