MapBox自定义引脚不显示

时间:2015-04-17 11:12:59

标签: maps mapbox

我有一个自定义引脚,但它显示为一个丑陋的默认灰色引脚。这是我的功能,我在设置我的pin。这是一个获取我的引脚的循环

    featureCollection.features.push({
            "type": "Feature",
            "properties": {
                "id": item.id,
                "title": item.title,
                "image":item.image,
                "description": item.description,
                "icon": {
                    "iconUrl": "../images/pin.png",
                    "iconSize": [29, 36],
                    "iconAnchor": [25, 25],
                    "popupAnchor": [0, -15],
                    "className": "pin"
                }
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    item.long,
                    item.lat
                ]
            }
        });

此处使用示例图标代码https://www.mapbox.com/mapbox.js/example/v1.0.0/custom-marker/

1 个答案:

答案 0 :(得分:1)

您需要准备自定义标记

var customIcon = L.icon({
    "iconUrl": "../images/pin.png",
    "iconSize": [29, 36],
    "iconAnchor": [25, 25],
    "popupAnchor": [0, -15],
    "className": "pin"
})

然后设置选项结构以使用此新图标,如

geojsonOptions = {
    pointToLayer: function(feature,latLng) {
        return L.marker(latLng,{icon:myIcon})
    }
}

然后在添加到地图时包含这样的选项。 L.geoJson(featureCollection,geojsonOptions).addTo(map)