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

geojson reactivity #2

Open
basaran opened this issue Feb 4, 2024 · 0 comments
Open

geojson reactivity #2

basaran opened this issue Feb 4, 2024 · 0 comments

Comments

@basaran
Copy link

basaran commented Feb 4, 2024

Hello, thank you for this, it's really a nice example of using svelte getContext and has been very helpful.

I added a geojson component to the mix myself, and been exploring the options to access the geoshape attributes once they are added, so I can have the map react to the "things" happening outside the map area.

  • For instance, hovering over a text outside, and changing the color of the geoJSON shape.

Could you please share if you have insights on how best to accomplish this? I found out geoJSON.eachLayer to add id attributes to the shapes, and then I can change the setAttribute of those SVG overlays through Javascript on the parent. I was just wondering if there would be a better way.

Thank you again, have I mentioned that this was helpful :)

export let color = "maroon";

onMount(() => {
    if (map) {
        geoJSON = L.geoJson(data, {
            style: {
                color: color /*initial color of the shape*/,
            },
        }).addTo(map);

        geoJSON.eachLayer(function (layer) {
            layer._path.id = "feature-" + layer.feature?.properties?.id;
        }); /*grab the id from json and add to the shape*/
    }
});

$: if (color) {
    console.log("this is not helping to make it reactive");
}
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

1 participant