[Mapbender-commits] r8332 - branches/2.7/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Apr 27 07:45:29 EDT 2012


Author: astrid_emde
Date: 2012-04-27 04:45:29 -0700 (Fri, 27 Apr 2012)
New Revision: 8332

Modified:
   branches/2.7/http/plugins/mb_overview.js
Log:
merged the mb_mobile code

Modified: branches/2.7/http/plugins/mb_overview.js
===================================================================
--- branches/2.7/http/plugins/mb_overview.js	2012-04-26 15:37:03 UTC (rev 8331)
+++ branches/2.7/http/plugins/mb_overview.js	2012-04-27 11:45:29 UTC (rev 8332)
@@ -2,32 +2,32 @@
  * Package: Overview
  *
  * Description:
- * Use the overview map to navigate the main map window. You can select a new 
- * rectangle in the overview map, the details will be displayed in the main 
- * map window. Recenter the main map window section by just clicking a new 
- * position in the overview map (the scale will not change). 
- * 
+ * Use the overview map to navigate the main map window. You can select a new
+ * rectangle in the overview map, the details will be displayed in the main
+ * map window. Recenter the main map window section by just clicking a new
+ * position in the overview map (the scale will not change).
+ *
  * Files:
  *  - http/javascripts/mod_overview.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 ('<app_id>','overview',
  * > 2,1,'OverviewFrame','Overview','div','','',15,25,150,150,2,
  * > 'overflow:hidden;',
  * > '<div id="overview_maps" style="position:absolute;left:0px;right:0px;"></div>',
  * > 'div','../plugins/mb_overview.js','mod_box1.js','mapframe1','mapframe1',
  * > 'http://www.mapbender.org/index.php/Overview');
- * > 
- * > INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name, 
- * > var_value, context, var_type) VALUES ('<app_id>', 'overview', 
+ * >
+ * > INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name,
+ * > var_value, context, var_type) VALUES ('<app_id>', 'overview',
  * > 'overview_wms', '0', 'wms that shows up as overview' ,'var');
  * >
- * > INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name, 
- * > var_value, context, var_type) VALUES ('<app_id>', 'overview', 
- * > 'skipWmsIfSrsNotSupported', '0', 
+ * > INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name,
+ * > var_value, context, var_type) VALUES ('<app_id>', 'overview',
+ * > 'skipWmsIfSrsNotSupported', '0',
  * > 'if set to 1, it skips the WMS request if the current SRS is not supported by the WMS; if set to 0, the WMS is always queried. Default is 0, because of backwards compatibility' ,
  * > 'var');
  *
@@ -36,27 +36,27 @@
  *
  * Maintainer:
  * http://www.mapbender.org/User:Christoph_Baudson
- * 
+ *
  * Parameters:
  * overview_wms                - wms that shows up as overview
- * skipWmsIfSrsNotSupported    - *[optional]* if set to 1, it skips the WMS 
- * 			request if the current SRS is not supported by the WMS; if set 
- * 			to 0, the WMS is always queried. Default is 0, because of 
+ * skipWmsIfSrsNotSupported    - *[optional]* if set to 1, it skips the WMS
+ * 			request if the current SRS is not supported by the WMS; if set
+ * 			to 0, the WMS is always queried. Default is 0, because of
  * 			backwards compatibility
  *
  * 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
  */
 
 if (typeof options.overview_wms === "undefined") {
-	options.overview_wms = 0;	
+	options.overview_wms = 0;
 }
 
 if (typeof options.enable_mouse === "undefined") {
-	options.enable_mouse = 1;	
+	options.enable_mouse = 1;
 }
 options.overview_wms = parseInt(options.overview_wms, 10);
 
@@ -70,22 +70,24 @@
 var $this = $(this);
 
 Mapbender.events.initMaps.register(function () {
-	
+        var touch;
+	var isTouchable = false;
+        try {document.createEvent("TouchEvent"); isTouchable = true; } catch(e){}
 	$this.data("isMap", true);
 
 	$this.mapbender(new Mapbender.Map({
-		id: options.id, 
-		width: options.width, 
-		height: options.height, 
+		id: options.id,
+		width: options.width,
+		height: options.height,
 		wms: wms,
 		wmsIndexOverview: options.overview_wms
-		
-	})); 
 
+	}));
+
 	map = Mapbender.modules[options.id];
 	map.isOverview = true;
 
-	map.skipWmsIfSrsNotSupported = 
+	map.skipWmsIfSrsNotSupported =
 		options.skipWmsIfSrsNotSupported === 1 ? true : false;
 
 	//
@@ -93,60 +95,162 @@
 	//
 	mb_mapObj.push(map);
 
-	// add select area behaviour
-	box = new Mapbender.Box({
-		target: options.id
-	});
-			
-	$(map.getDomElement()).mousedown(function (e) {
-		if (options.enable_mouse == '0') { 
-			return false;
-		}
-		box.start(e);
-		return false;
-	}).mouseup(function (e) {
-		var targetMap = Mapbender.modules[options.target];
-		if (!targetMap) {
-			return false;
-		}
-		box.stop(e, function (extent) {
-			if (typeof extent === "undefined") {
-				return false;
-			}
-			if (extent.constructor === Mapbender.Extent) {
-				targetMap.calculateExtent(extent);
-				targetMap.setMapRequest();
-			}
-			else if (extent.constructor === Mapbender.Point) {
-				targetMap.setCenter(extent);
-				targetMap.setMapRequest();
-			}
-		});
-		return false;
-	});
 
+	if (isTouchable) {
+            box = new Mapbender.BoxMobile({target: options.id});
+            touch = new mapTouch(map,$(map.getDomElement()), map.getDomElement(), box);
+            touch.activate();
+        } else {
+            // add select area behaviour
+            box = new Mapbender.Box({
+                    target: options.id
+            });
+            $(map.getDomElement()).mousedown(function (e) {
+                    if (options.enable_mouse == '0') {
+                            return false;
+                    }
+                    box.start(e);
+                    return false;
+            }).mouseup(function (e) {
+                    var targetMap = Mapbender.modules[options.target];
+                    if (!targetMap) {
+                            return false;
+                    }
+                    box.stop(e, function (extent) {
+                            if (typeof extent === "undefined") {
+                                    return false;
+                            }
+                            if (extent.constructor === Mapbender.Extent) {
+                                    targetMap.calculateExtent(extent);
+                                    targetMap.setMapRequest();
+                            }
+                            else if (extent.constructor === Mapbender.Point) {
+                                    targetMap.setCenter(extent);
+                                    targetMap.setMapRequest();
+                            }
+                    });
+                    return false;
+            });
+        }
+
 	// if the setBackground module is active,
 	// the overview wms might be hidden.
 	// so we activate it here.
-	var ovWmsArray = map.wms; 
-	if (typeof ovWmsArray !== "object" || ovWmsArray.length === 0) { 
-		return; 
-	} 
-	ovWmsArray[0].gui_wms_visible = 1; 
+	var ovWmsArray = map.wms;
+	if (typeof ovWmsArray !== "object" || ovWmsArray.length === 0) {
+		return;
+	}
+	ovWmsArray[0].gui_wms_visible = 1;
+
+        function mapTouch(map, $map, mapDom, box){
+            this.map = map;
+            this.$elm = $map;
+            this.elm = mapDom;
+            this.box = box;
+            this.activate = function() {
+                this.elm.addEventListener("touchstart", touch.startTouch, true);
+                this.elm.addEventListener("touchmove", touch.moveTouch, true);
+                this.elm.addEventListener("touchend", touch.endTouch, true);
+            }
+            this.deactivate = function() {
+                this.elm.removeEventListener("touchstart", touch.startTouch, true);
+                this.elm.removeEventListener("touchmove", touch.moveTouch, true);
+                this.elm.removeEventListener("touchend", touch.endTouch, true);
+            }
+            this.startTouch = function(event) {
+                if (options.enable_mouse == '0') {
+                        return false;
+                }
+                event.preventDefault();
+                var elm = findElement(event, "");
+                if (isSingleTouch(event)) {
+                    touch.startPos = new Point(
+                        event.touches[0].pageX - touch.$elm.offset().left,
+                        event.touches[0].pageY - touch.$elm.offset().top);
+                    var stopPos = new Point(touch.startPos.x, touch.startPos.y);
+                    touch.box.start(touch.startPos, stopPos);
+                } else if (isMultiTouch(event)) {
+                    var startPos = new Point(
+                        event.touches[0].pageX - touch.$elm.offset().left,
+                        event.touches[0].pageY - touch.$elm.offset().top);
+                    var stopPos = new Point(
+                        event.touches[1].pageX - touch.$elm.offset().left,
+                        event.touches[1].pageY - touch.$elm.offset().top);
+                    touch.box.start(startPos, stopPos);
+                }
+                return true;
+            }
+            this.moveTouch = function(event) {
+                event.preventDefault();
+                var elm = findElement(event, "");
+                if (isSingleTouch(event)) {
+                    var stopPos = new Point(
+                        event.touches[0].pageX - touch.$elm.offset().left,
+                        event.touches[0].pageY - touch.$elm.offset().top);
+                    touch.box.run(touch.startPos, stopPos);
+                } else if (isMultiTouch(event)) {
+                    var startPos = new Point(
+                        event.touches[0].pageX - touch.$elm.offset().left,
+                        event.touches[0].pageY - touch.$elm.offset().top);
+                    var stopPos = new Point(
+                        event.touches[1].pageX - touch.$elm.offset().left,
+                        event.touches[1].pageY - touch.$elm.offset().top);
+                    touch.box.run(startPos, stopPos);
+                }
+                return true;
+            }
+            this.endTouch = function(event) {
+                var targetMap = Mapbender.modules[options.target];
+                if (!targetMap) {
+                        return false;
+                }
+                return touch.box.stop(function (extent) {
+                        if (typeof extent === "undefined") {
+                                return false;
+                        }
+                        if (extent.constructor === Mapbender.Extent) {
+                                targetMap.calculateExtent(extent);
+                                targetMap.setMapRequest();
+                        }
+                        else if (extent.constructor === Mapbender.Point) {
+                                targetMap.setCenter(extent);
+                                targetMap.setMapRequest();
+                        }
+                });
+            }
+        }
+
+        function findElement(event, tagName) {
+            var element = getElement(event);
+            while (element.parentNode && (!element.tagName ||
+                (element.tagName.toUpperCase() != tagName.toUpperCase()))){
+                element = element.parentNode;
+                return element;
+            }
+        }
+        function getElement(event) {
+            return event.target || event.srcElement;
+        }
+        function isSingleTouch (event) {
+            return event.touches && event.touches.length == 1;
+        }
+        function isMultiTouch(event) {
+            return event.touches && event.touches.length > 1;
+        }
 });
 
 //
-// update the rectangle indicating the current extent 
+// update the rectangle indicating the current extent
 // of the target map after each map request in the target
 //
 Mapbender.events.init.register(function () {
 	options.$target.mapbender(function () {
 		var targetMap = this;
 		targetMap.events.afterMapRequest.register(function () {
-		
+
 			var min = map.convertRealToPixel(targetMap.extent.min);
 			var max = map.convertRealToPixel(targetMap.extent.max);
-			
+
 			if (min.x < 0) {
 				min.x = 0;
 			}
@@ -172,8 +276,8 @@
 				max.y = centerY - 4;
 			}
 			var extent = new Mapbender.Extent(min, max);
-		
+
 			box.draw(extent);
 		});
 	});
-});
+});
\ No newline at end of file



More information about the Mapbender_commits mailing list