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.

Custom icon Marker moves with zoom

See original GitHub issue

Hi I am new to leaflet. I am trying to add a custom marker similar to the custom icon sample here: http://leaflet.cloudmade.com/examples/custom-icons.html

When I zoom out the markers move away from the actual point at which the marker is placed. Here is my code, very simple: var map = L.map(‘map’).setView([51.5, -0.09], 13); L.tileLayer(‘http://{s}.tile.cloudmade.com/{key}/22677/256/{z}/{x}/{y}.png’, { attribution: ‘Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade’, key: ‘BC9A493B41014CAABB98F0471D759707’ }).addTo(map);

    var icon = new L.Icon({iconUrl: 'map_pin.png'});

    L.marker([51.5, -0.09], {icon: icon}).bindPopup("I am a green leaf.").addTo(map);

though I have tried a number of other things. This was brought up in issue #371. The author said he fixed it but did not provide the fix. Please help

Thanks, Sam

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
mournercommented, Aug 11, 2012

You need to also specify iconSize and iconAnchor, like in the tutorial.

0reactions
meislishacommented, Jul 16, 2022

@IvanSanchez look at this,please https://github.com/Leaflet/Leaflet/issues/895#issuecomment-1185630452

Read more comments on GitHub >

github_iconTop Results From Across the Web

LeafletJS markers move on zoom - map - Stack Overflow
The solution to this is quite simple. Leads should have posted it. when your markers are moving around your map it's because the...
Read more >
Markers change position when the map is zoomed
There are mainly 2 reason why the marker (mostly customized icons) on the map move its position when zoomed out. You are using...
Read more >
How can I prevent Leaflet from moving my marker while ...
Therefore, when zooming in/out, your actual icon "tip" (which is at bottom center) will "move" relatively to that position.
Read more >
Controlling Zoom and Pan | Maps JavaScript API
Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map...
Read more >
Marker position moves with zoom - SiteOrigin
It is at the correct position when zoomed in to the maximum level, however as you zoom out the icon gets progressively further...
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