<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Since you are using a KML file with attributes in the ExtendedData
    section, you need to tell the KML parser to use a simple attribute
    key:value model if you want to write rule based styling without an
    additional conversion function.<br>
    <br>
    new OpenLayers.Format.KML({<br>
                   extractStyles: false,<br>
                   extractAttributes: true,<br>
                   kvpAttribures: true, // <- THAT is the important
    part you are missing<br>
                   srsName: "EPSG:900913"<br>
                })<br>
    <br>
    Matt Priour<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 12/14/2012 6:53 AM,
      <a class="moz-txt-link-abbreviated" href="mailto:reinaldo@geodesign.com.br">reinaldo@geodesign.com.br</a> wrote:<br>
    </div>
    <blockquote
cite="mid:vmek2ko.a2eb856017bb0bb8b07d418517ed8a11@webmail.geodesign.com.br"
      type="cite">OL Users,<br>
      <br>
      I can't get the rule-base styling to work on a KML file.<br>
      <br>
      Please find below my JS, HTML and KML files.<br>
      <br>
      I would appreciate very much if someone could help me. <br>
      <br>
      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.<br>
      <br>
      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.<br>
      <br>
      Thanks in advance,<br>
      <br>
      Reinaldo<br>
      <br>
      *** JS FILE **************************************<br>
      var map = new OpenLayers.Map("map");<br>
      <br>
      var vector_style = new OpenLayers.Style(<br>
        {<br>
              fillColor: "#00ff00",<br>
              fillOpacity: 0.1,<br>
              strokeWidth: 1,<br>
              strokeColor: "#0000ff",<br>
              strokeOpacity: 4,<br>
      //        label: '${state}',<br>
      //        fontColor: "#ff0000",<br>
      //        fontFamily: "sans-serif",<br>
      //        fontSize: "10px",<br>
      //        fontWeight: "bold"<br>
      },<br>
      //{<br>
      //context: {<br>
      //state: function(feature){ return
      feature.attributes.SUMMER.value; }<br>
      //}},<br>
        {<br>
         rules: [<br>
           new OpenLayers.Rule({<br>
                  filter: new OpenLayers.Filter.Comparison({<br>
                  type: OpenLayers.Filter.Comparison.EQUAL_TO,<br>
                  property: "SUMMER",<br>
                  value: 1000.123<br>
                }),<br>
                  symbolizer: {<br>
                 fillColor: "#ff0000",<br>
                 fillOpacity: 1.0,<br>
                 strokeWidth: 1,<br>
                 strokeColor: "#ff0000",<br>
                 strokeOpacity: 4,<br>
                }<br>
               }),<br>
           new OpenLayers.Rule({<br>
                  filter: new OpenLayers.Filter.Comparison({<br>
                  type: OpenLayers.Filter.Comparison.EQUAL_TO,<br>
                  property: "SUMMER",<br>
                  value: 2000.123<br>
                }),<br>
                  symbolizer: {<br>
                 fillColor: "#00ff00",<br>
                 fillOpacity: 1.0,<br>
                 strokeWidth: 1,<br>
                 strokeColor: "#00ff00",<br>
                 strokeOpacity: 4,<br>
                }<br>
               }),<br>
           new OpenLayers.Rule({<br>
               // apply this rule if no others apply<br>
                  elseFilter: true,<br>
                  symbolizer: {<br>
                     fillColor: "#ffff00",<br>
                     fillOpacity: 1.0,<br>
                     strokeWidth: 1,<br>
                     strokeColor: "#ffffff",<br>
                     strokeOpacity: 4,<br>
                    }<br>
               })<br>
           ]<br>
        }<br>
      );<br>
      <br>
      var vector_style_map = new OpenLayers.StyleMap({<br>
      'default': vector_style<br>
      });<br>
      <br>
      var vectorlayer = new OpenLayers.Layer.Vector("SOLAR RAD BAHIA", {<br>
              strategies: [new OpenLayers.Strategy.Fixed()],<br>
              protocol: new OpenLayers.Protocol.HTTP({<br>
                 url: "kml/ba_diff_simple1.kml",<br>
                  format: new OpenLayers.Format.KML({<br>
                     extractStyles: false,<br>
                     extractAttributes: true,<br>
                     srsName: "EPSG:900913"<br>
                  })<br>
              }),<br>
              styleMap: vector_style_map<br>
      });<br>
      <br>
      var googleLayer = new OpenLayers.Layer.Google("Google Satellite",<br>
                  {type: google.maps.MapTypeId.SATELLITE, numZoomLevels:
      22}<br>
              );<br>
      <br>
      map.addLayers([googleLayer, vectorlayer]);<br>
      map.addControl(new OpenLayers.Control.LayerSwitcher());<br>
      map.zoomToMaxExtent();<br>
      <br>
      *** HTML FILE **************************************<br>
      <!DOCTYPE html><br>
      <html><br>
      <html><br>
          <head><br>
          <meta http-equiv="Content-Type" content="text/html; "><br>
          <meta name="viewport" content="width=device-width,
      initial-scale=1.0, maximum-scale=1.0, user-scalable=0"><br>
          <meta name="apple-mobile-web-app-capable" content="yes"><br>
              <link rel="stylesheet"
      href="../theme/default/style.css" type="text/css"><br>
              <link rel="stylesheet" href="style.css"
      type="text/css"><br>
              <script
src=<a class="moz-txt-link-rfc2396E" href="http://maps.google.com/maps/api/js?v=3&amp;sensor=false">"http://maps.google.com/maps/api/js?v=3&amp;sensor=false"</a>></script><br>
      <style type="text/css"><br>
      #map {<br>
          width: 600px;<br>
          height: 450px;<br>
          border: 1px solid black;<br>
      }<br>
      </style><br>
          </head><br>
          <body><br>
              <h1 id="title">OpenLayers Example</h1><br>
              <div id="tags">simple, basic, light</div><br>
              <div id="map" class="smallmap"></div><br>
              <script src="../lib/OpenLayers.js"></script><br>
              <script src="example1.js"></script><br>
          </body><br>
      </html><br>
      <br>
      *** KML FILE **************************************<br>
      <kml xmlns=<a class="moz-txt-link-rfc2396E" href="http://www.opengis.net/kml/2.2">"http://www.opengis.net/kml/2.2"</a>><br>
        <Document><br>
          <Folder><br>
            <name>diffuse_summer</name><br>
            <Schema name="ba_diffuse_summer" id="ba_summerId"><br>
          <SimpleField name="SUMMER"
      type="double"></SimpleField><br>
            </Schema><br>
            <Placemark><br>
              <Style><br>
                <LineStyle><br>
                  <color>ff0000ff</color><br>
                </LineStyle><br>
                <PolyStyle><br>
                  <fill>0</fill><br>
                </PolyStyle><br>
              </Style><br>
              <ExtendedData><br>
                <SchemaData schemaUrl="#ba_summerId"><br>
                  <SimpleData
      name="SUMMER">1000.123</SimpleData><br>
                </SchemaData><br>
              </ExtendedData><br>
              <Polygon><br>
                <outerBoundaryIs><br>
                  <LinearRing><br>
                   
      <coordinates>-39.551991120000018,-8.654038020000009
      -39.461196960000017,-8.650702980000011
      -39.457748160000023,-8.738279009999998
      -39.54856104000001,-8.741648970000023
      -39.551991120000018,-8.654038020000009</coordinates><br>
                  </LinearRing><br>
                </outerBoundaryIs><br>
              </Polygon><br>
            </Placemark><br>
            <Placemark><br>
              <Style><br>
                <LineStyle><br>
                  <color>ff0000ff</color><br>
                </LineStyle><br>
                <PolyStyle><br>
                  <fill>0</fill><br>
                </PolyStyle><br>
              </Style><br>
              <ExtendedData><br>
                <SchemaData schemaUrl="#ba_summerId"><br>
                  <SimpleData
      name="SUMMER">2000.123</SimpleData><br>
                </SchemaData><br>
              </ExtendedData><br>
              <Polygon><br>
                <outerBoundaryIs><br>
                  <LinearRing><br>
                   
      <coordinates>-39.370407120000024,-8.647350030000021
      -39.27961296000003,-8.643977999999999
      -39.27612708000003,-8.731485000000008
      -39.366936000000003,-8.734890960000024
      -39.370407120000024,-8.647350030000021</coordinates><br>
                  </LinearRing><br>
                </outerBoundaryIs><br>
              </Polygon><br>
            </Placemark><br>
            <Placemark><br>
              <Style><br>
                <LineStyle><br>
                  <color>ff0000ff</color><br>
                </LineStyle><br>
                <PolyStyle><br>
                  <fill>0</fill><br>
                </PolyStyle><br>
              </Style><br>
              <ExtendedData><br>
                <SchemaData schemaUrl="#ba_diffuse_summerId"><br>
                  <SimpleData
      name="SUMMER">3000.123</SimpleData><br>
                </SchemaData><br>
              </ExtendedData><br>
              <Polygon><br>
                <outerBoundaryIs><br>
                  <LinearRing><br>
                   
      <coordinates>-41.365158120000011,-8.805078990000009
      -41.274315,-8.802090000000005
      -41.271233040000013,-8.890313040000013
      -41.362098840000023,-8.893332990000021
      -41.365158120000011,-8.805078990000009</coordinates><br>
                  </LinearRing><br>
                </outerBoundaryIs><br>
              </Polygon><br>
            </Placemark><br>
          </Folder><br>
        </Document><br>
      </kml><br>
      <br>
      <br>
      <br>
      <hr>
      <br>
      Reinaldo Escada Chohfi<br>
      Sócio Gerente<br>
      GeoDesign Internacional<br>
      <a moz-do-not-send="true" href="http://www.geodesign.com.br">www.geodesign.com.br</a><br>
      Tel./Fax: (12) 3153-5115<br>
       <br>
      Inteligência e Tecnologia Espacial de Ponta<br>
       <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/openlayers-users">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>