[Mapbender-commits] r4769 - branches/astroidex_25/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Oct 2 17:47:46 EDT 2009


Author: astrid_emde
Date: 2009-10-02 17:47:45 -0400 (Fri, 02 Oct 2009)
New Revision: 4769

Added:
   branches/astroidex_25/http/javascripts/mod_perimeter.js
Log:
moving module perimeter to new structure

http://www.mapbender.org/Perimeter
http://www.mapbender.org/Write_a_Mapbender_module

Added: branches/astroidex_25/http/javascripts/mod_perimeter.js
===================================================================
--- branches/astroidex_25/http/javascripts/mod_perimeter.js	                        (rev 0)
+++ branches/astroidex_25/http/javascripts/mod_perimeter.js	2009-10-02 21:47:45 UTC (rev 4769)
@@ -0,0 +1,159 @@
+/**
+ * Package: perimeter
+ *
+ * Description:
+ * Klick in the map, choose a perimeter. Mapbender draws a circle on he map.
+ * 
+ * Files:
+ *  - http/javascripts/mod_perimeter.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, e_mb_mod, 
+ * > e_target, e_requires, e_url) VALUES('gui1_perimeter','perimeter',2,1,
+ * > 'draw a circle','Perimeter - Umkreis markieren','img','../img/button_gray/perimeter_off.png',
+ * > '',900,20,24,24,1,'','','','../javascripts/mod_perimeter.js','','mapframe1','','');
+ * >
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, 
+ * > context, var_type) VALUES('gui1', 'perimeter', 'mod_perimeter_color',
+ * > '#ff0000', 'draw ellipse with this color' ,'var');
+ * > 
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, 
+ * > var_value, context, var_type) VALUES('gui1', 'perimeter', 
+ * > 'mod_perimeter_error', 'Fehlerhafte Eingabe', 'error message for invalid input values' ,'var');
+ * >
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, 
+ * > context, var_type) VALUES('gui1', 'perimeter', 'mod_perimeter_text', 
+ * > 'Bitte geben Sie den Radius in Metern ein:', 'display this message on prompt' ,'var');
+ * >
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, 
+ * > context, var_type) VALUES('gui1', 'perimeter', 'mod_perimeter_thickness', '2', 
+ * > 'draw ellipse with this thickness' ,'var'); 
+ * > 
+ *
+ * Help:
+ * http://www.mapbender.org/Perimeter
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Astrid_Emde
+ * 
+ * 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
+ */
+
+var that = this;
+
+Mapbender.events.init.register(function () {
+	
+	var mb_perimeterActive = false;
+	var klickPos;
+	var myMapObj = Mapbender.modules[options.target];
+
+if (!options.mod_perimeter_color) {
+	options.mod_perimeter_color = "#000000";
+}
+var mod_perimeter_color = options.mod_perimeter_color;
+
+if (!options.mod_perimeter_thickness) {
+	options.mod_perimeter_thickness = 2;
+}
+var mod_perimeter_thickness = options.mod_perimeter_thickness;
+
+if (!options.mod_perimeter_text) {
+	options.mod_perimeter_text = "Please insert a radius: ";
+}
+var mod_perimeter_text = options.mod_perimeter_text;
+
+if (!options.mod_perimeter_error) {
+	options.mod_perimeter_error = "Invalid Input";
+}
+var mod_perimeter_error = options.mod_perimeter_error;
+
+function mod_perimeter_validate(u){
+	if(isNaN(u) == true){
+  		alert(mod_perimeter_error);
+  		return false;
+ 	}
+ 	else{
+		return parseInt(u);
+ 	}
+}
+function mod_perimeter_prepare(){
+	cw_opacity=1;
+	mod_perimeter_checkDefaults();	
+	var attributes = new Array();
+	attributes[0] = new Array();
+	attributes[0][0] = "style";
+	attributes[0][1] = "position:absolute; top:0px; left:0px; z-index:100; font-size:10px;"; 
+	var node = mb_checkTag(myMapObj, "div", "perimeter", "body", attributes);
+	mod_perimeter_canvas = new jsGraphics("perimeter", myMapObj);
+	mod_perimeter_canvas.setStroke(mod_perimeter_thickness);
+	mod_perimeter_canvas.setColor(mod_perimeter_color);
+}
+function mod_perimeter_draw(){
+	if(mb_perimeterActive == true){
+		//mod_perimeter_disable();
+		var widthHeight = new Mapbender.Point(
+			myMapObj.getWidth(),
+			myMapObj.getHeight()
+		);		
+		var realCenter = map.convertPixelToReal(widthHeight);  
+		
+		//var posCenter = makeRealWorld2mapPos(myMapObj,mod_perimeter_x, mod_perimeter_y);
+		var realCenter = map.convertPixelToReal(center);  
+		
+		var posRadius = makeRealWorld2mapPos(myMapObj,(mod_perimeter_x + mod_perimeter_r), mod_perimeter_y);
+		var pxRadius =  posRadius[0] - posCenter[0];
+		mod_perimeter_canvas.drawEllipse((posCenter[0]-pxRadius), (posCenter[1]-pxRadius), pxRadius*2, pxRadius*2);
+		mod_perimeter_canvas.paint();
+	}
+}
+	
+	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 (!myMapObj) {
+				new Mb_exception(options.id + ": " + 
+					options.target + " is not a map!");
+				return;
+			}
+			$(myMapObj.getDomElement()).css("cursor", "crosshair")
+				.click(function (e) {
+				mb_perimeterActive = true;
+				klickPos = myMapObj.getMousePosition(e);
+				new Mb_exception(options.id + ": " + 
+					options.target + " klickPos " + klickPos + "check color: " + mod_perimeter_color+mod_perimeter_text+mod_perimeter_error+mod_perimeter_thickness);				
+				mod_perimeter_x = klickPos[0];
+				mod_perimeter_y = klickPos[1];
+				var units = prompt(mod_perimeter_text);
+				var myUnits = mod_perimeter_validate(units);
+				if(myUnits != false){
+				mod_perimeter_r = myUnits;
+				mod_perimeter_draw();
+	}
+	else{
+		mod_perimeter_click(mod_perimeter_img_obj);	
+	}
+	mod_perimeter_restoreEvents();	
+				return true;
+			});
+		},
+		stop: function () {
+			if (!myMapObj) {
+				return false;
+			}
+			$(myMapObj.getDomElement())
+				.css("cursor", "pointer")
+				.unbind("click")
+				mb_perimeterActive = false;
+		}
+	});
+});



More information about the Mapbender_commits mailing list