It works and it looks much prettier. I'm impressed. Side note : Eric was close to find this solution too.
Thanks. Regards, Pierre On Tue, Jan 27, 2009 at 3:57 PM, Andreas Hocevar <[email protected]> wrote: > Hi Pierre, > > On Tue, Jan 27, 2009 at 3:32 PM, Pierre GIRAUD <[email protected]> wrote: >> 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. > > It was working because of a bug. To do this properly now, I would > recommend something like the following: > > var styleMap = new OpenLayers.StyleMap({ > 'select': OpenLayers.Util.extend({display: ""}, > OpenLayers.Feature.Vector.style['select']) > }); > // create a lookup table with different symbolizers for the different > // state values > var lookup = { > 'shown': {fillColor: "green"}, > 'hidden': {display: "none"} > }; > styleMap.addUniqueValueRules("default", "visibility", lookup); > > Regards, > Andreas. > > >> 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. >> >> Regards, >> Pierre >> >> >> >> [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.addLayer(wms); >> 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 >> }); >> map.addLayer(layer); >> >> var feature = new OpenLayers.Feature.Vector( >> new OpenLayers.Geometry.Point(0, 0), >> {visibility: 'shown'} >> ); >> layer.addFeatures([feature]); >> var feature = new OpenLayers.Feature.Vector( >> new OpenLayers.Geometry.Point(0, 10), >> {visibility: 'hidden'} >> ); >> layer.addFeatures([feature]); >> >> selectControl = new OpenLayers.Control.SelectFeature(layer); >> map.addControl(selectControl); >> >> selectControl.select(layer.features[0]); >> selectControl.select(layer.features[1]); >> } >> ---------------------------------- >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://openlayers.org/mailman/listinfo/dev >> > > > > -- > Andreas Hocevar > OpenGeo - http://opengeo.org/ > Expert service straight from the developers. > _______________________________________________ Dev mailing list [email protected] http://openlayers.org/mailman/listinfo/dev
