Piwigo / piwigo-openstreetmap

OpenStreetMap integration for Piwigo
http://piwigo.org/ext/extension_view.php?eid=701
GNU General Public License v3.0
35 stars 35 forks source link

Fix #89: Do not generate the geojson data for each request #90

Closed joubu closed 10 months ago

joubu commented 8 years ago

The current code use the omnivore plugin to display gpx data. It works great but generate an ajax request to the server for each gpx files. Once the gpx data are retrieved, the parse.gpx (or whatever) function will generate a geojson structure to display the polygon. If you have a lot of gpx files, this method could be a high time-consuming process.

This patch suggests a new manual workflow to manage the gps traces: 1/ Upload/synchronize a gpx file (/path/to/galleries/dir/file.gpx) 2/ Generate a geojson file from this gpx file:

On a debian-based linux distribution:
  % sudo apt-get install npm
  % sudo npm install -f togeojson
  % sudo n latest
  % togeojson file.gpx > file.geojson
  % perl -p -i -n -e 's/\s//g' file.geojson # To remove space characters

You can also simplify the gpx file, to make it lighter, using gpxbabel:

  % sudo apt-get install gpsbabel
  % gpsbabel -i gpx \
      -f file.gpx \
      -x simplify,crosstrack,error=0.001k \
      -i gpx -F file_simplified.gpx

It will remove points if they are no farther than 1 metre. For more details, see: https://wiki.openstreetmap.org/wiki/GPSBabel/Using_filters#Simplifying_tracks 3/ Put the geojson file in the same directory, with the same name but the geojson extension (/path/to/galleries/dir/file.geojson).

Now the geojson file will be used instead of the gpx file, and put in the original html document (no additional ajax requests).

joubu commented 8 years ago

This can be an answer for #73

ThomasDaheim commented 8 years ago

In general, I have done that for my gpx files. Might be able to reduce them even more but I haven't tried that yet. Will try the togeojson and report on the results.

xbgmsharp commented 8 years ago

@ThomasDaheim Would you be able to test and see if it works for you.

ThomasDaheim commented 8 years ago

So, lets see:

=> total loading speed doesn't increase noticeably - what you gain in avoiding multiple loads you loose in loading one big file

I have tried replacing leading space manually in the transferred html: size comes back down to 3,5MB. That should help. How could this be done in php? Surely with some regexp...

xbgmsharp commented 8 years ago

We can easily minify the GeoJSON file to reduce size, but minifying the file should not speed up the process and it does not seen to solve the issue. Are we sure the issue is on the ommivore plugin? Did you follow the process from @joubu, because there is a perl regexp to minify the file.

2/ Generate a geojson file from this gpx file:
On a debian-based linux distribution:
% sudo apt-get install npm
% sudo npm install -f togeojson
% sudo n latest
% togeojson file.gpx > file.geojson
% perl -p -i -n -e 's/\s//g' file.geojson # To remove space characters
joubu commented 8 years ago

I have (force) updated the commit. I have tried with ~100 gpx/geojson files and, indeed, the solution was not acceptable. This new commit uses the geojson file and count on the browser cache to optimize the process. At the first load, the browser will have to retrieve more data (the size of the geojson is a bit bigger than the gpx) but then it won't have to transform the gpx to geojson. On my side I have noticed a gain of 30%

ThomasDaheim commented 8 years ago

@xbgmsharp: Only in spirit... I don't have that kind of access from my hosting provider. Anyways, can't be expected from all future users to know how to do regexp in perl :-)

@joubu: You have reverted back to x100 gets to the server but for geojson this time? Still doesn't help with reducing the individual file size for each get... Let my have a look at this and report.

ThomasDaheim commented 8 years ago

@joubu: For it was definitely faster with one big file only - if I remove leading spaces in the merged geojson file. Would it be possible to have a version of your code that does that? So far, that was the fastest version for me...