簡體   English   中英

Leaflet:圖標標記未出現在地圖的右側

[英]Leaflet: Icon marker does not appear in the right point of the map

我在傳單地圖中放置了一個自定義圖標標記。

第一次加載地圖時,圖標標記不會出現在右側給定的坐標中。 它被“移動”,然后,如果你放大直到最小圖標出現在正確的點。 我想知道什么是錯的。

 var map = L.map('map').setView([-36.60664, -72.10342], 4); map.options.minZoom = 4; map.options.maxZoom = 18; L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' }).addTo(map); var LeafIcon = L.Icon.extend({ options: { //shadowUrl: 'leaf-shadow.png', iconSize: [30, 30], //shadowSize: [50, 64], iconAnchor: [22, 94], //shadowAnchor: [4, 62], popupAnchor: [-3, -76] } }); var myIcon = new LeafIcon({iconUrl: 'http://icons.veryicon.com/128/System/Small%20%26%20Flat/map%20marker.png'}); L.marker([-33.4247, -70.67877], {icon: myIcon}).bindPopup("Parque Fluvial Renato Poblete").addTo(map); 
  #map { width: 100%; height: 600px; } 
 <link href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" rel="stylesheet"/> <script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script> <div id='map'></div> 

您使用的圖標是128x128。 您必須將其大小調整為30x30,這是您在選項中聲明的大小。

如果要使用自定義圖標,還必須了解如何定義iconAnchorpopupAnchor

在您的情況下,可能的值可能是:

iconSize:    [30, 30],
iconAnchor:  [15, 30],
popupAnchor: [0, -25],

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM