Updating a leaflet map with new markers on click #17322
-
|
I'm trying to build a small map-based application with svelte, and sveaflet and I'm not sure if the problem I'm having is with one or the other so I'm starting here - I've got a map that I'd like to update with markers every time the user clicks on it. The idea here is that when someone clicks on the map, the lat/lng coordinates of that click gets sent to PostGIS via a backend, which then queries for all the rows that are within a certain radius of those coordinates. I'd then generate a for each one and place it on the map. My problem is that, after fetch()ing from the backend, the markers are never drawn on the map. I've tried map.invalidateSize(), and I've tried wrapping the in a {#key ...} to force redraw but markers never display. I've already checked the backend (no errors), and made sure that data is actually coming down (it's showing up in the console), its just that the markers aren't being drawn. How are you supposed to do this? Or is this kind of use case not supported? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Ok I figured it out - moving |
Beta Was this translation helpful? Give feedback.
Ok I figured it out - moving
markers = []into one of the .then() calls did the trick. I'm guessing that the {#each} doesn't trigger unless markers is updated, and markers probably wasn't being updated correctly where it originally was. Sorry for the trouble!