fitBounds to markers
See original GitHub issueGreat Vue plugin!
Apologies if this isn’t a question specific to your plugin, I’m not sure if there’s an easier way to do this. I am struggling figuring out how to retrieve all markers on the map in order to fit the bounds of the map automatically. I’ve looked at this.$ref.map.mapObject._layers, and saw suggestions online to look for layers that have a .feature property, but despite having a marker/markers on the map, I’m not seeing anything that looks like the marker instance. Any suggestions?
I’m also wondering if this will even be possible, if you don’t have a component for FeatureGroup…
<v-map v-if="collection" ref="map" :zoom=-1 :center="[47.413220, -1.219482]">
<v-tilelayer :url="`https://api.mapbox.com/styles/v1/mapbox/${map_id}/tiles/{z}/{x}/{y}?access_token=${access_token}`" />
<v-marker-cluster ref="cluster">
<v-marker
ref="marker"
v-for="(model, index) in collection.models"
v-if="model.acf.location !== null"
:lat-lng="[model.acf.location.lat, model.acf.location.lng]"
:key="index">
<v-popup :content="model.acf.content"></v-popup>
</v-marker>
</v-marker-cluster>
</v-map>
this.$refs.map.mapObject.eachLayer(layer => {
console.log('feature', layer.feature) // undefined
})
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
fitBounds of markers with Leaflet - Stack Overflow
I have a array of markers named markers ...
Read more >leaflet - How to fit bounds after adding multiple markers
You can instantiate a LatLngBounds object and then extend() it with the coordinates of the companies. After adding the markers you can call...
Read more >Leaflet.js Tips, Step 3 (markers and fitBounds) - gists · GitHub
Leaflet.js Tips, Step 3 (markers and fitBounds). GitHub Gist: instantly share code, notes, and snippets.
Read more >Map fit bounds for markers - Google Groups
It seems that the fitBound on a map occurs as a one time event to try and fit all markers on a map,...
Read more >Help with fitBounds - Maps SDK for Web (JavaScript)
... from goog maps and having trouble understanding how to use fitBounds. ... in case anyone else needs help with fitting markers to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@ThomasKientz You are over-complicating it 😃
Look there
https://leafletjs.com/reference-1.6.0.html#latlngbounds
The fitBounds accept an array of [lat,lng] items, so it is as simple as looping over your markers getting lat and long with a simple .map function, as a track
this.$refs.map.mapObject.fitBounds(this.markers.map(m => { return [m.lat, m.lng] }))@wannymiarelli thanks that works, i was doing the same thing … overcomplicating things when not even needed 😛