Skip to content

How to make computed setter activated when Leaflet map change view #184

Closed
@sangdth

Description

@sangdth

I have an app that has Leaflet map in different pages, and customer wants the view must be synced. I tried to make the center of the map and at least the zoom sync but had no luck.

Let's say I have simple leaflet map:

<l-map
    :center="currentCenter"
    :zoom="currentZoom"
    :options="mapOptions"
    :url="url"
/>

In computed, I tried this way:

computed: {
    currentCenter: {
        get() {
            return this.$store.state.currentCenter;
            // try to get currentCenter from vuex store
        },
        set(value) {
            this.$store.commit('updateCenter', value);
            // this setter does not triggered when currentCenter changes.
        }
    }
}

My problem is, it can get correct currentCenter when mounted, but whenever I pane the map around, the Leaflet map change the currentCenter, but the setter inside currentCenter does not triggered, so vuex yelling "Do not mutate vuex store state outside mutation handlers."

So my question is, how could I can make the setter in currentCenter computed get triggered everytime I pane the leaflet map?

Thank you.

Versions

  • Leaflet: v1.3.1
  • Vue: v2.5.13
  • Vue2Leaflet: v1.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions