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

kapuch kapusta.marcin at gmail.com
Fri Jul 8 04:16:03 EDT 2011


Try this and you will see that this is not the way to do this.

var context = {
   width: function(f) {
      return (f.cluster) ? 2 : 1;
   },
   radius: function(f) {
     var pix = 4;
     if(f.cluster) {
       pix = Math.min(f.attributes.count, 10) + 4;
     }
     return pix;
   },
   icon:function(f) {
     if (f.cluster) {
       return(null);
     } else {
       return("img/marker.png");
     }
   }
};

var style = new OpenLayers.Style({
   pointRadius: "${radius}",
   fillColor: "#ffcc66",
   fillOpacity: 0.8,
   strokeColor: "#cc6633",
   cursor: 'pointer',
   strokeWidth: "${width}",
   strokeOpacity: 0.8,
   externalGraphic: "${icon}"
}, {context: context});

If feature is cluster then i get this error:
GET http://localhost/openlayers/null 404 (Not Found)

So the externalGraphics override the rest of the style even if it pointing
to null image. I would like to remove externalGraphics from style if feature
is cluster. I try this for last 2 days and didn't solve it.


-----
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-attributes-tp6558275p6561690.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list