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.

L.Icon.Default errors using vue-loader and webpack | Duplicated Marker

See original GitHub issue

System Information | Affected Versions

leaflet: 1.0.3
vue2-leaflet: 0.0.47
vue: 2.2.6
chrome: 58.0.3029.81 (64-bit)

Description

In v.0.0.47, I have noticed an issue with the Marker component being duplicated/shadowed when rendered in the map.

Code

<v-map :zoom=15 :center="[organization.latitude, organization.longitude]">
    <v-tilelayer :token="mapboxAPIKey" url="https://api.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token={token}"></v-tilelayer>
    <v-marker :lat-lng="{'lat': organization.latitude, 'lng': organization.longitude}">
        <v-popup :content="organization.name"></v-popup>
    </v-marker>
</v-map>

edit: fixed code copy paste error

Fix

If I remove the transform: translate3d(395px, 200px, 0px) style from the img.leaflet-marker-icon, then the issue is resolved.

Edit: This change seems to move the “clickable” marker out of the pane, so it cannot be used as the trigger for a popup. The incorrect “fat” marker is the one that remains. I will look into other possible “full” resolutions.

Attachments

screen shot 2017-04-28 at 4 47 52 pm

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

14reactions
bytebraincommented, Aug 4, 2017

I’ve got it working by deleting the _getIconUrl prototype first.

Here is my complete working component:

<template>
  <div>
    <v-map class="mini-map" :zoom=13 :center="[47.413220, -1.219482]">
      <v-tilelayer url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"></v-tilelayer>
      <v-marker :lat-lng="[47.413220, -1.219482]"></v-marker>
    </v-map>
  </div>
</template>

<script>
import L from 'leaflet'
import Vue2Leaflet from 'vue2-leaflet'

// Build icon assets.
delete L.Icon.Default.prototype._getIconUrl
L.Icon.Default.imagePath = ''
L.Icon.Default.mergeOptions({
  iconRetinaUrl: require('../assets/markers/marker-icon-2x.png'),
  iconUrl: require('../assets/markers/marker-icon.png'),
  shadowUrl: require('../assets/markers/marker-shadow.png')
})

export default {
  components: {
    'v-map': Vue2Leaflet.Map,
    'v-tilelayer': Vue2Leaflet.TileLayer,
    'v-marker': Vue2Leaflet.Marker
  }
}
</script>

<style lang="scss">
@import "~leaflet/dist/leaflet.css";

.mini-map {
  width:100%;
  height:250px !important;
}
</style>
8reactions
jteppinettecommented, May 3, 2017

Okay, I found where the Leaflet people are discussing this issue with webpack: https://github.com/Leaflet/Leaflet/issues/4968

They proposed this solution:

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'),
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

L.Icon.Default errors using vue-loader and webpack | Duplicated ...
L.Icon.Default errors using vue-loader and webpack | Duplicated Marker.
Read more >
How to fix default marker-icon.png not found in vue 2 leaflet ...
One answer I found was to modify the mounted() method to be: async mounted() { delete L.Icon.Default.prototype._getIconUrl; L.Icon.Default.
Read more >
[Solved]-error when changing marker in leaflet geosearch-Vue.js
You are simply trying to pass directly options for an Icon, instead of expected options for a Marker (which in particular can receive...
Read more >
How to remove a marker from a Leaflet map?
I'm currently making a website where I'm using Leaflet 1.7.1 and ... init du marker marker = new L.marker([lat,lon], { icon: defaultIcon })....
Read more >
Migrating from v14 - Vue Loader
We are in the process of upgrading Vue CLI 3 beta to use webpack 4 + Vue ... loader, you'd have to duplicate...
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