Comments (5)
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.
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.
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.
Thank's man you saved my life :)
from vue2leaflet.
I agree with @jperelli that this issue can be closed.
@jperelli Great work on vue2-leaflet-markercluster !
from vue2leaflet.
Related Issues (20)
- Cannot add alt-text to l-marker icon HOT 2
- Leaflet GeoTiff plugin HOT 2
- The judgment statement may need to be corrected HOT 1
- Abnormal re-render of L-map when an unrelated data property changes HOT 1
- Add scale option for nautical miles HOT 2
- Suggestion for icon rotate / rotation / rotating - easy solution HOT 2
- Cannot read properties of undefined (reading '_leaflet_pos') HOT 1
- Leaflet in Dashboard Widget ( with vue-grid-layout) doesn't center
- Performance problem with big amounts of LCircleMarker HOT 1
- A trouble using Vue2Leaflet with perfect-scrollbar HOT 1
- popups broke HOT 3
- L.vectorGrid.protobuf plugin HOT 2
- coords are not unique HOT 1
- Not unique coords HOT 1
- Roadmap to support Leaflet 1.8.0 HOT 7
- Can you fix the document error 😥 HOT 1
- token prop merged out HOT 3
- lineCap is NOT working in Vue2-leaflet
- Map does not render logically when moving with one finger on uniapp
- Converting mapObject to leafletObject, as it is not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue2leaflet.