alp*_*rim 2 javascript leaflet
我想动态地向标记传递一个类名。我只需要知道如何使用传单的添加类方法。我尝试了几种变体但没有成功。
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);
Run Code Online (Sandbox Code Playgroud)
您可以使用类的className选项L.Icon:
分配给图标和阴影图像的自定义类名称。默认为空。
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'
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1613 次 |
| 最近记录: |