[OpenLayers-Dev] [OpenLayers-Trac] [OpenLayers] #1260: SelectFeature and OpenLayers.Feature.Vector.style["select"]

Christopher Schmidt crschmidt at metacarta.com
Thu Jan 17 07:17:55 EST 2008


On Thu, Jan 17, 2008 at 02:46:04PM +1100, Roald de Wit wrote:
> Hi Andreas,
> 
> On Fri, 2008-01-11 at 11:39 +0100, Andreas Hocevar wrote:
> > Take as an example a style map with styles ["default", "select"]. In 
> > that case, you would have two OL.Style objects, say myDefaultStyle and 
> > mySelectStyle. For the drawFeature and select methods proposed on the 
> > wiki to work, you would have to use an object looking like this as 
> > layer.style or feature.style:
> > 
> > style = {
> >     'default': /*OL.Style*/ myDefaultStyle,
> >     'select': /*OL.Style*/ mySelectStyle
> > }
> 
> Doing this creates a third possible style for a feature.style: a style
> hash... That would only create confusion, wouldn't it?

Why so? The only thing that should *use* feature.style once it is set is
internal, I'd hope, and we don't use it in enough places to make it
difficult, I don't think.

> I'd actually be very happy if the feature.style is a hash of OL.Style
> objects. Having this would require changes in Layer.drawFeature, but
> seems logical.

We can make it *allow* that without forcing that to be the only way, I'm
sure. it's just writing legacy support into drawFeature, so far as I
understand it.

> The way I see it then is:
> 
> - Control.SelectFeature adds the feature to the array of
> layer.selectedFeatures, it then calls layer.drawFeature(feature)
> - layer.drawFeature checks if the feature is in the list of
> selectedFeatures. If so, it fetches feature.style.select. If not, it
> takes feature.style.default.
> - when layer.drawFeature is called with a second parameter, that can be
> a style object or a name describing the render intent that is used to
> lookup the style from the hash.

Alternatively, Control.SelectFeature -- since it knows that the feature
is being selected -- is the one to check whether the feature has a
'feature.style.select', and draws it (using drawFeature) with that
style, rather than checking it in drawFeature. The end result is the
same, I think. I prefer for drawFeature to not depend on
selectedFeatures -- in my mind, that array is 'managed' by the
SelectFeature control,  so it should be the one doing the logic there.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list