Vue2Leaflet: vue-marker not displaying on map and map not fully rendering
Description
Steps to Reproduce
- installed Vue2Leaflet via npm
- created a component called
Simple
with the following contents (just copied the Simple.vue example and added the style import)
<template>
<div class="simple">
<div id="top_div" style="height: 100%">
<v-map :zoom="zoom" :center="center" style="height: 1000px; width: 1000px">
<v-tilelayer :url="url" :attribution="attribution"></v-tilelayer>
<v-marker :lat-lng="marker"></v-marker>
</v-map>
</div>
</div>
</template>
<script>
import Vue2Leaflet from 'vue2-leaflet';
export default {
name: 'simple',
components: {
'v-map': Vue2Leaflet.Map,
'v-tilelayer' :Vue2Leaflet.TileLayer,
'v-marker': Vue2Leaflet.Marker
},
data () {
return {
zoom: 13,
center: [47.413220, -1.219482],
url: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
marker: L.latLng(47.413220, -1.219482),
}
}
}
</script>
<style>
@import "~leaflet/dist/leaflet.css";
</style>
Expected Results
I expect to see the basic map with marker from the example jsfiddle.
Actual Results
The map appears as a large gray box with a small section with rendered map tiles. My problem looks identical to the one described in #81 , but I do include the leaflet css import.
What is strange is that when I resize the window, the map loads as it should, but the marker does not show up. I see in the html that the marker is loaded, however:
Browsers Affected
- [x ] Chrome
- [x ] Firefox
- Edge
- Safari 9
- Safari 8
- IE 11
Versions
- Leaflet: v1.2.0
- Vue: v2.5.2
- Vue2Leaflet: v0.0.55
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 24
- Comments: 47 (6 by maintainers)
I’ve had some similar issues. The marker image issue I solved using info from these threads: https://github.com/PaulLeCam/react-leaflet/issues/255 https://github.com/Leaflet/Leaflet/issues/4849 https://github.com/Leaflet/Leaflet/issues/4968
Basically, sounds like webpack is jacking up the embedded image URLs in the CSS. Throwing this at the top of your
main.js
may help:I’ve gotten to the point that everything renders after the user resizes but I can’t figure out why I’m getting grey space before that…
I ended up with a hack that helped get everything to render correctly as far as the resize issue goes.
This works down to 200 ms. After that the hack fails. Seems to be some sort of race condition. I tested slower bandwidths and they work fine.
Hello guys, If you are facing such problem with vuetifyjs it’s most probably that the map container is initialized with a small size.
To solve this problem you need to insure that you are loading the map whenever the container is taking the actual size.
For example, if you are using dialog as a container for the map, all what you have to do is using ‘lazy’ prop to insure that the content is rendered on mounted; in other words, the map must be rendered only if the dialog is activated 🎉
I hope this will help some one 😄
Quick update for those using vuetify 2.0. The lazy prop does not longer work, but v-lazy works:
That will do the trick!
This work for me!! thanks!!
It should be added in your ~/projectName/src/main.js file when you instantiate your Vue object. I’m also using Vuetify but my main.js file looks like this:
Hi @Alhakem , Thank you for the v-tab-item tag! I did not see that we could also use the “lazy” parameter in the v-tab!
Fot the sheet, the solution to rerender the Map works great!!! (I used the solution described at the bottom of this page : http://michaelnthiessen.com/force-re-render/).
I setted a key parameter on the map
<l-map :key="componentKey" ref="refMap" :zoom="10" :center="positionInitiale">
and change the value of the componentKey after cliquing on the button to display the sheet
Big thanks to all!
For anyone having problems with vuetify this is the layout which is working for me:
And on resize I do:
As for the issue with sizing issue in Vuetify: add a class on top of the v-container element :
then go into the vuetify.css and rip out all of the media queries for the .container class. I think its on lines 9301 to 9313.
I have a situation where my
<l-map>
component is inside a Vuetify stepper, and the problem is that it renders all of the<v-stepper-content>
components at once, but then not the map. I’m not that experienced with Vue so maybe this is totally wrong, but it seems to be that the map is pre-initizalied at too-small a size and then when you step to the one with the map, it doesn’t load properly and you get the grey square with the map tiles bunched up in the upper-left-hand corner.I tried many solutions here but the only one I could get to work was to set a watcher on the variable controlling the stepper and use @azurelogic’s
setTimeout
-based solution if the stepper variable is the one with the map on it, like this:Template
Script
Hi, In order to work with SEO, I added a watch function when tab item is selected :
And I my CarteEtablissement component
And now the map displays correctly and when I show the source of the page, I see the text for the SEO.
I was experiencing the same issue of leaflet tile not fully loading on the map. After going through various solutions and hacks suggested above., I finally managed to solve the issue by calling:
this.$refs.map.mapObject.invalideSize()
insidemounted
lifecycle hook. Plus I set a hard-coded height and width of the map’s parent container<div>
. And lastly, added the following code insidemain.js
file