AW: [OpenLayers-Users] Changing style based on feature attributes.

Arnd Wippermann arnd.wippermann at web.de
Thu Jul 7 13:58:20 EDT 2011


Hi,

Perhaps you can add the style attributes to your default style with call to
context functions, that returns null, if not match:

var style = new OpenLayers.Style({
              pointRadius: "${radius}",
              fillColor: "#ffcc66",
              fillOpacity: 0.8,
              strokeColor: "#cc6633",
              cursor: 'pointer',
              strokeWidth: "${width}",
              strokeOpacity: 0.8,
              externalGraphic: "${graphic}",
              graphicHeight:  "${graphicH}",
              graphicWidth:  "${graphicW}"
            }, {
              context: {
                graphic : function(feature){
                    if(....)
                        return(null);
                    else
                        return("img/marker.png");    
                ... 

Arnd

-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von kapuch
Gesendet: Donnerstag, 7. Juli 2011 15:01
An: users at openlayers.org
Betreff: [OpenLayers-Users] Changing style based on feature attributes.

Hi.

I was looking for answer on the mailing list but didn't find the answer.

I have clustered features and I want to use diffrent styles based on cluster
feature attribute count.

When the count attribute is more than 1 i would like to use this style:

var style = new OpenLayers.Style({
              pointRadius: "${radius}",
              fillColor: "#ffcc66",
              fillOpacity: 0.8,
              strokeColor: "#cc6633",
              cursor: 'pointer',
              strokeWidth: "${width}",
              strokeOpacity: 0.8,
            }, {
              context: {
                width: function(feature) {
                  return (feature.cluster) ? 2 : 1;
                },
                radius: function(feature) {
                  var pix = 2;
                  if(feature.cluster) {
                    pix = Math.min(feature.attributes.count, 7) + 2;
                  }
                  return pix;
                }
              }
            });

But when the count is 1 i would like to display externalImage with this
style:
var style = new OpenLayers.Style(
{externalGraphic: 'img/marker.png',
graphicHeight: 21,
graphicWidth: 16});

Now how can I switch between those two styles based on count attribute of
the feature.

Can anybody help?




-----
eDojazd.pl
Niższe koszty dojazdów dla wszystkich i wszędzie!
--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/Changing-style-based-on-feature-attri
butes-tp6558275p6558275.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list