You will have to set the extractStyles option of the KML format to false, otherwise your rule based styles will be taken precedence over by the inline styles of the KML.
Andreas. On Fri, Dec 7, 2012 at 3:27 AM, <[email protected]> wrote: > 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 > Tel./Fax: (12) 3153-5115 > > Inteligência e Tecnologia Espacial de Ponta > > > _______________________________________________ > Users mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/openlayers-users > -- Andreas Hocevar OpenGeo - http://opengeo.org/ Expert service straight from the developers. _______________________________________________ Users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/openlayers-users
