• Resolved philippenantes

    (@philippenantes)


    Hey there, thank you for this awesome plugin.
    I ran into an issue :
    When specifying custom (png) markers, they are not displayed at their correct place. They seem to have a small offset. Zooming out would increase the inaccuracy. When looking closer, I figured out the markers seem to have a wrong origin, as the offset value seem to be related to the size of the custom marker icon.

    For those interested, I used this workaround which works for me because all my markers are the same size.

    1/ Embed the leaflet.js on your own site so you have control over it
    2/ unminify it
    3/ in the database (with phpmyadmin for example),change in the Options table (typically wp_options), the option_name wich value is “leaflet_js_url”, in order to reflect your own URL to leaflet.js
    4/ edit your local copy of leaflet.js, locate the fonction and alter it :

    function rt(t, i, e) {
    var n = i || new x(0, 0);
    var myx = n.x + 13;// <— YOUR ICON WIDTH /2
    var myy = n.y + 37;// <— YOUR ICON HEIGHT
    t.style[ce] = (Ri ? “translate(” + myx + “px,” + myy + “px)” : “translate3d(” + myx + “px,” + myy + “px,0)”) + (e ? ” scale(” + e + “)” : “”)
    }

    Note this won’t support future updates of the plugin, this is a quick and dirty workaround , I didn’t have time to investigate further

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author bozdoz

    (@bozdoz)

    You could also get the source code from here: https://unpkg.com/[email protected]/dist/leaflet-src.js

    Plugin Contributor hupe13

    (@hupe13)

    This works for me:

    [leaflet-marker iconUrl="/path/to/image.png" iconSize="32,32" iconAnchor="16,16" lat=.... lng=.....]description[/leaflet-marker]

    The iconAnchor defines where the marker is. The middle of the marker points to lat/lng in this example.

    Thread Starter philippenantes

    (@philippenantes)

    Thank you guys for the followup.

    I was not aware of the iconSize parameter, thank you for this one. I guess this will make my workaround useless ??

    Thread Starter philippenantes

    (@philippenantes)

    Hey there,

    specifying parameters iconSize and iconAnchor works perfectly.

    My suggested workaround is irrelevant, but maybe we should leave this thread, should someone miss the doc.

    Many thanks
    Cheers !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Solved][2.14.0] Custom markers slightly misplaced’ is closed to new replies.