Raruto / leaflet-elevation

Leaflet plugin that allows to add elevation profiles using d3js
GNU General Public License v3.0
256 stars 85 forks source link

[How to] get a callback when file gpx is loaded? #289

Closed FranGhe closed 6 months ago

FranGhe commented 7 months ago

I would like to have a callback when the my Gpx file is loaded, so track and graph are ready because I need to get the zoom level.

My code is this:

var elevationFileGPX="https://....file.gpx";
var elevationViewer = L.control.elevation(options).addTo(mymap);
elevationViewer.load(elevationFileGPX);

I thought to use this... but don't work for me

elevationViewer.on('eledata_added eledata_loaded', function(){
    console.log("loaded");
}); 

I found on old issues but without success... any suggestion?

hupe13 commented 7 months ago

There is an event eledata_loaded: https://github.com/Raruto/leaflet-elevation/blob/bd9316bd1b7e7784b3bf3d812960eaa808ad94d6/examples/leaflet-elevation.html#L78

I use this in a WordPress plugin.

Raruto commented 6 months ago

Just a clarification:

  1. in here hupe listens for the eledata_loaded event on the L.Map object.
  2. the listener must be attached before invoking the elevationViewer.load() function

👋 Raruto

FranGhe commented 6 months ago

My was solution was :

elevationViewer.on('eledata_loaded', function({ layer, name } /* ← ADDED */) {
    console.log("loaded");
}); 

Thanks