Ticket #878 (closed feature: fixed)

Opened 6 years ago

Last modified 6 years ago

Add "layerswitched" event to Layer and Control.LayerSwitcher

Reported by: openlayers Owned by: 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@…

Attachments

layer_visibility.patch Download (1.5 KB) - added by crschmidt 6 years ago.
878.patch Download (8.1 KB) - added by crschmidt 6 years ago.
878.2.patch Download (8.0 KB) - added by euzuro 6 years ago.
coding standards, and making the layerStates items objects rather than arrays for readability

Change History

Changed 6 years ago 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.

Changed 6 years ago 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.

Changed 6 years ago 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.

Changed 6 years ago by crschmidt

Changed 6 years ago by crschmidt

  • keywords review added; layerswitched new layer event removed

Changed 6 years ago by crschmidt

Changed 6 years ago 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.

Changed 6 years ago by euzuro

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

Changed 6 years ago by euzuro

  • keywords review removed
  • 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)

Note: See TracTickets for help on using tickets.