Thanks Arnd, that worked like a charm.<div><br></div><div>Gissur</div><div><br><div class="gmail_quote">2011/5/18 Arnd Wippermann <span dir="ltr"><<a href="mailto:arnd.wippermann@web.de">arnd.wippermann@web.de</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>
<div dir="ltr" align="left"><font color="#0000ff" size="2" face="Arial"><span>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.</span></font></div>
<div dir="ltr" align="left"><font color="#0000ff" size="2" face="Arial"><span></span></font><font color="#0000ff" size="2" face="Arial"><span></span></font> </div>
<div dir="ltr" align="left"><font color="#0000ff" size="2" face="Arial"><span>But there is a property selectStyle for the
SelectFeatureControl.<br>It should also work, when the features have there own
style.<br></span></font></div>
<div dir="ltr" align="left"><font color="#0000ff" size="2" face="Arial">//ctrlSelectFeature = new
OpenLayers.Control.SelectFeature(...)<br>var selectStyle =
OpenLayers.Feature.Vector.style['select'];<br>ctrlSelectFeature.selectStyle =
selectStyle;<br></font></div>
<div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial">Arnd</font></span></div><br>
<div dir="ltr" lang="de" align="left">
<hr>
<font size="2" face="Tahoma"><b>Von:</b> <a href="mailto:openlayers-users-bounces@lists.osgeo.org" target="_blank">openlayers-users-bounces@lists.osgeo.org</a>
[mailto:<a href="mailto:openlayers-users-bounces@lists.osgeo.org" target="_blank">openlayers-users-bounces@lists.osgeo.org</a>] <b>Im Auftrag von </b>Gissur
Þórhallsson<br><b>Gesendet:</b> Mittwoch, 18. Mai 2011 19:13<br><b>An:</b>
<a href="mailto:openlayers-users@lists.osgeo.org" target="_blank">openlayers-users@lists.osgeo.org</a><br><b>Betreff:</b> [OpenLayers-Users]
OpenLayers.Feature.style
vs.OpenLayers.Layer.Vector.styleMap<br></font><br></div><div><div></div><div class="h5">
<div></div>Hi guys,
<div><br></div>
<div>I've got a vector layer that I initialize with the following code:<br clear="all">
<div><font face="'courier new', monospace">var
vector_style = new
OpenLayers.StyleMap(OpenLayers.Util.applyDefaults({</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>strokeColor:'yellow',</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>fillOpacity:0.0,</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>strokeOpacity:1,</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>strokeWidth:
2,</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>fillOpacity:0.1</font><span style="font-family:'courier new', monospace"><span style="white-space:pre-wrap"> </span></span><span style="font-family:'courier new', monospace">},</span></div>
</div><span style="white-space:pre-wrap"></span> <span style="font-family:'courier new', monospace">OpenLayers.Feature.Vector.style["default"]));</span><br>
<blockquote style="border-bottom:medium none;border-left:medium none;padding-bottom:0px;margin:0px 0px 0px 40px;padding-left:0px;padding-right:0px;border-top:medium none;border-right:medium none;padding-top:0px">
<div>
<div><span style="font-family:'courier new', monospace"><span style="white-space:pre-wrap"></span></span></div></div></blockquote>
<div>
<div><span style="font-family:'courier new', monospace">vectorLayer.styleMap = </span><span style="font-family:'courier new', monospace">vector_style</span><span style="font-family:'courier new', monospace">;</span></div>
<div><span style="font-family:'courier new', monospace"><br></span></div>
<div><font face="arial, helvetica, sans-serif">This
renders fine, I get yellow vector features that turn blue when I hover over them
(per default)</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div>
<div><font face="arial, helvetica, sans-serif">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:</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div>
<div>
<div><font face="'courier new', monospace">var feats
=map.layers[22].features;</font></div>
<div><font face="'courier new', monospace">var lengd =
feats.length;</font></div>
<div><font face="'courier new', monospace">cursize =
2;</font></div>
<div><font face="'courier new', monospace">for(var
i=lengd-1 ;i>=0 ;i--)</font></div>
<div><font face="'courier new', monospace">{</font></div>
<div><font face="'courier new', monospace">
if(feats[i+1]!==undefined)</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>{</font></div>
<div><font face="'courier new', monospace">
if(feats[i].geometry.intersects(feats[i+1].geometry))</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>cursize++;</font></div>
<div><font face="'courier new', monospace">
else</font></div>
<div><font face="'courier new', monospace">
cursize = 2;</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>}</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>feats[i].style =
OpenLayers.Util.applyDefaults(</font></div>
<div><font face="'courier new', monospace">
{</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>graphicZIndex :
(lengd-i)+1000,</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>strokeColor :
"#"+genHex(),</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>fillOpacity :
0.03,</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>pointRadius :
7*(cursize)</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap"></span>},</font></div>
<div><font face="'courier new', monospace">
OpenLayers.Feature.Vector.style["select"]);</font></div>
<div><font face="'courier new', monospace">}</font></div></div>
<div><font face="'courier new', monospace"><br></font></div>
<div><font face="arial, helvetica, sans-serif">The code
above loops through the features array </font><span style="font-family:arial, helvetica, sans-serif">(these
are all Points)</span><font face="arial, helvetica, sans-serif">, and if it finds </font><span style="font-family:arial, helvetica, sans-serif">features</span><span style="font-family:arial, helvetica, sans-serif"> </span><span style="font-family:arial, helvetica, sans-serif">adjacent to each other in the array which also
intersect/share the same location - it draws them in bigger and bigger
increments.</span></div>
<div><span style="font-family:arial, helvetica, sans-serif"><br></span></div>
<div><font face="arial, helvetica, sans-serif">The code
works fine, except for the fact that I lose the select </font><font face="arial, helvetica, sans-serif">behavior from before
(the points don't turn blue when I hover over them). </font></div>
<div></div>
<div><br></div>Firebug reveals that the style object that I assign to the
features contain hoverStrokeColor, hoverFillColor etc, but these don't seem to
do anything.</div>
<div><br></div>
<div>Does anybody have ideas?</div>
<div><br></div>
<div>Kind regards from Iceland,</div>
<div>Gissur</div>
<div><br></div>
<div>-- <br>Gissur Þórhallsson<br><br>Loftmyndir ehf.<br>Laugavegur 13<br>IS 101
Reykjavík - Iceland<br>sími (tel): (+354) 540 2500<br>tölvupóstur (email): <a href="mailto:gissur@loftmyndir.is" target="_blank">gissur@loftmyndir.is</a><br></div></div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Gissur Þórhallsson<br><br>Loftmyndir ehf.<br>Laugavegur 13<br>IS 101 Reykjavík - Iceland<br>sími (tel): (+354) 540 2500<br>tölvupóstur (email): <a href="mailto:gissur@loftmyndir.is">gissur@loftmyndir.is</a><br>
</div>