Is there any real advantage in using L.GeoJson instead of Polyline when drawing paths in a map powered by Leaflet?

I know that GeoJson can attach additional options. It is also possible with Polyline but one has to extend it or have a wrapper object.

Our project needs dynamic addition and removal of paths. Can GeoJson still handle it?


1 Answer 1


The L.GeoJSON layer group is just a Feature Group with extra methods specific for vector layers.

It provides a convenient conversion from a GeoJSON data object into a layer group made of Leaflet vector shapes converted from the GeoJSON data. In particular, a LineString is converted into an L.Polyline.

So your L.GeoJSON group is in the end just a container for your Polylines.

Therefore you can directly add and remove child layers like with a normal group (addLayer and removeLayer methods). You can add and remove child Polylines, whether built automatically at construction from the GeoJSON object, or added later on through addLayer (or even through addData).

If you want to shorten / extend a Polyline (through spliceLatLngs and addLatLng methods), of course you can also do it, provided that you get the direct reference to your Polyline.

  • Thank you @ghybs you helped me to choose. Instead of making our own wrapper we will use L.GeoJSON.
    – Amio.io
    Mar 11, 2016 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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