jperelli / vue2-leaflet-markercluster

markercluster plugin extension for vue2-leaflet package
MIT License
132 stars 55 forks source link

Map doesn't update when the options changes #2

Closed dramaking closed 7 years ago

dramaking commented 7 years ago

I am trying to give users the option to toggle the cluster by using "disableClusteringAtZoom" option:

<v-marker-cluster :options="clusterOptions">
      <v-marker v-for="(marker, index) in assetMarkers" :key="index" :lat-lng="marker.position" :icon="marker.icon"></v-marker>
</v-marker-cluster>

then return the clusterOptions an object in the computed property.

But the map doesn't toggle the cluster unless I reload the page.

So I ended up doing this

<template v-if="isClusterOn">
        <v-marker-cluster>
          <v-marker v-for="(marker, index) in assetMarkers" :key="index" :lat-lng="marker.position" :icon="marker.icon"></v-marker>
        </v-marker-cluster>
</template>
<template v-else>
        <v-marker v-for="(marker, index) in assetMarkers" :key="index" :lat-lng="marker.position" :icon="marker.icon"></v-marker>
      </template>

Can we bind the cluster options to the map so that it can be updated immedietely?

jperelli commented 7 years ago

Nice one, let me see if I can do something about this. Also, any pull request to solve this is welcome

jperelli commented 7 years ago

@dramaking I fixed it in v1.2.0, but I don't know why it didn't work with watch deep:true, so you'll need to create a new options object every time you change an option, something like this:

newOptions = Object.assign({}, oldOptions, {opt: val})

You can also see the new example.vue file, in this line https://github.com/jperelli/vue2-leaflet-markercluster/blob/master/example.vue#L57 to see how to change options