ngyewch / svelte-leafletjs

Svelte component for leaflet.
https://ngyewch.github.io/svelte-leafletjs/
MIT License
96 stars 17 forks source link

<DivIcon> does not render when <Marker> has dynamic latLng #30

Open kauaicreative opened 11 months ago

kauaicreative commented 11 months ago

The <DivIcon> renders as expected when I pass hard coded values to <Marker latLng={[500,500]}> But <DivIcon> does not render at all when I pass dynamic values from #each to <Marker latLng={[location.lat, location.lng]}> Does anyone have any ideas why this is the case and how to fix it or possible work arounds. I have hit a wall.

Hard coded latLng works:

{#each locationArr as location, ii}
    {#if location.meta.lat && location.meta.lng && location.meta.key}
        <Marker latLng={[500,500]}>
            {console.log([location.meta.lat, location.meta.lng]+' '+ii), ''}
            <DivIcon>
                <div style='background: #ff00ff; color: #fff; font-size:20px; width: 40px; height:40px'>
                    123
                </div>
            </DivIcon>
        </Marker>
    {/if}
{/each}

Dynamic latLng does not work:

{#each locationArr as location, ii}
    {#if location.meta.lat && location.meta.lng && location.meta.key}
        <Marker latLng={[Number(location.meta.lat), Number(location.meta.lng)]}>
            {console.log([location.meta.lat, location.meta.lng]+' '+ii), ''}
            <DivIcon>
                <div style='background: #ff00ff; color: #fff; font-size:20px; width: 40px; height:40px'>
                    123
                </div>
            </DivIcon>
        </Marker>
    {/if}
{/each}
mugu-fatman commented 11 months ago

Same happens to me as well

kauaicreative commented 11 months ago

@mugu-fatman I was able to fix this by modifying the Marker.svelte component.

Change line 34 if (icon) marker.setIcon(icon);