• Resolved pedjas

    (@pedjas)


    I tried to set map with prepared GPX.

    After I selected GPX map preview did not show track from GPX so I was unable to manually center map.

    After I inserted map ti post and previewed post content I had to scroll through the map to find track and then I had to edit short code by guess until I set correct center of the map.

    This should be easier.

    At the first place, GPX contains coordinates for all track points. It should be easy to go through track points, find minimum and maximum for Lon and Lat and thus calculate where center is.

    If that is not possible, at least show track in preview maps so user can see where track is and manually set center.

    • This topic was modified 6 years, 3 months ago by pedjas.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author MiKa

    (@photoweblog)

    Hi @pedjas

    yes, to center the map is something several people asked for and there are some ideas for it. If you could support with some lines of code, we love to add them in the next version.

    Up to now the center has to be set manuall in the way you explained in your thread.

    Br, MiKa

    Thread Starter pedjas

    (@pedjas)

    I am not fluent with JavaScript so I am not daring to offer to do coding, although I might try.

    I did some research and I found https://github.com/mpetazzoni/leaflet-gpx

    There is an example:
    `var gpx = ‘…’; // URL to your GPX file or the GPX itself
    new L.GPX(gpx, {async: true}).on(‘loaded’, function(e) {
    map.fitBounds(e.target.getBounds());
    }).addTo(map);’

    I guess it could lead to quite simple solution: if user does not specify map center call to map.fitBounds() could set view to area covered with loaded GPX.

    Other way may be to use getBounds() from GPX layer to get bounding coordinates and simply calculate center coordinate and use that as center of map.

    If something has to be done in PHP, I can help there.

    Thread Starter pedjas

    (@pedjas)

    Here https://www.wrld3d.com/wrld.js/latest/docs/leaflet/L.LatLngBounds/ I foudn that there is even getCenter().

    Thread Starter pedjas

    (@pedjas)

    This also seems as possible solution: http://www.d3noob.org/2014/02/load-kml-gpx-or-geojson-traces-into.html

    Look for fitBounds

    Plugin Author MiKa

    (@photoweblog)

    Hello @pedjas

    The latest version of the OSM plugin does autocenter, you do not need to adjust the map anymore.

    Br, MiKa

    Plugin Author MiKa

    (@photoweblog)

    I close it since there is no feedback anymore and the feature ist covered.
    Br, MiKa

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Centering map on GPX’ is closed to new replies.