1

I am trying to load a GeoJSON file from a MySQL database but it is taking about 6-10 seconds to load the data into the map. This is what I have done so far.

I generate a GeoJSON file after doing a process which contains LineString geometries. The size of these files are about 4 to 5 MB. Then I store this data in a MySQL database. When I load the map I initiate the request of data from the MySQL database so that the data is in the client. I am currently using a button to load the GeoJSON into the map but it is taking long time (6 to 10 seconds).

I have seen some other posts similar to my issue which have suggested simplifying the geometry. But this is not an option for me right now.

Is there any other method to show this GeoJSON data faster?

I am showing data like this

var geojsondata = JSON.parse('data from mysql database already in the client side');
map.data.addGeoJson(geojsondata); 
1
  • 1
    Have you heard of TopoJSON. It stores arcs just once and can reduce storage by up to 80%. However, this will only save time in transmission, you still have to display the polygons, and I don't think Google Maps support TopoJSON. Commented Apr 4, 2016 at 14:24

2 Answers 2

1

If you can't simplify your geometry, you may reduce the size of your GeoJSON file with reducing its COORDINATE_PRECISION

so, instead of 15 (default) after decimal delimiter, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 101.44728385483901, 0.518614509749332 ], [ 101.44603305119549, 0.518614544886082 ], [ 101.44517243453565, 0.518629248927146 ] ] ] }

try to reducing it into 4 (or less if zero) number after decimal delimiter. "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 101.4473, 0.5186 ], [ 101.446, 0.5186 ], [ 101.4452, 0.5186 ] ] ] }

the different is barely visible on map whose scale less then 1:10000

You may check Point Compression Algorithm from Microsoft.

0

Another option is if the data is static, save the GeoJSON data as a GeoJSON file, and just load the file. I load NY State county boundaries this way and it's faster then getting them from the database. I also know these boundaries won't change.

I also agree with trimming down the coordinates, and removing not used fields from your data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.