Leaflet / Leaflet.VectorGrid

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0
598 stars 194 forks source link

Custom JSON vector grid #116

Closed c-martinez closed 7 years ago

c-martinez commented 7 years ago

I am trying to load a custom JSON for each vector tile. So whenever I zoom in/out / move around, I want to load a different chunk of JSON data. I am doing some data plotting using the JSON data from the different layers.

When zooming in and out, I am hooking up to the zoomend event to refresh the plots. However this does not work when the map is loaded for the first time. Is there any other event which I could hook up to? Or (even better) are is there a function / event which VectorGrid calls / notifies when it starts and finishes loading data?

IvanSanchez commented 7 years ago

Can you publish a fiddle/codepen/playground that displays this behaviour?

c-martinez commented 7 years ago

Fiddle: https://jsfiddle.net/cmartinez/qw0bdd9a/1/

Basically I would like to:

perliedman commented 7 years ago

If I understand correctly, you want to create support for another data format than VectorGrid already supports (GeoJSON, MVT). However, I'm not sure I understand how this relates to hooking up to zoomend or other events - VectorGrid will automatically update its tiles whenever the map is zoomed, so this is not something you would have to implement. The same goes for moving around (panning): already handled by VectorGrid (or rather by L.GridLayer, which VectorGrid uses).

So, for me, it's a bit unclear what the actual question here is?

c-martinez commented 7 years ago

Indeed what I am aiming is for another data format. The reason why I want (or at least I think I want) to hook up to an event is because I want to know when the data from my custom format has finished loading so I can start processing. For example, I could trigger drawing of a pie chart with the data from my custom format.

Does this make sense? Or am I approaching the problem the wrong way?

perliedman commented 7 years ago

Oh, if all you need is to know when the tile is loaded, you should listen for the tileload event, or possibly just the layer's load event, they will fire once the data is actually loaded.

c-martinez commented 7 years ago

Aha! I think that is just what I needed. Thanks!