Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to Markers via code #60

Open
BrettBurbidge opened this issue Jan 2, 2022 · 1 comment
Open

Access to Markers via code #60

BrettBurbidge opened this issue Jan 2, 2022 · 1 comment

Comments

@BrettBurbidge
Copy link

I am currently adding markers to the map like this: (I have custom Marker Icons and popup code, this example is simplified).

<Map> {#if markers} {#each markers as m} <Marker lng={m.longitude} lat={m.latitude} label={m.name} /> {/each} {/if} </Map>

Is there a way to build these markers in code and add them to the map? I need the ability to add and remove markers based on the result of an API call.

Currently, when the API returns 0 markers I set the variable markers to null and receive this error: TypeError: Cannot read properties of null (reading 'removeChild')... I can add more detail if you need it.

Thank you.

@antony
Copy link
Member

antony commented Jan 4, 2022

You should probably set markers to an empty array and drop the if - that might be the cause of the error.

you can interact with the map as you normally would using their JS api - so you can add markers dynamically in this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants