[OpenLayers-Users] Can't define hover behavior on a Feature.Vector or a Layer.Vector

mail.roliveira at gmail.com mail.roliveira at gmail.com
Mon Aug 26 03:19:39 PDT 2013


Hi Diego,
Thank you for you answer.
That was my first approach.I realized that:
var fv = new OpenLayers.Feature.Vector(linearRing, {}, {strokeWidth: "#123456" ,strokeColor: "#123456", fillColor: "#123456", fillOpacity: "#123456"})
;is the same as:
var fv = new OpenLayers.Feature.Vector(linearRing);fv.style = {strokeWidth: "#123456" ,strokeColor: "#123456", fillColor: "#123456", fillOpacity: "#123456"}

;The thing is, I'm only defining one style. What I need is a style for "default" and a style for "select" but  OpenLayers.Feature.Vector doesn't support an OpenLayers.StyleMap like the OpenLayers.Layer.Vector does. If an OpenLayers.StyleMap was supported I could define a renderIntent and therefore maybe implement the select behaviour.



Sent from Alto - altomail.com


From: diegoguidi at gmail.com<diegoguidi at gmail.com>
To: mail.roliveira at gmail.com<mail.roliveira at gmail.com>
cc: openlayers-users at lists.osgeo.org<openlayers-users at lists.osgeo.org>
Sent: Monday, August 26, 2013
Subject: Re: [OpenLayers-Users] Can't define hover behavior on a Feature.Vector or a Layer.Vector

Why you can't define a stylemap for "default" feature visibility?
You need some computation inside the loop to build a style for the feature?

Anyway, try to pass the style as a Style objectdirectly in the Vector
constructor, ie:
var yourstyle = new Openlayers.Style({strokeWidth: "#123456"
,strokeColor: "#123456", fillColor: "#123456", fillOpacity:
"#123456"})
;var fv = new OpenLayers.Feature.Vector(linearRing, {/*empty
attributes*/, yourstyle)

;Diego Guidi


On Mon, Aug 26, 2013 at 11:29 AM, mail.roliveira at gmail.com
<mail.roliveira at gmail.com> wrote:
> Hi.
>
> I'm facing what appears to be a simple problem but there is something
> missing that I can't figure it out what it is...
>
> Hi have this layer:
>
> var layer_style = new OpenLayers.StyleMap({
>             "select": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
>             fillColor: "#626262",
>             strokeColor: "#111111"},
> OpenLayers.Feature.Vector.style["select"]))
>         })
;>
> var vectorLayer = new OpenLayers.Layer.Vector("prach layer", {
> styleMap: layer_style,
> renderers: ['SVG', 'VML', 'Canvas']
> })
;>
>
>
> And have several OpenLayers.Feature.Vector instances that are added to
> vectorLayer:
>
> features = []
;>
> // START: for loop that sets different colors on each iteraction
> var fv = new OpenLayers.Feature.Vector(linearRing); // linearRing is an
> instance of OpenLayers.Geometry.LinearRing determined previously
>
> fv.style = {strokeWidth: "#123456" ,strokeColor: "#123456", fillColor:
> "#123456", fillOpacity: "#123456"}
;>
> features.push(fv)
;> // END: for loop that sets different colors on each iteraction
>
> vectorLayer.addFeatures(features)
;>
> ==
>
> My problem is:
>
> If I click on each created shape the shape doesn't get selected as I would
> expect from the layer_style definition.
> But if I remove the style from each Feature.Vector, then the select behavior
> works. However, I really need to have a style on each Feature.Vector.
>
> I can't figure out why the layer select behavior isn't working.
> As an alternative, is it possible to have a select style (as a render
> intent) on the Feature.Vector, instead of having it on the layer? From the
> docs, it seem this is not possible since the Feature.Vector only allows a
> style definition that maps the SVG style directives
> (http://dev.openlayers.org/docs/files/OpenLayers/Feature/Vector-js.html#OpenLayers.Feature.Vector.OpenLayers.Feature.Vector.style).
>
> On firebug, I can see that each Feature.Vector has a renderIntent set to
> 'default', so I deduce a Feature.Vector also has a renderIntent (probably
> inherited from the layer's renderIntent?).
>
> Any idea on how to solve this?
>
> Thanks in advance.
> Ruben.
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130826/caeb11a3/attachment-0001.html>


More information about the Users mailing list