[OpenLayers-Dev] hidden but selectable features

Pierre GIRAUD bluecarto at gmail.com
Tue Jan 27 09:32:16 EST 2009

Hi all,

Here's a project use case : I have features in a vector layer in a map
and corresponding rows in an Ext grid. I want some of those features
to be hidden on the map. However, I want them all to be selectable in
the grid.
If a feature is selected in the grid, I want it to be shown as
selected on the map too, even it is was previously hidden.

In order to achieve this, I took advantage of the styleMap
uniquevaluerules and a specific lookup omitting the values for the
hidden features.

It was working well until r8620 [1]. The features are still hidden,
but selecting them programmatically has no effect.

I could have used lookup properties with empty style definition, but
hidden features are then selectable on the map, which I don't want.

I put some code (enclosed) to reproduce if someone wants to give it a look.

Help appreciated.


[1] http://trac.openlayers.org/changeset/8620

function init(){
            map = new OpenLayers.Map('map', {maxResolution:'auto'});
            var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
            map.setCenter(new OpenLayers.LonLat(0, 0), 0);

            var styleMap = new OpenLayers.StyleMap();

            // create a lookup table with different symbolizers for
the different
            // state values
            var lookup = {
                'shown': {fillColor: "green"}

            styleMap.addUniqueValueRules("default", "visibility", lookup);

            layer = new OpenLayers.Layer.Vector('Points', {
                styleMap: styleMap

            var feature = new OpenLayers.Feature.Vector(
                new OpenLayers.Geometry.Point(0, 0),
                {visibility: 'shown'}
            var feature = new OpenLayers.Feature.Vector(
                new OpenLayers.Geometry.Point(0, 10),
                {visibility: 'hidden'}

            selectControl = new OpenLayers.Control.SelectFeature(layer);


More information about the Dev mailing list