I am trying to get the GeoJSON of a VectorGrid layer on a click event.

Something like this:

var vectorTile = new L.vectorGrid.protobuf(url, options).addTo(map)

vectorTile.on('click', e => {
   let layerJson = e.layer.toGeoJson() //toGeoJson is not a function of layer

My goal is to be able to store the GeoJSON of the clicked layer in a db, so I can draw it later on another page.

I was not able to find a lot information about this in the internet.

I found a similar question/request, but no solution: https://github.com/Leaflet/Leaflet.VectorGrid/issues/176

Is this doable? Any suggestion on how to accomplish this?

1 Answer 1


I'm afraid, it's not. According to https://github.com/Leaflet/Leaflet.VectorGrid/issues/177 they only have a .toGeoJSON(x, y, z) method to convert an exact tile into a GeoJSON. They also say, that vector-tile-js is able to convert an exact feature to geosjon, but not Leaflet.VectorGrid .

  • I think, the solution for your problem actually depends on a layer source. Where does your features come from on a map? If you browse a layer from your tile server, maybe you could also get a clicked feature's geometry from some API by request. But if a user draws this feature on a map, then the best way is to keep your layer as GeoJSON, so you could easily extract a needed feature by click. Feb 2, 2023 at 13:43

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.