Search code examples
javascripthtmldictionaryopenlayerskml

How to add the KML layer for Openlayers switcher?


how can i add a KML layer to the switcher by ol-ext Viglino?

When I add:

var vectorSource = new ol.layer.Vector({
  source: new ol.source.Vector({
  url: "IG1.kml",
  format: new ol.format.KML()
})

The layer does not appear on the map.


Solution

  • To appear in the layer switcher the layer must have a title property

    var vectorSource = new ol.layer.Vector({
      title: "KML Layer",
      source: new ol.source.Vector({
        url: "IG1.kml",
        format: new ol.format.KML()
      })
    })
    

    If the layer is not appearing on the map check that .kml extension is enabled in your server MIME types.