0

I have made some examples showing timezones.kml on top of my map in openlayers v3.8.2 without any big issues but this kml (document.kml) of mine just does not want to work. It just doesn't show at all. It loads perfectly in Google Eart and you should be able to have a look at it there if you want to see how it should be.

This is one version of my code that doesn't show the vector layer (or showing it in the wrong place/hidden/scaled so small I can't find it or whatever).

I haven't got the grasp of all this yet and would be very happy for some help on the way.

var raster = new ol.layer.Tile({
              source: new ol.source.OSM("Thunderforest.Landscape",
      ["http://a.tile.thunderforest.com/landscape/${z}/${x}/${y}.png",
       "http://b.tile.thunderforest.com/landscape/${z}/${x}/${y}.png",
       "http://c.tile.thunderforest.com/landscape//${z}/${x}/${y}.png"])
})

var vector = new ol.layer.Vector({
        source: new ol.source.Vector({
            url: 'path/to/document.kml',
            format: new ol.format.KML({ extractStyles: true, extractAttributes: true})
        })
    });

 var map = new ol.Map({
        target: 'map',
        layers: [
          raster,
          vector,
        ],
        view: new ol.View({
            center: ol.proj.transform([12.58,58.76], 'EPSG:4326', 'EPSG:3857'),
            zoom: 13
        })
    });
2

Your KML file contains a lot of nested <Document> tag inside a main <Folder>. The OL parser doesn't handle correctly these tags it manages only one main <Document> tag on top, then nested <Folder> tags.

If you remove all the <Document> tags it works.

1
  • Worked.... not I just have to figure out how to "fix" the kml in the client on load. (preferably)
    – kmpm
    Aug 17 '15 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.