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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zzolo’s picture

http://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.

tmcw’s picture

Just 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.

zzolo’s picture

I 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.

tmcw’s picture

This 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.

zzolo’s picture

I 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?

zzolo’s picture

Status: Active » Needs review
tmcw’s picture

Uh, 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?

zzolo’s picture

Well, 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.

tmcw’s picture

So the solution is to have the displayInLayerSwitcher checkbox automatically check itself when somebody activates the layer, right?

zzolo’s picture

That 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.

tmcw’s picture

... couldn't you just set the layer to be in the switcher if the displayInLayerSwitcher key is not set / has no value?

zzolo’s picture

This 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.

tmcw’s picture

It 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.

zzolo’s picture

Right, 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.

tmcw’s picture

re: 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.

zzolo’s picture

Well, 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:

$map_array = array(
  //....
  'layer_activated' => array(
    ''osm_mapnik' => 'osm_mapnik',
  ),
  //....
);

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.

tmcw’s picture

Why 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.

zzolo’s picture

My thinking was that whether the layer was in the switcher was a preset level option, not a layer level option. Like the visible property.

zzolo’s picture

New patch with just a little extra logic to default to TRUE if no "layer_activated" is present. Works well for me.

tmcw’s picture

Here'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.

zzolo’s picture

Status: Needs review » Needs work

Any suggestions on a better index name than layer_activated? Maybe layer_display?

tmcw’s picture

visibility is what OpenLayers itself uses, and I think what we should use for this name.

zzolo’s picture

I 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.

tmcw’s picture

I'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.

zzolo’s picture

Here 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.

zzolo’s picture

Issue tags: +beta blocker

tagged as beta blocker

tmcw’s picture

What remains to be done here? It appears that all of this work is in the module.

zzolo’s picture

The "In Switcher" option has not been added to base layers still.

strk’s picture

Also, the !! thingy, which otherwise breaks other uses of displayInLayerSwitcher (most noticeably GeoExt)
I committed this one: http://drupal.org/cvs?commit=422852

strk’s picture

Title: Add displayInLayerSwitcher to the OpenLayers UI » Add displayInLayerSwitcher for base layers to the OpenLayers UI
Remon’s picture

subscribe

Remon’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 710514-activated-layers-25.patch, failed testing.

mrfelton’s picture

Subscribe.

tmcw’s picture

It's probably going to take a patch, mrfelton. Things are slow in these parts, and contributions are gladly accepted.

mrfelton’s picture

Status: Needs work » Needs review
FileSize
6.3 KB

Fair enough... here you go then. Patch against latest in CVS.

ressa’s picture

Sounds 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/

<script type="text/javascript">
        var map;
        function init(){
            map = new OpenLayers.Map('map', { controls: [] });
            map.addControl(new OpenLayers.Control.Navigation());

            map.addControl(new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}));

            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                "http://vmap0.tiles.osgeo.org/wms/vmap0",
                {layers: 'basic'}, {'displayInLayerSwitcher':false} );

            var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
                "http://t1.hypercube.telascience.org/cgi-bin/landsat7", 
                {layers: "landsat7"}, {'isBaseLayer': false});

            var dm_wms = new OpenLayers.Layer.WMS( "DM Solutions Demo",
                "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
                {layers: "bathymetry,land_fn,park,drain_fn,drainage," +
                         "prov_bound,fedlimit,rail,road,popplace",
                 transparent: "true", format: "image/png" });

            jpl_wms.setVisibility(false);
            dm_wms.setVisibility(false);

            map.addLayers([ol_wms, jpl_wms, dm_wms]);
            if (!map.getCenter()) map.zoomToMaxExtent();
        }
</script>

I am not sure how to implement it though...

zzolo’s picture

Hi @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.

ressa’s picture

Thank 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)

ressa’s picture

All 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:

    data.openlayers.addControl(control);
    control.activate();
    control.maximizeControl();
  }
}
ressa’s picture

I 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

zzolo’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Component: OpenLayers UI » OL API
Category: task » feature
Priority: Normal » Minor
Status: Needs review » Needs work

Bumping to 7.x.

Remon’s picture

Openlayers Plus module is on a drupal sandbox project now. Check it out.

mgifford’s picture

That's moved. See - http://drupal.org/node/1271828

ekes’s picture

Issue tags: -beta blocker

So 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.

  • zzolo committed f14c5c2 on 7.x-3.1.x
    #710514: Added In Switcher option for overlays.