[OpenLayers-Users] Ruled-Based Styling Does Not Work with KML File

reinaldo at geodesign.com.br reinaldo at geodesign.com.br
Fri Dec 14 04:53:21 PST 2012


OL Users,

I can't get the rule-base styling to work on a KML file.

Please find below my JS, HTML and KML files.

I would appreciate very much if someone could help me. 

I  examined the examples, read the documentation and double checked the 
KML file structure. Evertyhing indicate that the rule-based styling  should
work, but it doesn't.

I created a simple kml file with one  attribute for each placemark. I can
get the attributes rendered as  labels, but I can not do the rule-based
styling to work It looks like  the rules are not being evaluated because I
only get the elseifFilter  style result rendered. It does not evaluate the
other two EQUAL_TO  rules, or any other Filter.Comparison rule.

Thanks in advance,

Reinaldo

*** JS FILE **************************************
var map = new OpenLayers.Map("map");

var vector_style = new OpenLayers.Style(
  {
        fillColor: "#00ff00",
        fillOpacity: 0.1,
        strokeWidth: 1,
        strokeColor: "#0000ff",
        strokeOpacity: 4,
//        label: 'S{state}',
//        fontColor: "#ff0000",
//        fontFamily: "sans-serif",
//        fontSize: "10px",
//        fontWeight: "bold"
},
//{
//context: {
//state: function(feature){ return feature.attributes.SUMMER.value; }
//}},
  {
   rules: [
     new OpenLayers.Rule({
            filter: new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.EQUAL_TO,
            property: "SUMMER",
            value: 1000.123
          }),
            symbolizer: {
           fillColor: "#ff0000",
           fillOpacity: 1.0,
           strokeWidth: 1,
           strokeColor: "#ff0000",
           strokeOpacity: 4,
          }
         }),
     new OpenLayers.Rule({
            filter: new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.EQUAL_TO,
            property: "SUMMER",
            value: 2000.123
          }),
            symbolizer: {
           fillColor: "#00ff00",
           fillOpacity: 1.0,
           strokeWidth: 1,
           strokeColor: "#00ff00",
           strokeOpacity: 4,
          }
         }),
     new OpenLayers.Rule({
         // apply this rule if no others apply
            elseFilter: true,
            symbolizer: {
               fillColor: "#ffff00",
               fillOpacity: 1.0,
               strokeWidth: 1,
               strokeColor: "#ffffff",
               strokeOpacity: 4,
              }
         })
     ]
  }
);

var vector_style_map = new OpenLayers.StyleMap({
'default': vector_style
});

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

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

map.addLayers([googleLayer, vectorlayer]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();

*** HTML FILE **************************************
#map {
    width: 600px;
    height: 450px;
    border: 1px solid black;
}
        OpenLayers Example
        simple, basic, light
*** KML FILE **************************************
      diffuse_summer
            ff0000ff
            0
            1000.123
               -39.551991120000018,-8.654038020000009 
-39.461196960000017,-8.650702980000011 
-39.457748160000023,-8.738279009999998 
-39.54856104000001,-8.741648970000023 
-39.551991120000018,-8.654038020000009
            ff0000ff
            0
            2000.123
               -39.370407120000024,-8.647350030000021 
-39.27961296000003,-8.643977999999999 
-39.27612708000003,-8.731485000000008 
-39.366936000000003,-8.734890960000024 
-39.370407120000024,-8.647350030000021
            ff0000ff
            0
            3000.123
               -41.365158120000011,-8.805078990000009 
-41.274315,-8.802090000000005 -41.271233040000013,-8.890313040000013 
-41.362098840000023,-8.893332990000021 
-41.365158120000011,-8.805078990000009
------------------------------------
 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/20121214/9915a321/attachment-0001.html>


More information about the Users mailing list