[OpenLayers-Commits] r2056 - in sandbox/camptocamp/advancedcontrol: examples lib lib/OpenLayers lib/OpenLayers/Control

commits at openlayers.org commits at openlayers.org
Thu Dec 14 09:28:33 EST 2006


Author: bertil
Date: 2006-12-14 09:28:31 -0500 (Thu, 14 Dec 2006)
New Revision: 2056

Added:
   sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/Button.js
Modified:
   sandbox/camptocamp/advancedcontrol/examples/AdvancedControl.html
   sandbox/camptocamp/advancedcontrol/lib/OpenLayers.js
   sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control.js
   sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Map.js
Log:
changes to give the ability to easy extend the controls actions.


Modified: sandbox/camptocamp/advancedcontrol/examples/AdvancedControl.html
===================================================================
--- sandbox/camptocamp/advancedcontrol/examples/AdvancedControl.html	2006-12-14 14:20:22 UTC (rev 2055)
+++ sandbox/camptocamp/advancedcontrol/examples/AdvancedControl.html	2006-12-14 14:28:31 UTC (rev 2056)
@@ -1,28 +1,44 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
     <style type="text/css">
-        #map {
+        #map1 {
             width: 512px;
             height: 512px;
             border: 1px solid black;
         }
+        
+        #map2 {
+            width: 512px;
+            height: 512px;
+            border: 1px solid black;
+        }
     </style>
     <script src="../lib/OpenLayers.js"></script>
     <script type="text/javascript">
         <!--
         function init(){
-            var map = new OpenLayers.Map('map');
+            var map = new OpenLayers.Map('map1');
             var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
-                "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}); 
-
+                "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
+			// {div: $("containerControl")}
 			var container = new OpenLayers.Control.Container({div: $("containerControl")});
 			container.addControl(new OpenLayers.Control());
 			container.addControl(new OpenLayers.Control());
-			container.addControl(new OpenLayers.Control());
-
+			var button = new OpenLayers.Control.Button("bouton test");
+			container.addControl(button);            
+            
+            var map2 = new OpenLayers.Map('map2');
+            var ol_wms2 = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
+                "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
+            map2.addLayers([ol_wms2]);
+            map2.zoomToMaxExtent();
+            
+            var mapcontr = new OpenLayers.Control.MouseDefaults();
+			mapcontr.setMap(map2);
+			map.addMouseListener(mapcontr);
+			
 			map.addControl(container);
             
-            
             map.addLayers([ol_wms]);
             map.zoomToMaxExtent();
         }
@@ -31,7 +47,8 @@
   </head>
   <body onload="init()">
     <h1>OpenLayers Example</h1>
-    <div id="map"></div>
+    <div id="map1"></div>
+    <div id="map2"></div>
     <div id="containerControl"></div>
   </body>
 </html>

Added: sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/Button.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/Button.js	                        (rev 0)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/Button.js	2006-12-14 14:28:31 UTC (rev 2056)
@@ -0,0 +1,55 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+/**
+ * @class
+ *
+ * @requires OpenLayers/Control.js
+ */
+OpenLayers.Control.Button = OpenLayers.Class.create();
+OpenLayers.Control.Button.prototype = OpenLayers.Class.inherit( OpenLayers.Control, {
+	
+	name: null,
+	
+	icon: null,
+	
+	actionListeners: null,
+	
+    /**
+     * @constructor
+     * 
+     * @param {Object} options
+     */
+    initialize: function(name, icon, options) {
+        OpenLayers.Control.prototype.initialize.apply(this, options);
+        this.controlName = "olButton";
+        this.name = name;
+        this.icon = icon;
+    },
+    
+    /**
+     * @param {OpenLayers.Pixel} px
+     *
+     * @returns A reference to the DIV DOMElement containing the control
+     * @type DOMElement
+     */
+    draw: function (px) {
+        if (this.div == null) {
+            this.div = document.createElement("button");
+            this.div.id = this.id;
+            this.div.style.position = "absolute";
+            this.div.appendChild(document.createTextNode(this.name));
+            this.div.className = this.controlName;
+        }
+        if (px != null) {
+            this.position = px.clone();
+        }
+        this.moveTo(this.position);
+        
+        return this.div;
+    },
+    
+    CLASS_NAME: "OpenLayers.Control.Button"
+
+});
\ No newline at end of file

Modified: sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control.js	2006-12-14 14:20:22 UTC (rev 2055)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control.js	2006-12-14 14:28:31 UTC (rev 2056)
@@ -85,6 +85,20 @@
         }
     },
 
+    /**
+     * @param {OpenLayers.Control.ActionListener} actionListener
+     */    
+    addActionListener: function(actionListener) {
+    	OpenLayers.Event.observe(this.div, "click", actionListener.actionPerformed , false);
+    },
+
+    /**
+     * @param {OpenLayers.Control.ActionListener} actionListener
+     */
+    removeActionListener: function(actionListener) {
+    	penLayers.Event.observe(this.div, "click", actionListener.actionPerformed , false);
+    },
+
     /** @final @type String */
     CLASS_NAME: "OpenLayers.Control"
 };

Modified: sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Map.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Map.js	2006-12-14 14:20:22 UTC (rev 2055)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Map.js	2006-12-14 14:28:31 UTC (rev 2056)
@@ -198,7 +198,10 @@
                       this.destroy.bindAsEventListener(this));
         
         // initialize default mouseListener
-        this.setMouseListener(new OpenLayers.Control.MouseDefaults());
+        this.mouseListeners = [];
+        var mouseListener = new OpenLayers.Control.MouseDefaults()
+        mouseListener.setMap(this);
+        this.addMouseListener(mouseListener);
 
     },
 
@@ -535,30 +538,37 @@
     /**
      * @param {OpenLayers.Control.MouseListener} mouseListener
      */       
-    setMouseListener: function(mouseListener) {
-    	 
-    	 if (this.mouseListener) {
-	    	 this.events.unregister( "click", this.mouseListener, this.mouseListener.mouseClick );
-	         this.events.unregister( "dblclick", this.mouseListener, this.mouseListener.mouseDblClick );
-	         this.events.unregister( "mousedown", this.mouseListener, this.mouseListener.mouseDown );
-	         this.events.unregister( "mouseup", this.mouseListener, this.mouseListener.mouseUp );
-	         this.events.unregister( "mousemove", this.mouseListener, this.mouseListener.mouseMove );
-	         this.events.unregister( "mouseout", this.mouseListener, this.mouseListener.mouseOut );
-	         this.events.unregister( "DOMMouseScroll", this.mouseListener, this.mouseListener.mouseWheel);
-         }
+    addMouseListener: function(mouseListener) {
+		 
+		 this.events.register( "click", mouseListener, mouseListener.mouseClick );
+         this.events.register( "dblclick", mouseListener, mouseListener.mouseDblClick );
+         this.events.register( "mousedown", mouseListener, mouseListener.mouseDown );
+         this.events.register( "mouseup", mouseListener, mouseListener.mouseUp );
+         this.events.register( "mousemove", mouseListener, mouseListener.mouseMove );
+         this.events.register( "mouseout", mouseListener, mouseListener.mouseOut );
+         this.events.register( "DOMMouseScroll", mouseListener, mouseListener.mouseWheel);
          
-		 this.mouseListener = mouseListener;
-		 this.mouseListener.setMap(this);
-		 
-		 this.events.register( "click", this.mouseListener, this.mouseListener.mouseClick );
-         this.events.register( "dblclick", this.mouseListener, this.mouseListener.mouseDblClick );
-         this.events.register( "mousedown", this.mouseListener, this.mouseListener.mouseDown );
-         this.events.register( "mouseup", this.mouseListener, this.mouseListener.mouseUp );
-         this.events.register( "mousemove", this.mouseListener, this.mouseListener.mouseMove );
-         this.events.register( "mouseout", this.mouseListener, this.mouseListener.mouseOut );
-         this.events.register( "DOMMouseScroll", this.mouseListener, this.mouseListener.mouseWheel);
+         this.mouseListeners.push(mouseListener);
     },
     
+    removeMouseListener: function(mouseListener){
+		 this.events.unregister( "click", mouseListener, mouseListener.mouseClick );
+         this.events.unregister( "dblclick", mouseListener, mouseListener.mouseDblClick );
+         this.events.unregister( "mousedown", mouseListener, mouseListener.mouseDown );
+         this.events.unregister( "mouseup", mouseListener, mouseListener.mouseUp );
+         this.events.unregister( "mousemove", mouseListener, mouseListener.mouseMove );
+         this.events.unregister( "mouseout", mouseListener, mouseListener.mouseOut );
+         this.events.unregister( "DOMMouseScroll", mouseListener, mouseListener.mouseWheel);
+         
+         this.mouseListeners = OpenLayers.Util.removeItem(this.mouseListeners, mouseListener);
+    },
+    
+    resetMouseListeners: function(){
+    	for (var i=0; i < this.mouseListeners.length; i++) {
+    		this.removeMouseListener(this.mouseListeners[i])
+    	}
+    },
+    
     /** 
     * @param {OpenLayers.Popup} popup
     * @param {Boolean} exclusive If true, closes all other popups first

Modified: sandbox/camptocamp/advancedcontrol/lib/OpenLayers.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers.js	2006-12-14 14:20:22 UTC (rev 2055)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers.js	2006-12-14 14:28:31 UTC (rev 2056)
@@ -92,6 +92,7 @@
         "OpenLayers/Popup/AnchoredBubble.js",
         "OpenLayers/Control.js",
         "OpenLayers/Control/Container.js",
+        "OpenLayers/Control/Button.js",
         "OpenLayers/Control/MouseListener.js",
         "OpenLayers/Control/MouseDefaults.js",
         "OpenLayers/Control/MouseToolbar.js",



More information about the Commits mailing list