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

Diego Guidi diegoguidi at gmail.com
Mon Aug 26 02:52:46 PDT 2013


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
>


More information about the Users mailing list