[OpenLayers-Users] Dynamically change a control handler

Gilles Bassière gilles.bassiere at makina-corpus.com
Wed Jun 18 07:43:06 EDT 2008


Hi list,

I'd like to know if there is a cross-browser way to change the mouse 
handler associated to a control.

Context: I want to query the server for a given area. This area may be a 
point, a box or a any polygon. The user can choose the type of area with 
simple html radiobuttons.

My control is set up with the following draw() method:

draw: function() {
    switch (this.handlerType) {
       case 'POINT':
          this.handler = new OpenLayers.Handler.Point(
             this,
             {done: this.selectGeom},
             {keyMask: this.keyMask}
          );
          break;
       case 'BOX':
          this.handler = new OpenLayers.Handler.RegularPolygon(
             this,
             {done: this.selectGeom},
             {keyMask: this.keyMask, sides: 4, irregular: true}
          );
          break;
       ...
    }
},

I added a custom method in order to set the "handlerType" property:

setHandlerType: function(handlerType) {
    this.handlerType = handlerType;
    if (this.active) {
       this.deactivate();
       this.draw();
       this.activate();
    }
},

All this works pretty fine in Firefox but does not in IE...
The behavior in IE is the following:
- when the control is selected, the default point handler works fine and 
the user can click on the map to fire a data request.
- if the user change the handler type (using html radiobuttons and so, 
the control setHandlerType method), the mouse handler is lost until the 
first click on the map.

Right after the call to setHandlerType(), I expect is to see my new 
handler but in IE, there is just no handler. The user needs to click 
once on the map and then the handler appears...

Is it simply possible to achieve dynamic replacement of a control 
handler? If so, can anyone point me in the right direction?

Regards
Gilles

-- 
Gilles Bassiere
MAKINA CORPUS
30 rue des Jeuneurs
FR-75002 PARIS
+33 (0) 1 44 82 00 80
http://www.makina-corpus.com


-------------- next part --------------
A non-text attachment was scrubbed...
Name: gilles_bassiere.vcf
Type: text/x-vcard
Size: 368 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080618/bb7001be/gilles_bassiere.vcf


More information about the Users mailing list