Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The option displayInLayerSwitcher is rather self-explanatory, but it very useful for cases in which you want to show overlay options in a layer switcher but there's only one baselayer option, or when layers are not displayed (for instance, transparent layers for zoomToLayer / zoomToFeature bboxes).
Since this can be set on any layer, and is definitely a per-map setting, this should be in the UI, in the same way as the enabled / activated checkboxes are displayed.
Comment | File | Size | Author |
---|---|---|---|
#36 | 710514-activated-layers-26.patch | 6.3 KB | mrfelton |
#25 | 710514-activated-layers-25.patch | 6.81 KB | zzolo |
#20 | 710514-activated-layers-03.patch | 3.35 KB | tmcw |
#19 | 710514-activated-layers-02.patch | 5.28 KB | zzolo |
#5 | 710514-activated-layers-01.patch | 4.93 KB | zzolo |
Comments
Comment #1
zzolo CreditAttribution: zzolo commentedhttp://drupal.org/cvs?commit=337902
Added this in for overlays. On the rendering JS side, it checks layer is a baselayer. Still needs work to get baselayers. I think the most important thing is to ensure that baselayers are in the switcher by default.
Comment #2
tmcw CreditAttribution: tmcw commentedJust a cursory glance, but it seems like the best way to implement this would be rather to make the displayInLayerSwitcher property set at the PHP level, via openlayers_layers_process, etc. This way the generated-javascript layer definitions are closer to the 'real thing' and there's less javascript logic at play. I can roll a patch if necessary.
Comment #3
zzolo CreditAttribution: zzolo commentedI just pretty much copied what was already going on with the activated switch. It does make more sense to actually set the property in PHP instead of adding JS logic, given this is a property of the layer class and not a method.
Comment #4
tmcw CreditAttribution: tmcw commentedThis is very important to have in baselayers, though - mainly because many maps have a single baselayer and multiple overlays, and since there's no other baselayer to select, there's no reason to have a selector for the baselayer.
Comment #5
zzolo CreditAttribution: zzolo commentedI have created a patch that allows for both types of layers to have the "In Switcher" option. But as I was doing this, I realized that the default is to not display the layer in the Switcher. I think this is a good default, but it will cause problems for everyone currently using the 2.x branch.
We can't really do an update function because maps can live in code. Or we could do an update function, but make sure to tell users that have maps in code, they must update them. Or we put the default to show in Switcher (which I don't really like). Thoughts?
Comment #6
zzolo CreditAttribution: zzolo commentedComment #7
tmcw CreditAttribution: tmcw commentedUh, why should the default be for maps not to appear in the layer switcher? That doesn't seem to make any sense, and would add to lots of user confusion. Could you expand on that point?
Comment #8
zzolo CreditAttribution: zzolo commentedWell, the default for overlays is not to be visible, and it would be kind of a weird interface to have all the checkboxes checked by default. I do think it would be good to have the default to be activated, I just don't think it flows with the interface. We could make the interface the opposite, where checking this box removes it from the switcher. I am not sure what is best, but thats just my train of thought.
Comment #9
tmcw CreditAttribution: tmcw commentedSo the solution is to have the displayInLayerSwitcher checkbox automatically check itself when somebody activates the layer, right?
Comment #10
zzolo CreditAttribution: zzolo commentedThat would be cool going forward, but would not address the users that already have 2.x installed as none of those layers will show up in the switcher.
I think the only way to address existing presets is to go the opposite and assume layer is in the switcher, unless the checkbox is checked. This would involve changing the title as well as variable names. Otherwise, any solution we have will involve some, if not all, existing maps to not have layers in the switcher.
Comment #11
tmcw CreditAttribution: tmcw commented... couldn't you just set the layer to be in the switcher if the displayInLayerSwitcher key is not set / has no value?
Comment #12
zzolo CreditAttribution: zzolo commentedThis would mean that the layers_activated array would need to maintain empty/false values, as opposed to just the TRUE values (or just FALSE values). This is possible, but just not an ideal way to maintain this information (and does not go along with similar structures). Also, it creates more convoluted logic in maintaining a full array of all layers.
I think what is more obvious to users and would take care of this, is to actually make the switch to a "Not in Switcher" switch as opposed to the opposite. As most users will want to just add a layer and assume it is in the interface.
Comment #13
tmcw CreditAttribution: tmcw commentedIt would look like:
displaying map:
if layer is in map and displayInLayerSwitcher is either not a key or true, set it to true.
editing map preset
if layer is in map and displayInLayerSwitcher is either not a key or true, set it to true.
Really not sure how this is complex or convoluted. I can code it up as soon as I get a moment.
Comment #14
zzolo CreditAttribution: zzolo commentedRight, but this means that the state of "not in switcher" has to be maintained and explicit, meaning there has to be a FALSE or non-true value set for the layers that are to not be displayed. This is not complex by any means, it is just more to keep track of and not following the same structures for such things like visible layers, which only keep track of layers that are visible and assume false otherwise.
It's not a big deal, just s shame, given that it is only necessary because we have to support existing users. :)
Actually, just an idea popped in my head. We could keep the existing construct in the most recent patch where we only maintain TRUE values, but just have a bit of hackery in the layer processing, that assumes all layers are in the switcher if the "activated_layers" key in the preset array is not present. This would mean that all current presets will behave the same, but any new or edited presets will have to choose whether they want their layers in the switcher or not.
Comment #15
tmcw CreditAttribution: tmcw commentedre: third paragraph; yes, that's what I described in #11 and #13, except that this would be very easy to implement so that it works in the admin side too.
Comment #16
zzolo CreditAttribution: zzolo commentedWell, the way this actually works in the patch is that there is a "layer_activated" array in the preset that collects what layers are activated; this is very similar to visible layers. For example:
Then, when layers get built on the PHP, it looks at this array and sets the displayInLayerSwitcher switch in the layer, which gets handled automatically on the JS side.
Because you mentioned displayInLayerSwitcher, I assumed you were talking about checking for each layer value in the "layer_activated" array as opposed the array itself. Mishap in communication. :)
I can try to make patch right now, actually.
Comment #17
tmcw CreditAttribution: tmcw commentedWhy shouldn't displayInLayerSwitcher be a property of the layer (in data) instead of a new array in the map object? It seems to make a ton more sense that way.
Comment #18
zzolo CreditAttribution: zzolo commentedMy thinking was that whether the layer was in the switcher was a preset level option, not a layer level option. Like the visible property.
Comment #19
zzolo CreditAttribution: zzolo commentedNew patch with just a little extra logic to default to TRUE if no "layer_activated" is present. Works well for me.
Comment #20
tmcw CreditAttribution: tmcw commentedHere's a cleaned-up patch (reduces logic into a single expression). Let me make another patch before committing; I think that there are a few things that could be improved - like layer_activated is kind of confusing, since layers can also be activated without being in the layer switcher.
Comment #21
zzolo CreditAttribution: zzolo commentedAny suggestions on a better index name than layer_activated? Maybe layer_display?
Comment #22
tmcw CreditAttribution: tmcw commentedvisibility is what OpenLayers itself uses, and I think what we should use for this name.
Comment #23
zzolo CreditAttribution: zzolo commentedI was just trying to rewrite this patch and got really confused.
The patches we wrote are utilizing layer_activited to deal with displayInSwitcher. But, we should be utilizing layer_switcher, as layer_activated is something entirely different. Either I am missing something or somewhere along the the line we got confused.
So, you are suggesting changing layer_activated to layer_visbility? I am cool with this, but the one thought I have is that activated makes a little more sense because it is describing the initial state of the layer, while visibility is describes the current state of it which can get turned off and on.
When its not 3am, I will try to rewrite this.
Comment #24
tmcw CreditAttribution: tmcw commentedI'd recommend sticking with 'visibility'. In OpenLayers.js, speak, 'active' refers to whether the layer is 'in range', like a layer that only covers zoom 4-5 when you're at zoom 6. So, active refers to what you think of visible as. Not endorsing these decisions, but I think that it's best to defer to the structure of OpenLayers where possible, so that the PHP->Javascript link doesn't have any terminology switches.
Comment #25
zzolo CreditAttribution: zzolo commentedHere is a cleaned up patch. This standardizes layer_switcher and layer_visbility and gets rid of layer_activated. Unfortunately it does not seem to be working for overlays. The PHP values get set/rendered right and the layer has the right values, but still no good. Maybe anotehr set of eyes can help me out.
Comment #26
zzolo CreditAttribution: zzolo commentedtagged as beta blocker
Comment #27
tmcw CreditAttribution: tmcw commentedWhat remains to be done here? It appears that all of this work is in the module.
Comment #28
zzolo CreditAttribution: zzolo commentedThe "In Switcher" option has not been added to base layers still.
Comment #29
strk CreditAttribution: strk commentedAlso, the !! thingy, which otherwise breaks other uses of displayInLayerSwitcher (most noticeably GeoExt)
I committed this one: http://drupal.org/cvs?commit=422852
Comment #30
strk CreditAttribution: strk commentedComment #31
Remon CreditAttribution: Remon commentedsubscribe
Comment #32
Remon CreditAttribution: Remon commentedComment #34
mrfelton CreditAttribution: mrfelton commentedSubscribe.
Comment #35
tmcw CreditAttribution: tmcw commentedIt's probably going to take a patch, mrfelton. Things are slow in these parts, and contributions are gladly accepted.
Comment #36
mrfelton CreditAttribution: mrfelton commentedFair enough... here you go then. Patch against latest in CVS.
Comment #37
ressa CreditAttribution: ressa commentedSounds great that this feature is getting added. In the meantime, until the patch is reviewed and added to the module, can anyone here show me how to add a JavaScript file, referenced in the .info file, to execute the displayInLayerSwitcher command?
I found this page with examples, look under "Layer Switcher Example": http://openlayers.org/dev/examples/
I am not sure how to implement it though...
Comment #38
zzolo CreditAttribution: zzolo commentedHi @ressa. You'll probably want to look at making a custom module and putting a behavior in it. You can look at examples in includes/behaviors and also there are help files in the module.
Comment #39
ressa CreditAttribution: ressa commentedThank you for the guidance. I tried to make a custom module, but the combination of my lack of coding skills and limited OpenLayers knowledge stopped me. But thanks anyway 8o)
Comment #40
ressa CreditAttribution: ressa commentedAll along, I thought this thread was about hiding or showing the entire Layer switcher box, not just the title, doh! What I wanted to do was have the default behavior of the LayerSwitcher be expanded and showing content upon entering the application.
The maximizeControl() command will do this. Unfortunately I don't know how to write a module which will add this option under the Openlayers settings inside Drupal. But you can call it by adding the line in the openlayers_behavior_layerswitcher.js file around line 20 like this:
Comment #41
ressa CreditAttribution: ressa commentedI just discovered that you can also use the OpenLayers Plus module, for extra configuration options of the layer switcher, and other stuff: https://github.com/developmentseed/openlayers_plus
Comment #42
zzolo CreditAttribution: zzolo commentedBumping to 7.x.
Comment #43
Remon CreditAttribution: Remon commentedOpenlayers Plus module is on a drupal sandbox project now. Check it out.
Comment #44
mgiffordThat's moved. See - http://drupal.org/node/1271828
Comment #45
ekes CreditAttribution: ekes commentedSo update: https://drupal.org/project/openlayers_plus does offer a selected one/two/none layer switcher block; and other another more themable switcher block. Openlayers module itself still doesn't allow you to select if a base layer is in the switcher or not.
Removing beta blocker tag - beta is out. Update as part of Drupalcon Munich Openlayers sprint.