Search code examples
google-maps-api-3kmlgeojson

KML to geoJSON - how to include styles?


We have been using KML to allow clients to upload Layers to a Google Maps based App. We are trying to replace KML with geoJSON, and all is fine with the exception of styles.

The style definitions in the KML files do not get included in the conveted geoJSON file (we have used a number of converters, but the one we are working with mainly is http://converter.mygeodata.eu/)

As you can see in the KML below, there is a style block there (purple box), but this just gets excluded from any generated geoJSON.

Does anyone know of a converter, or way of converting KML to geoJSON, that retains the style?

Thanks

Jason

enter image description here


Solution

  • In the end, I found that toGeoJson (http://mapbox.github.io/togeojson/) actually does convert the KML <style> node contents into the resulting geoJSON.
    All the online tools seem to use ogr2ogr on the server side, which ignores the <style> as it isn't semantic, but toGeoJson has a go at it and so far does a good job.

    I could then just access those properties, after the geoJSON was loaded, to apply the styles.