Eric Lemoine wrote:
Alexandre

I now understand one of your problems, you need to give the handler a
reference to the control, but the control does not exist yet since
you're actually creating it. Giving the handler a fake control, of the
form {map: map} (where map is the map instance) should do the trick.

I think handlers do not actually require a reference to the control,
they just need a reference to the map (to register listeners). So I
don't understand why we have this constraint. Anyone involved in the
design of handlers knows?



Mmm... I understand, but since I need to use callbacks on "handler" events, I think it's simpler to create my control the way I already did it. I won't go any further in this example.

I still agree with automatic controls and handlers activation/deactivation. Attached an new patch with the simple changes needed. Is it ok ? If it is, I'll open a ticket.

Again, many thanks for your help,

--
Alexandre Dubé
Mapgears
www.mapgears.com

Index: Control.js
===================================================================
--- Control.js	(revision 9573)
+++ Control.js	(working copy)
@@ -117,6 +117,20 @@
      */
     handler: null,
 
+    /** 
+     * Property: handlers
+     * {Array of(<OpenLayers.Handler>)} null
+     */
+    handlers: null,
+
+    /** 
+     * Property: controls
+     * Controls can contain other controls.  When this control is activated, all
+     * its child controls, i.e. this.controls should be activated as well.
+     * {Array of(<OpenLayers.Controls>)} null
+     */
+    controls: null,
+
     /**
      * APIProperty: eventListeners
      * {Object} If set as an option at construction, the eventListeners
@@ -235,6 +249,16 @@
         if (this.handler) {
             this.handler.setMap(map);
         }
+        if(this.handlers) {
+            for(var key in this.handlers) {
+                this.handlers[key].setMap(map);
+            }
+        }
+        if(this.controls) {
+            for(var i=0, len=this.controls.length; i<len; i++) {
+                this.controls[i].setMap(map);
+            }
+        }
     },
   
     /**
@@ -303,6 +327,16 @@
         if (this.handler) {
             this.handler.activate();
         }
+        if(this.handlers) {
+            for(var key in this.handlers) {
+                this.handlers[key].activate();
+            }
+        }
+        if(this.controls) {
+            for(var i=0, len=this.controls.length; i<len; i++) {
+                this.controls[i].activate();
+            }
+        }
         this.active = true;
         if(this.map) {
             OpenLayers.Element.addClass(
@@ -328,6 +362,16 @@
             if (this.handler) {
                 this.handler.deactivate();
             }
+            if(this.handlers) {
+                for(var key in this.handlers) {
+                    this.handlers[key].deactivate();
+                }
+            }
+            if(this.controls) {
+                for(var i=0, len=this.controls.length; i<len; i++) {
+                    this.controls[i].deactivate();
+                }
+            }
             this.active = false;
             if(this.map) {
                 OpenLayers.Element.removeClass(
_______________________________________________
Dev mailing list
Dev@openlayers.org
http://openlayers.org/mailman/listinfo/dev

Reply via email to