N
N
Nahs2014-10-25 11:14:50
JavaScript
Nahs, 2014-10-25 11:14:50

How to display labels from KML in separate layers in leaflet?

There is KML with traffic route marking

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" >
<Folder id="results">
  <name>trace name</name>
  <Style id="dir_step"></Style>
  <Placemark id="26.1.1"></Placemark>
  <Placemark id="26.1.2"></Placemark>
  <Folder id="26"></Folder>
  <Folder id="27"></Folder>
  <Folder id="28"></Folder>
  <Folder id="29"></Folder>
</Folder>
</kml>

Display it with the following code
function init(){

var map = L.map('map').setView([55.826797, 49.130057], 11);
 
L.tileLayer('map/{z}/{x}/{y}.png', {
  minZoom: 10,
  maxZoom: 18
}).addTo(map);

var track = new L.KML("kml/rathaus_trans.kml", {async: true});
                                                              
track.on("loaded", function(e) { 
            map.fitBounds(e.target.getBounds());
         });

map.addLayer(track);

map.addControl(new L.Control.Layers({}, {'Track':track}));
}

All Folder layers are displayed at once.
How to display each layer separately?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question