Code Monkey home page Code Monkey logo

Comments (5)

jperelli avatar jperelli commented on August 26, 2024 7

UPDATE:

I made a npm package specifically to address this issue. You can see how to install and use it here: https://github.com/jperelli/vue2-leaflet-markercluster

OLD COMMENT:
I've done it with this code

MarkerCluster.vue

<template>
  <div>
    <slot></slot>
  </div>
</template>

<script>
import 'leaflet.markercluster'

const props = {
  visible: {
    type: Boolean,
    custom: true,
    default: true
  }
}

export default {
  props: props,
  mounted () {
    this.mapObject = window.L.markerClusterGroup()

    if (this.$parent._isMounted) {
      this.deferredMountedTo(this.$parent.mapObject)
    }
  },
  beforeDestroy () {
    this.setVisible(false)
  },
  methods: {
    deferredMountedTo (parent) {
      this.parent = parent
      var that = this.mapObject
      this.$children.forEach((child) => {
        child.deferredMountedTo(that)
      })
      if (this.visible) {
        this.mapObject.addTo(parent)
      }
    },
    setVisible (newVal, oldVal) {
      if (newVal === oldVal) return
      if (this.mapObject) {
        if (newVal) {
          this.mapObject.addTo(this.parent)
        }
        else {
          this.parent.removeLayer(this.mapObject)
        }
      }
    }
  }
}
</script>

<style>
@import "~leaflet.markercluster/dist/MarkerCluster.css";
@import "~leaflet.markercluster/dist/MarkerCluster.Default.css";
</style>

Then use it like this

npm install --save leaflet.markercluster

on template:

    <v-map :zoom=10 :center="initialLocation">
      <v-icondefault :image-path="'/statics/leafletImages/'"></v-icondefault>
      <v-tilelayer url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"></v-tilelayer>
      <v-marker-cluster>
        <v-marker v-for="c in cases" v-if="c.location !== null" :lat-lng="geojsonPoint2leaflet(c.location)">
          <v-popup :content="tooltipContent(c)"></v-popup>
        </v-marker>
      </v-marker-cluster>
    </v-map>

on script:

import MarkerCluster from './MarkerCluster'
...
  components: {
    'v-marker-cluster': MarkerCluster
  },
...

I'm going to make a package with this and upload it to npm in a couple of days

from vue2leaflet.

jperelli avatar jperelli commented on August 26, 2024 7

I made the npm package. You can see how to install and use it here: https://github.com/jperelli/vue2-leaflet-markercluster

I think this issue can be closed.

from vue2leaflet.

KoRiGaN avatar KoRiGaN commented on August 26, 2024

Hi @shtw,

I don't know how most of plugins work for leaflet. So I don't know what I should had to ease integration in leaflet.

Some don't need to interact directly with leaflet (custom markers). No modification of Vue2Leaflet is required.
Some need to be added as a simple layer so exposing addLayer on map should be enough (FreeDraw).

I never used makercluter and it may need more than that.
Vue2Leaflet Map will need to instanciate MarkerCluster Layer that will need to instanciate Vue2Leaflet marker or MarkerCluster Cluster Marker.

If you create MarkerCluster component and declare all those component globally (Vue.component(...)) it should work.

I haven't tried it yet, but would be happy to have some help on that.

Mickaël

from vue2leaflet.

vicmars5 avatar vicmars5 commented on August 26, 2024

Thank's man you saved my life :)

from vue2leaflet.

KoRiGaN avatar KoRiGaN commented on August 26, 2024

I agree with @jperelli that this issue can be closed.
@jperelli Great work on vue2-leaflet-markercluster !

from vue2leaflet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.