[OpenLayers-Users] Still Can Not Do Rule-based Styling with KML

reinaldo at geodesign.com.br reinaldo at geodesign.com.br
Thu Dec 6 18:27:47 PST 2012


OL Users,

I tried a new piece of code based on the provided OL examples. But I still
can not get the rule-based styling to work with a KML file.

Could someone please help?

Thanks.

This is how my code looks like now:

var map = new OpenLayers.Map("map");

var googleLayer = new OpenLayers.Layer.Google("Google Satellite",
            {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}
        );

var features = new OpenLayers.Layer.Vector("SOLAR RAD BA", {
        strategies: [new OpenLayers.Strategy.Fixed()],
        protocol: new OpenLayers.Protocol.HTTP({
            url: "kml/ba_diffuse_summer.kml",
            format: new OpenLayers.Format.KML({
               extractStyles: false,
               extractAttributes: true,
               srsName: "EPSG:900913"
            })
        })
        styleMap: new OpenLayers.StyleMap(style)
});

var style = new OpenLayers.Style(
  {
   fillColor: "#ffffff",
   fillOpacity: 0.1,
   strokeWidth: 1,
   strokeColor: "#ffffff",
   strokeOpacity: 4
  },
  {
   rules: [
     new OpenLayers.Rule({
            filter: new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.LESS_THAN,
            property: "SUMMER",
            value: 2000
          }),
            symbolizer: {
            strokeColor: "#00ff00",
            strokeWidth: 1,
            fillColor: "#00ff00"
          }
         }),
     new OpenLayers.Rule({
            filter: new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO,
            property: "SUMMER",
            value: 2000
          }),
            symbolizer: {
            strokeColor: "#ff0000",
            strokeWidth: 1,
            fillColor: "#ff0000"
          }
         })
     ]
  }
);

map.addLayers([googleLayer, features]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
------------------------------------
 Reinaldo Escada Chohfi
 Sócio Gerente
 GeoDesign Internacional
 www.geodesign.com.br (http://www.geodesign.com.br)
 Tel./Fax: (12) 3153-5115
 Inteligência e Tecnologia Espacial de Ponta

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20121207/a228031e/attachment.html>


More information about the Users mailing list