question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vue-marker not displaying on map and map not fully rendering

See original GitHub issue

Description

Steps to Reproduce

  1. installed Vue2Leaflet via npm
  2. 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: '&copy; <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.

leaflet

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: leaflet2

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:24
  • Comments:47 (6 by maintainers)

github_iconTop GitHub Comments

64reactions
azurelogiccommented, Nov 2, 2017

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:

import L from 'leaflet';
delete L.Icon.Default.prototype._getIconUrl;

L.Icon.Default.mergeOptions({
  iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
  iconUrl: require('leaflet/dist/images/marker-icon.png'),
  shadowUrl: require('leaflet/dist/images/marker-shadow.png')
});

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…

49reactions
azurelogiccommented, Nov 2, 2017

I ended up with a hack that helped get everything to render correctly as far as the resize issue goes.

mounted() {
      setTimeout(function() { window.dispatchEvent(new Event('resize')) }, 250);
}

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue Leaflet not rendering map - Stack Overflow
I want to render map with markers. I'm the beginner with Vue and maybe you can help me with that. I've followed some...
Read more >
Vue2Leaflet: vue-marker not displaying on map and map not ...
When using Vue2Leaflet the map shows a graw box and only a small section of the map is rendered.
Read more >
leaflet js map not showing fully on page load - Laracasts
First try setting width: 100% to #map . Then make sure when the JavaScript is loaded, the container around the map is loaded...
Read more >
Marker | Maps JavaScript API - Google Developers
Renders the Marker on the specified map or panorama. If map is set to null , the marker will be removed. Parameters:
Read more >
FAQ | Vue Leaflet
My map and/or markers don't fully render. ... If Leaflet does not provide a method to change an option on an existing element...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found