[OpenLayers-Users] OpenLayers.Feature.style vs. OpenLayers.Layer.Vector.styleMap

Gissur Þórhallsson gissur at loftmyndir.is
Wed May 18 13:13:09 EDT 2011


Hi guys,

I've got a vector layer that I initialize with the following code:
var vector_style =  new OpenLayers.StyleMap(OpenLayers.Util.applyDefaults({
 strokeColor:'yellow',
fillOpacity:0.0,
 strokeOpacity:1,
strokeWidth: 2,
 fillOpacity:0.1 },
        OpenLayers.Feature.Vector.style["default"]));

 vectorLayer.styleMap = vector_style;

This renders fine, I get yellow vector features that turn blue when I hover
over them (per default)

The problem is that later on I have an event that styles each feature
depending on a certain condition, the event is something like the following:

var feats =map.layers[22].features;
var lengd = feats.length;
cursize = 2;
for(var i=lengd-1 ;i>=0 ;i--)
{
    if(feats[i+1]!==undefined)
{
        if(feats[i].geometry.intersects(feats[i+1].geometry))
cursize++;
        else
            cursize = 2;
}
 feats[i].style = OpenLayers.Util.applyDefaults(
        {
 graphicZIndex : (lengd-i)+1000,
strokeColor : "#"+genHex(),
 fillOpacity : 0.03,
pointRadius : 7*(cursize)
 },
        OpenLayers.Feature.Vector.style["select"]);
}

The code above loops through the features array (these are all Points), and
if it finds features adjacent to each other in the array which also
intersect/share the same location  - it draws them in bigger and bigger
increments.

The code works fine, except for the fact that I lose the select behavior
from before (the points don't turn blue when I hover over them).

Firebug reveals that the style object that I assign to the features contain
hoverStrokeColor, hoverFillColor etc, but these don't seem to do anything.

Does anybody have ideas?

Kind regards from Iceland,
Gissur

-- 
Gissur Þórhallsson

Loftmyndir ehf.
Laugavegur 13
IS 101 Reykjavík - Iceland
sími (tel): (+354) 540 2500
tölvupóstur (email): gissur at loftmyndir.is
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110518/73d880a1/attachment.html


More information about the Users mailing list