LeafletJS markers move on zoom

后端 未结 2 1424
长发绾君心
长发绾君心 2020-12-09 12:21

Using LeafletJS which is ace, well until now :P We don\'t have a JSON object or anything, so I am taking the values out of the HTML (title, latlng) and creating markers. Gen

2条回答
  •  孤城傲影
    2020-12-09 12:54

    Given an icon that looks like this, with an overall size of 98px wide by 114px tall:

    • iconSize will be [98, 114]. This is the overall size of the icon.
    • Your iconAnchor will be [49, 114]. The icon anchors first numeral can be calculated by taking the first numeral in the iconSize and dividing by 2 (i.e., 98 ÷ 2 = 49)

    If you wanted to use this icon example, your final code should look like this:

    var locationIcon = L.icon({
      iconUrl:'location_marker_icon.png',
      iconSize: [98, 114],
      iconAnchor: [49, 114]
    });
    

    Here's a Gist example you can test with (I highlighted the lines in question) https://gist.github.com/anonymous/fe19008c911e1e6b6490#file-index-html-L38-L44

提交回复
热议问题