[Mapbender-commits] r4269 - in trunk/mapbender: core http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 1 10:29:37 EDT 2009


Author: christoph
Date: 2009-07-01 10:29:37 -0400 (Wed, 01 Jul 2009)
New Revision: 4269

Added:
   trunk/mapbender/http/javascripts/mod_doubleclickZoom.js
   trunk/mapbender/http/javascripts/mod_mousewheelZoom.js
Modified:
   trunk/mapbender/core/system.php
   trunk/mapbender/http/javascripts/map.php
   trunk/mapbender/http/javascripts/mapnf.php
Log:
http://trac.osgeo.org/mapbender/ticket/489

Modified: trunk/mapbender/core/system.php
===================================================================
--- trunk/mapbender/core/system.php	2009-07-01 14:28:22 UTC (rev 4268)
+++ trunk/mapbender/core/system.php	2009-07-01 14:29:37 UTC (rev 4269)
@@ -34,12 +34,10 @@
 #
 define("LOG_LEVEL_LIST", "off,error,warning,notice,all");
 
-define("ZOOM_MOUSEWHEEL", "1.1");
-
 define("MODULES_NOT_RELYING_ON_GLOBALS",
 	"mapframe1,featureInfo1,gazetteerWFS,back,forward,zoomCoords,zoomFull,zoomIn1," .
 	"zoomOut1,selArea1,pan1,copyright,dependentDiv,dragMapSize," .
 	"dynamicOverview,FeatureInfoRedirect,highlightPOI,navFrame,sandclock," .
 	"scaleBar,scaleSelect,setBBOX,setPOI2Scale,reload,overview,addWMS," . 
-	"repaint,changeEPSG"
+	"repaint,changeEPSG,mousewheelZoom,doubleclickZoom"
 );

Modified: trunk/mapbender/http/javascripts/map.php
===================================================================
--- trunk/mapbender/http/javascripts/map.php	2009-07-01 14:28:22 UTC (rev 4268)
+++ trunk/mapbender/http/javascripts/map.php	2009-07-01 14:29:37 UTC (rev 4269)
@@ -63,7 +63,6 @@
 echo "Mapbender.versionNumber = '" . MB_VERSION_NUMBER . "';";
 echo "Mapbender.versionAppendix = '" . MB_VERSION_APPENDIX . "';";
 echo "Mapbender.releaseDate = new Date(".date("Y",MB_RELEASE_DATE).",".date("n",MB_RELEASE_DATE).",".date("j",MB_RELEASE_DATE).");";
-echo "Mapbender.zoomMousewheel = " . ZOOM_MOUSEWHEEL . ";";
 echo "var owsproxy = '".OWSPROXY."';";
 echo "var global_mb_log_js = '".LOG_JS."';";
 echo "var global_mb_log_level = '".LOG_LEVEL."';";
@@ -202,7 +201,7 @@
 			if (!file_exists($currentFile)) {
 				$e = new mb_exception("Javascript not found: " . $currentFile);
 				echo "var e = new Mb_exception('Javascript not found: " . $currentFile . "');";
-				die;
+				continue;
 			}
 			if (in_array($e_id, $modulesNotRelyingOnGlobalsArray)) {
 				ob_start();
@@ -246,6 +245,7 @@
 				echo "};\n";
 				require($currentFile);
 			}
+			$e = new mb_notice("LOADING JS : " . $currentFile);
 		}
 	}
 }

Modified: trunk/mapbender/http/javascripts/mapnf.php
===================================================================
--- trunk/mapbender/http/javascripts/mapnf.php	2009-07-01 14:28:22 UTC (rev 4268)
+++ trunk/mapbender/http/javascripts/mapnf.php	2009-07-01 14:29:37 UTC (rev 4269)
@@ -17,78 +17,34 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 ?>
-	var mapTimeout;
-	var	sum_delta = 0;
-	var lastTimestamp;
-	var lastScrollPosition;
-		
 
-	eventInitMap.register(function () {
-		
-		Mapbender.modules[options.id] = new Mapbender.Map (
-			'', 
-			options.id, 
-			options.width, 
-			options.height, 
-			null
-		);
-		mb_mapObj.push(Mapbender.modules[options.id]);
-		var mapObject = Mapbender.modules[options.id];
-		
-		try {
-			if (restrictedExtent !== '') {
-				mapObject.setRestrictedExtent(restrictedExtent);
-			}
-		}
-		catch (e) {
-			new Mb_notice("Restricted extent not set via element variable.");
-		}
-		
-		$(document).mousewheel(function (e, delta) {
-			if (sum_delta == 0) {
-				mapTimeout = setTimeout(function () {
-						lastScrollPosition = mapObject.getMousePosition(e);
-						mousewheelZoom();	
-					}, 
-					100);
-			}
-			sum_delta = sum_delta + (delta);
-			var currentTime = new Date();
-			lastTimestamp = currentTime.getTime();
-			
-			return false;
-		});
-	});
+var $this = $(this);
+
+eventInitMap.register(function () {
 	
-	function mousewheelZoom () {
-		var currentTime = new Date();
+	$this.html('<div id="'+options.id+'_maps" name="maps" style ="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index:2;"></div>');
+
+	Mapbender.modules[options.id] = new Mapbender.Map (
+		'', 
+		options.id, 
+		options.width, 
+		options.height, 
+		null
+	);
 	
-		if (currentTime.getTime() - lastTimestamp > 200) {
-			if (lastScrollPosition !== null) {
-				var pos = mapObject.convertPixelToReal(lastScrollPosition);
+	mb_mapObj.push(Mapbender.modules[options.id]);
+	var mapObject = Mapbender.modules[options.id];
 	
-				if (sum_delta > 0) {
-					mapObject.zoom(true, Math.pow(Mapbender.zoomMousewheel, sum_delta), pos.x, pos.y);
-				}
-				else {
-					mapObject.zoom(false, Math.pow(Mapbender.zoomMousewheel, -sum_delta), pos.x, pos.y);
-				}
-				
-				var newPos = new Point();
-				newPos.x = mapObject.width - lastScrollPosition.x;
-				newPos.y = mapObject.height - lastScrollPosition.y;
-						
-				var posAfterZoom = mapObject.convertPixelToReal(newPos);
-				mapObject.zoom(false, 1.0, posAfterZoom.x, posAfterZoom.y);
-			}			
-			sum_delta = 0;
-			clearTimeout(mapTimeout);
+	//
+	// set restricted extent
+	//
+	try {
+		if (restrictedExtent !== '') {
+			mapObject.setRestrictedExtent(restrictedExtent);
 		}
-		else {
-			mapTimeout = setTimeout(function () {
-					mousewheelZoom(sum_delta);	
-				}, 
-				100
-			);
-		}
 	}
+	catch (e) {
+		new Mb_notice("Restricted extent not set via element variable.");
+	}
+	
+});

Added: trunk/mapbender/http/javascripts/mod_doubleclickZoom.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_doubleclickZoom.js	                        (rev 0)
+++ trunk/mapbender/http/javascripts/mod_doubleclickZoom.js	2009-07-01 14:29:37 UTC (rev 4269)
@@ -0,0 +1,102 @@
+/**
+ * Package: <Application element name>
+ *
+ * Description:
+ * Adds behaviour to maps specified in the target field.
+ * Zoom in on left double click, zoom out on right double click.
+ * Deactivates the browser contextmenu!
+ * 
+ * Files:
+ *  - http/javascripts/mod_doubleclickZoom.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 ('<gui_id>', 
+ * > 'doubleclickZoom',2,1,'adds doubleclick zoom to map module (target). 
+ * > Deactivates the browser contextmenu!!!','Doubleclick zoom','div', 
+ * > '','',NULL ,NULL ,NULL ,NULL ,NULL ,'','','div',
+ * > 'mod_doubleclickZoom.js','','mapframe1','','');
+ *
+ * Help:
+ * http://www.mapbender.org/DoubleclickZoom
+ *
+ * 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.  
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+
+eventInit.register(function () {
+
+	for (var i in options.target) {
+		(function () {
+		
+			var currentTarget = options.target[i];
+	
+			var mapObject = Mapbender.modules[currentTarget];
+			
+			//
+			// Zoom out on right double click
+			//
+			mapObject.doubleClickZoomOut = function (lastScrollPosition) {
+				var pos = mapObject.convertPixelToReal(lastScrollPosition);
+				this.zoom(false, 2.0, pos.x, pos.y);
+		
+				var newPos = new Point();
+				newPos.x = this.width - lastScrollPosition.x;
+				newPos.y = this.height - lastScrollPosition.y;
+						
+				var posAfterZoom = this.convertPixelToReal(newPos);
+				this.zoom(false, 1.0, posAfterZoom.x, posAfterZoom.y);
+			};
+			
+			//
+			// Zoom in on left double click
+			//
+			mapObject.doubleClickZoomIn = function (lastScrollPosition) {
+				var pos = mapObject.convertPixelToReal(lastScrollPosition);
+				this.zoom(true, 2.0, pos.x, pos.y);
+		
+				var newPos = new Point();
+				newPos.x = this.width - lastScrollPosition.x;
+				newPos.y = this.height - lastScrollPosition.y;
+						
+				var posAfterZoom = this.convertPixelToReal(newPos);
+				this.zoom(false, 1.0, posAfterZoom.x, posAfterZoom.y);
+			};
+		
+			//
+			// add doubleclick behaviour
+			//
+			$("#" + currentTarget).dblclick(function (e) {
+				mapObject.doubleClickZoomIn(mapObject.getMousePosition(e));
+			}).bind('contextmenu',function(){ 
+				return false 
+			}).mouseup(function(e){
+				var rightclick = (e.which) ? (e.which == 3) : (e.button == 2);
+				var t = $(this);
+				if (rightclick) {
+					if (t.data('rightclicked')) {
+						mapObject.doubleClickZoomOut(mapObject.getMousePosition(e));
+		
+						t.data('rightclicked',false);
+						clearTimeout(t.data('rcTimer'));
+					} else {
+						t.data('rightclicked',true);
+						t.data('rcTimer',setTimeout((function(t){ 
+							return function(){ 
+								t.data('rightclicked', false); 
+							} 
+						})(t), 800));
+					};
+				};
+			}); 
+		}());
+	}
+});
\ No newline at end of file

Added: trunk/mapbender/http/javascripts/mod_mousewheelZoom.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_mousewheelZoom.js	                        (rev 0)
+++ trunk/mapbender/http/javascripts/mod_mousewheelZoom.js	2009-07-01 14:29:37 UTC (rev 4269)
@@ -0,0 +1,112 @@
+/**
+ * Package: mousewheelZoom
+ *
+ * Description:
+ * Zoom in/out with the mousewheel. Specify maps in target field.
+ * 
+ * Files:
+ *  - http/javascripts/mod_mousewheelZoom.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('<gui_id>','mousewheelZoom',
+ * > 2,1,'adds mousewheel zoom to map module (target)','Mousewheel zoom',
+ * > 'div','','',NULL ,NULL ,NULL ,NULL ,NULL ,'','','div',
+ * > 'mod_mousewheelZoom.js','','mapframe1','','');
+ * >
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, 
+ * > context, var_type) VALUES('<gui_id>', 'mousewheelZoom', 'factor', '2', 
+ * > 'The factor by which the map is zoomed on each mousewheel unit' ,'var');
+ *
+ * Help:
+ * http://www.mapbender.org/MousewheelZoom
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ * 
+ * Parameters:
+ * factor    - *[optional]* {Float} The factor by which the map is zoomed on 
+ * 					each mousewheel unit. Default is 2.
+ *
+ * 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
+ */
+
+ 
+if (options.factor === undefined) {
+	options.factor = 2;
+}
+
+eventInit.register(function () {
+
+	for (var i in options.target) {
+		(function () {
+		
+			var currentTarget = options.target[i];
+	
+			var mapTimeout;
+			var	sum_delta = 0;
+			var lastTimestamp;
+			var lastScrollPosition;
+			var zoomMousewheel = options.factor;
+		
+			var mapObject = Mapbender.modules[currentTarget];
+			mapObject.mousewheelZoom = function () {
+				var currentTime = new Date();
+			
+				if (currentTime.getTime() - lastTimestamp > 200) {
+					if (lastScrollPosition !== null) {
+						var pos = mapObject.convertPixelToReal(lastScrollPosition);
+			
+						if (sum_delta > 0) {
+							this.zoom(true, Math.pow(zoomMousewheel, sum_delta), pos.x, pos.y);
+						}
+						else {
+							this.zoom(false, Math.pow(zoomMousewheel, -sum_delta), pos.x, pos.y);
+						}
+						
+						var newPos = new Point();
+						newPos.x = this.width - lastScrollPosition.x;
+						newPos.y = this.height - lastScrollPosition.y;
+								
+						var posAfterZoom = this.convertPixelToReal(newPos);
+						this.zoom(false, 1.0, posAfterZoom.x, posAfterZoom.y);
+					}			
+					sum_delta = 0;
+					clearTimeout(mapTimeout);
+				}
+				else {
+					var that = this;
+					mapTimeout = setTimeout(function () {
+							that.mousewheelZoom();	
+						}, 
+						100
+					);
+				}
+			};
+		
+			//
+			// add mousewheel behaviour
+			//
+			$("#" + currentTarget).mousewheel(function (e, delta) {
+				if (sum_delta == 0) {
+					mapTimeout = setTimeout(function () {
+							lastScrollPosition = mapObject.getMousePosition(e);
+							mapObject.mousewheelZoom();	
+						}, 
+						100);
+				}
+				sum_delta = sum_delta + (delta);
+				var currentTime = new Date();
+				lastTimestamp = currentTime.getTime();
+				
+				return false;
+			});
+		}());
+	}
+});
\ No newline at end of file



More information about the Mapbender_commits mailing list