Javascript 如何在传单制作中使用addClass方法?
我想动态地给标记传递一个类名。我只需要知道如何使用传单的addclass方法。Iv'e尝试了几个变体,但没有成功Javascript 如何在传单制作中使用addClass方法?,javascript,leaflet,Javascript,Leaflet,我想动态地给标记传递一个类名。我只需要知道如何使用传单的addclass方法。Iv'e尝试了几个变体,但没有成功 var venueName = venues[i]['venue']['name']; /* Build icon for each venue. */ var fsqIcon = venues[i]['venue']['categories'][0]['icon']; var lea
var venueName = venues[i]['venue']['name'];
/* Build icon for each venue. */
var fsqIcon = venues[i]['venue']['categories'][0]['icon'];
var leafletIcon = L.Icon.extend({
options: {
iconUrl: fsqIcon['prefix'] + '32' + fsqIcon['suffix'],
shadowUrl: null,
iconSize: new L.Point(32, 32),
iconAnchor: new L.Point(16, 41),
popupAnchor: new L.Point(0, -51)
}
});
var icon = new leafletIcon();
var marker = new L.Marker(latLng, {
icon: icon,
riseOnHover: true
})/*tried adding here */
.bindPopup("<div class='venueName'>" + '<h1>' + '<u>' + venueName + '</u>' + '</h1>' + '<br>' + venueLocation + '<br>' + 'Category:' + " " + category + '<br>' + 'Rating:' + " " + rating + '<br>' + venueHours + '</div>', {
closeButton: false
})
.on('click', function(e) {
this.openPopup();
this.bounce(1000, 50);
})
.on('mouseout', function(e) {
this.closePopup();
/*also tried this dot method here*/
}).addClass(venueName);
/*also tried this variation as well*/
marker.addClass(venueName);
map.addLayer(marker);
var venueName=场馆[i]['venue']['name'];
/*为每个场馆创建图标*/
var fsqIcon=场馆[i]['场馆]['categories'][0]['icon'];
var-Icon=L.Icon.extend({
选项:{
iconUrl:fsqIcon['prefix']+'32'+fsqIcon['suffix'],
shadowUrl:null,
iconSize:新的L点(32,32),
iconAnchor:新的L点(16,41),
popupAnchor:新的L点(0,-51)
}
});
var icon=新的传单图标();
var标记=新的L.标记(板条{
图标:图标,
riseOnHover:正确
})/*尝试在此处添加*/
.bindPopup(“+”+“+”+“+”+“+”+”+“+”+”
“+venueLocation+”
“+”类别:“+”+类别+”
“+”评级:“+”+”
“+venueHours+”{
关闭按钮:false
})
.on('click',函数(e){
这个.openPopup();
这个。反弹(1000,50);
})
.on('mouseout',函数(e){
this.closePopup();
/*这里也试过这个点法*/
}).addClass(VenuName);
/*也尝试过这种变化*/
marker.addClass(VenuName);
添加图层(标记);
您可以使用L.图标的className
选项
类:
指定给图标和阴影图像的自定义类名。默认为空
var leafletIcon = L.Icon.extend({
options: {
iconUrl: fsqIcon['prefix'] + '32' + fsqIcon['suffix'],
shadowUrl: null,
iconSize: new L.Point(32, 32),
iconAnchor: new L.Point(16, 41),
popupAnchor: new L.Point(0, -51),
className: 'my-own-class'
}
});