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

Arnd Wippermann arnd.wippermann at web.de
Wed May 18 16:15:46 EDT 2011


i'm not sure, but if you add a style to a feature instead a styleMap to the
layer, you can't add a select style.
 
But there is a property selectStyle for the SelectFeatureControl.
It should also work, when the features have there own style.

//ctrlSelectFeature = new OpenLayers.Control.SelectFeature(...)
var selectStyle = OpenLayers.Feature.Vector.style['select'];
ctrlSelectFeature.selectStyle = selectStyle;

Arnd

  _____  

Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Gissur
Þórhallsson
Gesendet: Mittwoch, 18. Mai 2011 19:13
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] OpenLayers.Feature.style
vs.OpenLayers.Layer.Vector.styleMap


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/8d9a9b70/attachment.html


More information about the Users mailing list