如何在传单制作者中使用addClass方法?

时间:2015-10-03 21:45:04

标签: javascript leaflet

我想动态地传递标记一个类名。我只需要知道如何使用leaflet的add class方法。我试过几个变种没有成功。

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

1 个答案:

答案 0 :(得分:3)

您可以使用LinkedHashMap类的className选项:

  

要分配给图标和阴影图像的自定义类名。默认为空。

http://leafletjs.com/reference.html#icon-classname

L.Icon