OpenLayers OpenLayers

Ticket #878 (closed feature: fixed)

Opened 10 months ago

Last modified 8 months ago

Add "layerswitched" event to Layer and Control.LayerSwitcher

Reported by: openlayers Assigned to: euzuro
Priority: minor Milestone: 2.5 Release
Component: Layer Version: 2.4
Keywords: Cc:
State:

Description

I have patched my OL 2.4 code to include a "layerswitched" event, and I think it makes sense and would be useful to have this in the OL trunk. This event is associated with a Layer object and is triggered by the LayerSwitcher control any time a layer (base or overlay) is clicked.

Here's my purpose - I've got multiple pairs of layers, a marker layer and a vector layer. One appears in the LayerSwitcher, the other does not. When the user selects or deselects the marker layer (causing its visibility to change), I need the "layerswitched" event to trigger on the layer that was clicked. The event handler for the clicked layer responds by changing the visibility of the other layer in the pair to match the one that was clicked.

I think this implementation makes a bit more logical sense than watching for the "changelayer" event at the Map level. There are many sources of the "changelayer" event, and dealing with them all at the map level would make the event handler more complex than necessary for this type of operation.

The change is to add "layerswitched" to the list of events in the OpenLayers.Layer class, then to add the following line to the end of the OpenLayers.Control.LayerSwitcher.onInputClick() method:

this.layer.events.triggerEvent("layerswitched");

(After line 242 in OL 2.4)

Submitted by Eric.Peterson@motorola.com

Attachments

layer_visibility.patch (1.5 kB) - added by crschmidt on 09/11/07 21:25:28.
878.patch (8.1 kB) - added by crschmidt on 09/11/07 23:22:11.
878.2.patch (8.0 kB) - added by euzuro on 09/11/07 23:57:50.
coding standards, and making the layerStates items objects rather than arrays for readability

Change History

08/27/07 11:59:25 changed by euzuro

  • milestone changed from 2.5 Release to 2.6 Release.

sounds like a good feature -- we'll consider it for 2.6 we're trying to concentrate at this point on closing tickets with patches and getting 2.5 out the door.

08/27/07 12:12:19 changed by crschmidt

  • milestone changed from 2.6 Release to 2.5 Release.

#103 depends on this getting resolved -- either by fixing the layerchanged event, or adding a new one. Bumping this back to 2.5 and assigning to Erik for him to work out which is best.

09/04/07 07:21:36 changed by crschmidt

Talked to Erik, on his way out the door to rome: Plan is to do both visibility-changed event on the layer, *and* fix the layerswitcher to file correct layerchanged events. I've got both on my plate. I'll do what I can.

09/11/07 21:25:28 changed by crschmidt

  • attachment layer_visibility.patch added.

09/11/07 21:25:58 changed by crschmidt

  • keywords changed from layerswitched new layer event to review.

09/11/07 23:22:11 changed by crschmidt

  • attachment 878.patch added.

09/11/07 23:23:37 changed by crschmidt

  • Add Layer Event
  • Remove noEvent from the code -- only used in LayerSwitcher, and no longer needed there
  • Add checkRedraw to LayerSwitcher -- called before redraw -- which returns whether a redraw is neccesary
  • Add LayerStates to LayerSwitcher for above. keeps track of visibility and name.

Includes tests.

09/11/07 23:57:50 changed by euzuro

  • attachment 878.2.patch added.

coding standards, and making the layerStates items objects rather than arrays for readability

09/12/07 00:00:32 changed by euzuro

  • keywords deleted.
  • status changed from new to closed.
  • resolution set to fixed.

(In [4229]) making the layerswitcher a little smarter. Instead of fancy 'noEvent' parameters, we just keep track of the state at each redraw. When asked to redraw, we then check first to see if anything has changed before going ahead with the redraw. Also in this patch, we add a 'visibilitychanged' event to the layer's events object -- upon request by users. (Closes #878)