[Mapbender-commits] r5827 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Mar 22 13:49:18 EDT 2010


Author: christoph
Date: 2010-03-22 13:49:17 -0400 (Mon, 22 Mar 2010)
New Revision: 5827

Added:
   trunk/mapbender/http/plugins/mb_digitize_geometry.js
Log:


Added: trunk/mapbender/http/plugins/mb_digitize_geometry.js
===================================================================
--- trunk/mapbender/http/plugins/mb_digitize_geometry.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_digitize_geometry.js	2010-03-22 17:49:17 UTC (rev 5827)
@@ -0,0 +1,81 @@
+var $digitize = $(this);
+
+var DigitizeApi = function () {
+	var that = this;
+	var geom;
+	var settings = {
+		geometryType: "point"
+	};
+	settings = $.extend({}, settings, options);
+
+	this.events = {
+		finished: new Mapbender.Event(),
+		added: new Mapbender.Event(),
+		mousemove: new Mapbender.Event()
+	};
+
+	var mousemove = function (e) {
+		that.events.mousemove.trigger(e);
+	};
+
+	var setPoint = function (e) {
+		var map = $(this).mapbender(); 
+		var pt = map.getMousePosition(e);
+		var coord = map.convertPixelToReal(pt);
+		geom.get(-1).setEpsg(map.getSrs());
+
+		// add snapping!
+		geom.get(-1).addPoint(coord);
+		
+		that.events.added.trigger({
+			point: coord
+		});
+		
+		if (settings.geometryType === Mapbender.geometryType.point) {
+			return button.stop();
+		}
+	};
+
+	var button = new Mapbender.Button({
+		domElement: $digitize.get(0),
+		over: options.src.replace(/_off/, "_over"),
+		on: options.src.replace(/_off/, "_on"),
+		off: options.src,
+		name: options.id,
+		go: function () {
+			geom = new MultiGeometry(settings.geometryType);
+			geom.addGeometry();
+			
+			options.$target.bind("click", setPoint);
+			options.$target.bind("mousemove", mousemove);
+		},
+		stop: function () {
+			if (geom !== undefined) {
+				if (!geom.get(-1).close()) {
+					new Mapbender.Exception("Geometry could not be created.");	
+				}
+				else {
+					var json = geom.toString();
+					that.events.finished.trigger({
+						feature: json
+					});
+				}
+				geom = undefined;
+			}
+			options.$target.unbind("click", setPoint);
+			options.$target.unbind("mousemove", mousemove);
+		}
+	});
+};
+
+$digitize.mapbender(new DigitizeApi());
+
+$digitize.mapbender().events.finished.register(function (obj) {
+	console.log(obj.feature);
+});
+$digitize.mapbender().events.mousemove.register(function (obj) {
+	console.log(obj);
+});
+$digitize.mapbender().events.added.register(function (obj) {
+	console.log(obj.point);
+});



More information about the Mapbender_commits mailing list