Javascript 带有传单的自定义图像标记不显示图像
我有一些代码试图将用户的标记设置为他的个人资料图像。这张图片是JPG,我认为这是问题所在,因为我认为这张传单不支持JPG。但以防万一,这是我的代码。控制台中没有错误,标记只是保留默认标记Javascript 带有传单的自定义图像标记不显示图像,javascript,leaflet,Javascript,Leaflet,我有一些代码试图将用户的标记设置为他的个人资料图像。这张图片是JPG,我认为这是问题所在,因为我认为这张传单不支持JPG。但以防万一,这是我的代码。控制台中没有错误,标记只是保留默认标记 var markers = new L.FeatureGroup(); function addMarkerGroup(lat_ret,lon_ret,map,user, profile_pic) { console.log(profile_pic); var profilePicIcon = L.ic
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})
我也有类似的问题。我已经定义了图标,但是,我是否必须声明一个新的功能组和层,或者我可以只使用var marker=L.marker([lat_-ret,lon_-ret])。addTo(map)这就是我要的谢谢!