带有传单的自定义图像标记不显示图像

Custom image markers with leaflet not displaying image

本文关键字:图像 显示 显示图 自定义      更新时间:2023-09-26

我有一些代码试图将用户的标记设置为他的个人资料图像。图片是JPG,我认为这是问题所在,因为我不认为传单支持JPG。但以防万一,这是我的代码。控制台中没有错误,标记仍然是默认标记。

var markers = new L.FeatureGroup();
function addMarkerGroup(lat_ret,lon_ret,map,user, profile_pic) {
  console.log(profile_pic);
  var profilePicIcon = L.icon({
    iconUrl: profile_pic,
    iconSize: [50, 50], // size of the icon
    iconAnchor: [25, 25], // point of the icon which will correspond to marker's location
    popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
  });
  map.removeLayer(markers);
  markers = new L.FeatureGroup();
  var marker = L.marker([lat_ret, lon_ret]).addTo(map).bindPopup("User:" + user,{autoClose: false,autoPan: false,icon: profilePicIcon}).openPopup();
  markers.addLayer(marker);
  map.addLayer(markers);
}

您需要在L.Marker选项中定义图标:

var marker = L.marker([lat_ret, lon_ret], {icon: profilePicIcon})