【问题标题】:How to use custom markers with leaflet?如何在传单中使用自定义标记?
【发布时间】:2014-02-05 17:56:22
【问题描述】:

我正在从 google doc 上的共享 CSV 中提取标记数据。我可以在传单中将它们映射好。我想使用我自己的 PNG 标记。我还想按数据类别分配不同的标记(如果 'employees' 字段 =

【问题讨论】:

    标签: leaflet mapbox tilemill


    【解决方案1】:

    文档页面上有一个带有自定义图标的标记示例:http://leafletjs.com/examples/custom-icons.html

    var greenIcon = L.icon({
        iconUrl: 'leaf-green.png',
        shadowUrl: 'leaf-shadow.png',
    
        iconSize:     [38, 95], // size of the icon
        shadowSize:   [50, 64], // size of the shadow
        iconAnchor:   [22, 94], // point of the icon which will correspond to marker's location
        shadowAnchor: [4, 62],  // the same for the shadow
        popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
    });
    

    定义所有图标,然后在创建标记时使用它们。例如,

    var employeesLowIcon = L.icon({ ... });
    var employeesHighIcon = L.icon({ ... });
    var markerIcon = employees < 10 ? employeesLowIcon : employeesHighIcon;
    L.marker([51.5, -0.09], {icon: markerIcon }).addTo(map);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-19
      • 2016-10-18
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      相关资源
      最近更新 更多