gpt4 book ai didi

javascript - 如何使用传单制作中的addClass方法?

转载 作者:行者123 更新时间:2023-12-02 17:31:19 25 4
gpt4 key购买 nike

我想动态地向标记传递一个类名。我只需要知道如何使用传单的添加类方法。我尝试了几种变体,但没有成功。

            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);

最佳答案

您可以使用L.Icon类的className选项:

A custom class name to assign to both icon and shadow images. Empty by default.

http://leafletjs.com/reference.html#icon-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'
}
});

关于javascript - 如何使用传单制作中的addClass方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32927798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com