[OpenLayers-Dev] Idea: New Layer Event: clicklayer

Peterson Eric-EEP002 Eric.Peterson at motorola.com
Fri Jul 20 17:22:51 EDT 2007


I was thinking about the 'changelayer' event and how to use it in my
environment, and I think I've come up with a cleaner solution for my
specific application. However, I don't know how this aligns with the
overall architecture/philosophy of the OpenLayers code, so I'd love to
get some feedback on the idea to see if I'm doing something wrong/weird
or if it merits integration into the code base.

What I want is when I click on one overlay layer in the LayerSwitcher,
then I want a corresponding layer that does not appear in the
LayerSwitcher to change its visibility to the one I just clicked. When I
click on a marker layer in the Layer Switcher, I want its corresponding
line layer to appear or disappear along with the markers. As I emailed
earlier this week, changelayer isn't working in this instance in the 2.4
baseline.

I decided to create a new event called 'clicklayer' (probably not the
best name for it) as an Event type in the Layer class. I then changed
the LayerSwitcher to generate a clicklayer event during a call to the
onInputClick() method. Finally, I registered an event handler for
clicklayer with my marker layer whose callback sets the corresponding
line layer's visibility to that of the associated marker layer (whether
visible or not).

Long story short: when I check and uncheck my marker layer in the
LayerSwitcher, both my marker and line layers appear and disappear. This
is exactly what I want. It also allows me to target the specific event
better than trying to make sense of a could-be-triggered-anywhere
changelayer event ... the code "feels" right.

Question: Is adding a new event type "okay"? How tightly are event types
controlled?

-eP
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20070720/ef1584c3/attachment.html


More information about the Dev mailing list