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.

The marker icon is not displayed in a vue.js webpack template

See original GitHub issue

Description

The marker icon can’t be loaded properly when using v-marker as shown in the image below (in Actual results). As you can see the marker img element is on the DOM but the src url is not pointing to the correct image.

Steps to Reproduce

here the code I am using, it is almost the same as provided in the README

import vue2Leaflet from 'vue2-leaflet'
export default {
  components: {
    vMap: vue2Leaflet.Map,
    vTilelayer: vue2Leaflet.TileLayer,
    vMarker: vue2Leaflet.Marker
  }
}
<!-- show map -->
<div style="height: 300px;>
  <v-map :zoom="12" :center="[location.lat, location.lon]">
    <v-tilelayer url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"></v-tilelayer>
    <v-marker :lat-lng="[location.lat, location.lon]"></v-marker>
  </v-map>
</div>

Expected Results

The marker image get displayed properly

Actual Results

The marker image is on the DOM but is not displayed properly

screenshot from 2017-11-24 15-11-21

Browsers Affected

I tested it just on these browsers

  • Chrome
  • Firefox

Versions

  • Leaflet: v1.2.0
  • Vue: v2.3.4
  • Vue2Leaflet: v0.0.57

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

28reactions
psychosis448commented, Nov 25, 2017

Issue is known. Add the following to main.js

// eslint-disable-next-line  
delete L.Icon.Default.prototype._getIconUrl  
// eslint-disable-next-line  
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')  
})

That worked for me 😃

2reactions
anton-kazlouskicommented, Jun 23, 2021

@simenJohnsen thanks, I was struggling to find the solution.

Is there any explanation of a cause of the problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue.js: Leaflet-Marker is not visible - Stack Overflow
Now I solved it by importing the png directly in the component. In case it could help. Map.vue component. template <l-marker> <l-icon :icon-url= ......
Read more >
Working with Webpack | Vue CLI
Some webpack options are set based on values in vue.config.js and should not be mutated directly. For example, instead of modifying ...
Read more >
FAQ | Vue Leaflet
In most cases, though, it is Webpack messing with Leaflet marker icons' paths, resulting in warnings or even errors. You can alleviate that...
Read more >
Vue2Leaflet is not placing custom Icon in the map-Vue.js
Coding example for the question Vue2Leaflet is not placing custom Icon in the map-Vue.js.
Read more >
Default Leaflet icon is not showing - GIS Stack Exchange
marker ([50,10], {icon: myIcon}).addTo(this.map);. leaflet · javascript.
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