[Mapbender-commits] r8056 - in branches/2.7/http: img/button_blue_red plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Aug 4 05:55:16 EDT 2011


Author: verenadiewald
Date: 2011-08-04 02:55:16 -0700 (Thu, 04 Aug 2011)
New Revision: 8056

Added:
   branches/2.7/http/img/button_blue_red/select_circle_off.png
   branches/2.7/http/img/button_blue_red/select_circle_on.png
   branches/2.7/http/img/button_blue_red/select_circle_over.png
Modified:
   branches/2.7/http/plugins/mb_digitize_geometry.js
Log:
added digitize option for circle

Added: branches/2.7/http/img/button_blue_red/select_circle_off.png
===================================================================
(Binary files differ)


Property changes on: branches/2.7/http/img/button_blue_red/select_circle_off.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/2.7/http/img/button_blue_red/select_circle_on.png
===================================================================
(Binary files differ)


Property changes on: branches/2.7/http/img/button_blue_red/select_circle_on.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/2.7/http/img/button_blue_red/select_circle_over.png
===================================================================
(Binary files differ)


Property changes on: branches/2.7/http/img/button_blue_red/select_circle_over.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: branches/2.7/http/plugins/mb_digitize_geometry.js
===================================================================
--- branches/2.7/http/plugins/mb_digitize_geometry.js	2011-08-04 09:33:25 UTC (rev 8055)
+++ branches/2.7/http/plugins/mb_digitize_geometry.js	2011-08-04 09:55:16 UTC (rev 8056)
@@ -3,25 +3,25 @@
  *
  * Description:
  * A button that allows to draw a geometry on maps, for example polygons.
- * 
+ *
  * For other geometries, change the element variable "geometryType", and
  * of course select another button image.
- * 
+ *
  * Files:
  *  - http/plugins/mb_digitize_geometry.js
  *
  * SQL:
- * > INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment, 
- * > e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, 
- * > e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, 
+ * > INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment,
+ * > e_title, e_element, e_src, e_attributes, e_left, e_top, e_width,
+ * > e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file,
  * > e_mb_mod, e_target, e_requires, e_url) VALUES ('<appId>',
  * > 'mb_digitize_polygon',1,1,'Digitize a polygon geometry',
  * > 'Digitize a polygon geometry','img',
  * > '../img/button_digitize/polygon_off.png','',NULL ,NULL ,24,24,NULL ,'',
  * > '','','../plugins/mb_digitize_geometry.js','','mapframe1','','');
- * > 
- * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, 
- * > var_value, context, var_type) VALUES('<appId>', 'mb_digitize_polygon', 
+ * >
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name,
+ * > var_value, context, var_type) VALUES('<appId>', 'mb_digitize_polygon',
  * > 'geometryType', 'polygon', '' ,'var');
  *
  * Help:
@@ -29,15 +29,15 @@
  *
  * Maintainer:
  * http://www.mapbender.org/User:Christoph_Baudson
- * 
+ *
  * Parameters:
- * geometryType      - (String) "polygon", "line", "point" (default) 
+ * geometryType      - (String) "polygon", "line", "point" (default)
  * 						or "rectangle"
  *
  * 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
  */
 
@@ -54,7 +54,7 @@
 	this.events = {
 		/**
 		 * Property: events.finished
-		 * 
+		 *
 		 * Description:
 		 * Triggered after the geometry has been completed.
 		 * obj.featureCollection contains the GeoJSON
@@ -62,14 +62,14 @@
 		finished: new Mapbender.Event(),
 		/**
 		 * Property: events.aborted
-		 * 
+		 *
 		 * Description:
 		 * Triggered if the geometry could not be created.
 		 */
 		aborted: new Mapbender.Event(),
 		/**
 		 * Property: events.added
-		 * 
+		 *
 		 * Description:
 		 * Triggered after a point has been added to the geometry.
 		 * obj.featureCollection contains the feature collection as GeoJSON
@@ -78,7 +78,7 @@
 		added: new Mapbender.Event(),
 		/**
 		 * Property: events.mousemove
-		 * 
+		 *
 		 * Description:
 		 * Triggered whenever a new point can be added to the geometry.
 		 * obj.featureCollection contains the feature collection as GeoJSON
@@ -88,23 +88,23 @@
 	};
 
 	var mousemove = function (e) {
-		var map = $(this).mapbender(); 
+		var map = $(this).mapbender();
 		var pt = map.getPos(e);
 		var coord = map.convertPixelToReal(pt);
-		
+
 		// compute feature collection to be delegated
 		var collection = new GeometryArray();
 		collection.importGeoJSON(featureCollection.toString(), false);
 
 		if (settings.geometryType === "point") {
-			// if a point is digitized, we discard it, as we will 
+			// if a point is digitized, we discard it, as we will
 			// display the current position anyway
 			collection = new GeometryArray();
 		}
 		else if (settings.geometryType === "rectangle") {
 			var lastPoint = collection.getPoint(-1, -1, -1);
 			if (lastPoint) {
-				// if the second point of the rectangle is set, add 
+				// if the second point of the rectangle is set, add
 				// other points to complete the polygon
 				var points = calculateRectanglePoints(lastPoint, coord);
 				if(points === undefined) {
@@ -116,8 +116,22 @@
 				collection.getGeometry(-1, -1).addPoint(points[3]);
 			}
 		}
+                else if (settings.geometryType === "circle") {
+			var lastPoint = collection.getPoint(-1, -1, -1);
+			if (lastPoint) {
+				// if the second point of the circle is set, add
+				// other points to complete the circle
+				var points = calculateCirclePoints(lastPoint, coord);
+				if(points === undefined) {
+					return;
+				}
+				for (var i = 0; i < points.length; i++) {
+                                    collection.getGeometry(-1, -1).addPoint(points[i]);
+                                }
+			}
+		}
 		else if (
-			settings.geometryType === "polygon" 
+			settings.geometryType === "polygon"
 			|| settings.geometryType === "line"
 		) {
 			var numCollections = collection.count();
@@ -127,7 +141,7 @@
 					var feature = collection.getGeometry(-1, -1);
 					var ps = feature.count();
 					// if geometry is a polygon, reopen it
-					if (ps > 1 && 
+					if (ps > 1 &&
 						feature.geomType === Mapbender.geometryType.polygon
 					) {
 						collection.delPoint(-1, -1, -1);
@@ -137,6 +151,7 @@
 				}
 			}
 		}
+
 		// display current mouse position as point
 		collection.addMember(Mapbender.geometryType.point);
 		collection.get(-1).addGeometry();
@@ -152,7 +167,7 @@
 		var q2;
 		var q3;
 		var q4;
-		
+
 		//box in northeast direction
 		if(p1.x < p3.x && p1.y < p3.y) {
 			q1 = p1;
@@ -184,7 +199,7 @@
 		else {
 			return;
 		}
-		
+
 		return [
 			q1,
 			q2,
@@ -193,27 +208,48 @@
 		];
 	};
 
+        var calculateCirclePoints = function (p1, p2) {
+            var centerPoint = p1;
+            var secondPoint = p2;
+            var radius = Math.sqrt(Math.pow(Math.abs(centerPoint.x - secondPoint.x),2)+Math.pow(Math.abs(centerPoint.y - secondPoint.y),2));
+
+            var center = [centerPoint.x, centerPoint.y];
+            var steps = 32;
+
+            var circlePoints = [];
+            for (var i = 0; i < steps + 1; i++) {
+                var newX = (center[0] + radius * Math.cos(2 * Math.PI * i / steps));
+                var newY = (center[1] + radius * Math.sin(2 * Math.PI * i / steps));
+                circlePoints[i] = new Mapbender.Point(newX, newY);
+            }
+            return circlePoints;
+	};
+
 	var setPoint = function (e) {
-		var map = $(this).mapbender(); 
+		var map = $(this).mapbender();
 		var pt = map.getPos(e);
 		var coord = map.convertPixelToReal(pt);
-		
+
 		// do not add same point twice
 		var lastPoint = featureCollection.getPoint(-1,-1,-1);
 		if (lastPoint && coord.equals(featureCollection.getPoint(-1,-1,-1))) {
 			// abort if rectangle
-			if (settings.geometryType === "rectangle") {
+                        if (
+                            settings.geometryType === "rectangle"
+                            || settings.geometryType === "circle"
+                        ) {
 				featureCollection = new GeometryArray();
-				button.stop();		
+				button.stop();
 			}
 			return false;
 		}
 
 		// add point(s)
 		if (settings.geometryType === "rectangle" && lastPoint) {
-			// if the second point of the rectangle is set, add 
+			// if the second point of the rectangle is set, add
 			// other points to complete the polygon
 			var points = calculateRectanglePoints(lastPoint, coord);
+
 			if(points === undefined) {
 				return;
 			}
@@ -222,6 +258,19 @@
 			featureCollection.getGeometry(-1, -1).addPoint(points[2]);
 			featureCollection.getGeometry(-1, -1).addPoint(points[3]);
 		}
+                else if (settings.geometryType === "circle" && lastPoint) {
+                    	// if the second point of the circle is set, add
+			// other points to complete the circle polygon
+			var points = calculateCirclePoints(lastPoint, coord);
+
+			if(points === undefined) {
+				return;
+			}
+
+                        for (var i = 0; i < points.length; i++) {
+                            featureCollection.getGeometry(-1, -1).addPoint(points[i]);
+                        }
+		}
 		else {
 			featureCollection.getGeometry(-1, -1).addPoint(coord);
 		}
@@ -233,27 +282,28 @@
 			point: coord,
 			featureCollection: featureCollection.toString()
 		});
-		
+
 		if (settings.geometryType === Mapbender.geometryType.point) {
 			return button.stop();
 		}
 	};
-	
+
 	var finishFeature = function () {
-		if (featureCollection.count() > 0 &&
+            	if (featureCollection.count() > 0 &&
 			featureCollection.getGeometry(-1, -1).close()
 		) {
-			button.stop();		
-		}
+			button.stop();
+            	}
+
 	};
-	
+
 	var correctGeometryType = function (str) {
-		if (str === "rectangle" || str === "extent") {
+		if (str === "rectangle" || str === "extent" || str === "circle") {
 			return Mapbender.geometryType.polygon;
 		}
 		return str;
 	};
-		
+
 	var prevent = function(e){ e.preventDefault(); };
 
 	var button = new Mapbender.Button({
@@ -268,8 +318,8 @@
 				correctGeometryType(settings.geometryType)
 			);
 			featureCollection.get(-1).addGeometry();
-			
-			if (settings.geometryType === "rectangle") {
+
+			if (settings.geometryType === "rectangle" || settings.geometryType === "circle") {
 				o.$target.bind("mousedown", setPoint);
 				o.$target.bind("mouseup", setPoint);
 				o.$target.bind("mouseup", finishFeature);
@@ -286,7 +336,7 @@
 				featureCollection.getGeometry(-1, -1).addPoint(points[3]);
 				featureCollection.getGeometry(-1, -1).addPoint(points[0]);
 				button.stop();
-				
+
 			}
 			else {
 				o.$target.bind("click", setPoint);
@@ -310,10 +360,10 @@
 				featureCollection.empty();
 			}
 			else {
-				new Mapbender.Exception("Geometry could not be created.");	
+				new Mapbender.Exception("Geometry could not be created.");
 				that.events.aborted.trigger();
 			}
-			if (settings.geometryType === "rectangle") {
+			if (settings.geometryType === "rectangle" || settings.geometryType === "circle") {
 				o.$target.unbind("mousedown", setPoint);
 				o.$target.unbind("mouseup", setPoint);
 				o.$target.unbind("mouseup", finishFeature);
@@ -324,7 +374,7 @@
 			}
 			o.$target.unbind("mousemove", mousemove);
 			$("body").unbind("mousedown", prevent).unbind("mouseover", prevent).unbind("mousemove", prevent);
-		
+
 		}
 	});
 };



More information about the Mapbender_commits mailing list