[OpenLayers-Users] KML styles

Tobias Reinicke ramotswa at gmail.com
Thu Nov 3 15:10:37 EDT 2011


Hi All,

When creating a vector layer from kml you have the usual:

var layerName= new OpenLayers.Layer.Vector("LayerName", {
    projection: new OpenLayers.Projection("EPSG:4326"),
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.HTTP(
    {
        url: url,
        format: new OpenLayers.Format.KML(
        {
            extractStyles: true,
            extractAttributes: true
        })

    }),
    visibility: false
});

Now, I'm trying to add a hover style to that kml layer, but it seems
that this isn't possible as long as extractStyles is set to true.

Is that correct? There is no way to override the default select /
hover styles from a kml that already passes through styles?
What I have been trying is this:

var xyz= new OpenLayers.Layer.Vector("xyz", {
    projection: new OpenLayers.Projection("EPSG:4326"),
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.HTTP(
    {
        url: url,
        format: new OpenLayers.Format.KML(
        {
            extractStyles: true,
            extractAttributes: true
        })

    }),
    visibility: false,
    styleMap: new OpenLayers.StyleMap({
        "temporary": hoverStyle,

        "select": {

            pointRadius: 20,
            fillColor: "#57FFD8",
            fillOpacity: 0.8,
            strokeColor: "#0000a1",
            strokeWidth: 4,
            strokeOpacity: 0.8
        }
    })

});

I saw this:
http://wiki.openstreetmap.org/wiki/OpenLayers_Dynamic_KML
and in the js code part of it the kml layer was indeed being styled
with extractStyles = true, but I presume that is because the kml has
no style attached to it in the first place...

Any pointers would be great.

Toby


More information about the Users mailing list