我有一些代码试图将用户的标记设置为他的个人资料图片。图像是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);
}
答案 0 :(得分:2)
您需要在L.Marker
选项中定义图标:
var marker = L.marker([lat_ret, lon_ret], {icon: profilePicIcon})