mpetazzoni / leaflet-gpx

A GPX track plugin for Leaflet.js
http://mpetazzoni.github.io/leaflet-gpx
BSD 2-Clause "Simplified" License
529 stars 114 forks source link

Question: Editing GPX #56

Closed citizenfish closed 6 years ago

citizenfish commented 7 years ago

Could the GPX be edited by a draw control for example https://github.com/Leaflet/Leaflet.draw.

I tried the following code but it did not appear to work. The GPX displays fine but the draw control cannot edit it?

var gpxLayer = new L.GPX(gpx, {async: true});
        gpxLayer.on('loaded', function(e) { map.fitBounds(e.target.getBounds());}); 
        map.addLayer(gpxLayer);

    var options = {
        position: 'topleft',
        draw : {
            polygon: false,
            circle: false,
            rectangle: false,
            marker: false,
            line: false
        },

        edit: {
            featureGroup: gpxLayer,
            remove: false
        }
    };

    var drawControl = new L.Control.Draw(options);
    map.addControl(drawControl);
mpetazzoni commented 7 years ago

I must say I've never tried this. If there is a way to make it work, keep in mind that all the metadata information calculated by leaflet-gpx is done when reading/parsing the original GPX file, so none of that information will be accurate once you start editing the features directly.