makinacorpus / Leaflet.FileLayer

Loads files locally (GeoJSON, KML, GPX) as layers using HTML5 File API
http://makinacorpus.github.io/Leaflet.FileLayer/
MIT License
271 stars 91 forks source link

Accessing LatLngs from KML-derived layer #57

Closed timburgess closed 6 years ago

timburgess commented 6 years ago

I have an example KML file uploading and being displayed. Very cool. But I'm wondering how to reference the lat/lngs in the returned layer object..

uploadControl.loader.on('data:loaded', function (event) {
   // event.layer gives you access to the layers you just uploaded!
  ...

Looking at the layer properties I can't see any means to reference the lat/lngs.

timburgess commented 6 years ago

I've resolved this by reaching into the internals. So for my code which extracts latlngs from layers, I now do a check for getLatlngs and if not present, I extract from the internals. This is just for single uploads.

  var latlngs;
  if (typeof layer.getLatLngs === 'function') {
    latlngs = layer.getLatLngs()[0];
  } else {
    latlngs = Object.values(layer._layers)[0]._latlngs[0]
  }