[OpenLayers-Trac] [OpenLayers] #1240: navigation history control

OpenLayers trac at openlayers.org
Mon Jan 7 13:03:58 EST 2008


#1240: navigation history control
----------------------+-----------------------------------------------------
  Reporter:  tschaub  |       Owner:             
      Type:  feature  |      Status:  new        
  Priority:  minor    |   Milestone:  2.6 Release
 Component:  Control  |     Version:  2.5        
Resolution:           |    Keywords:             
     State:           |  
----------------------+-----------------------------------------------------
Comment (by tschaub):

 Replying to [comment:5 bartvde]:
 > Tim,
 >
 > would it be an option to have a control property direction with values
 forward and backward? So that things can just be handled the same way as
 other controls (API-wise)? One would just call trigger like with other
 controls of type OpenLayers.Control.TYPE_BUTTON.
 >
 > So e.g.:
 >
 > {{{
 > var nav_fwd = new OpenLayers.Control.NavigationHistory({direction:
 'forward'});
 > var nav_back = new OpenLayers.Control.NavigationHistory({direction:
 'backward'});
 > }}}

 One issue here is that you need a single history stack for next/previous
 to work as you'd expect.  With the above configuration, you'll have two
 stacks that don't know about each other.  I had imagined these history
 controls to be meta-controls of a sort.  Meaning that you might have two
 visual representations (buttons) of the same control.  If you want those
 visual representations to be OL controls, then you can make simple button
 controls like so:

 {{{
                 nav = new OpenLayers.Control.NavigationHistory();
                 map.addControl(nav);

                 prev = new OpenLayers.Control({
                     type: OpenLayers.Control.BUTTON,
                     trigger: function() {nav.previous();},
                     active: true
                 });
                 map.addControl(prev);

                 next = new OpenLayers.Control({
                     type: OpenLayers.Control.BUTTON,
                     trigger: function() {nav.next();},
                     active: true
                 });
                 map.addControl(next);

 }}}

 I've also updated my sandbox code to make the NavigationHistory control a
 button type control with a trigger method.  The behavior of the trigger
 method is controlled by the "backwards" property (boolean).  By default
 (backwards true), trigger calls previous.  If backwards is false, trigger
 calls next.

 I've also given the trigger method an options argument.  If
 options.opposite is true, then the behavior of trigger is reversed.  The
 idea would be that you could have a single visual representation (button)
 with different behavior based on some condition (like shift or ctrl key
 modifiers).  For this to work all in OL (in a panel), we'd need the
 panel.onClick method to pass along additional arguments to
 panel.activateControl (like the click event itself).  Then activateControl
 would call trigger (or activate or deactivate) with an options arg like
 {evt: evt} - leaving the controls to decide what to do with that event
 (like check for key modifiers and modify their own behavior).

 All that is a bit weird.  I can't really imagine a history control with
 only a single button.  I think you need two buttons (one that knows about
 control.previous and one that knows about control.next).  Whether or not
 these buttons are OL controls is up to the designer.

 Make sense?

-- 
Ticket URL: <http://trac.openlayers.org/ticket/1240#comment:8>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list