如何在Map中显示自定义标记

时间:2015-04-24 07:52:28

标签: leaflet geojson

您好我需要在地图中显示自定义标记,但无法在我的地图上显示,请帮我如何显示自定义标记。

这是我的json对象:

{
    "features": [
    {
      "geometry": {
        "coordinates": [
          [-89.39982622861862, 43.06710857435938 ],
          [-89.39982622861862, 43.06710857435938 ]
        ],
        "type": "Point"
      },
      "id": "ci7gsmklj004ahym0qpgca8j7",
      "properties": {
        "icon": {
          "options": {
            "className": "",
            "iconUrl": "/hb/assets/leaflet/images/d.png",
            "iconSize": [ 64, 64],
            "iconAnchor": [ 32, 32],
            "popupAnchor": [  0, -24 ]
          },
          "_initHooksCalled": true
        },
        "text": "Hari",
        "title": "Hunt Area #1"
      },
      "type": "Feature"
    }
     ],
    "type": "FeatureCollection"
    }

这是我的代码:

 var layer = new L.tileLayer('http://{s}.tiles.mapbox.com/v4/zittelevan.lgjj093b/{z}/{x}/{y}.png?access_token={token}', {
                            attribution: 'Attribute data here'
                            maxZoom: 18,
                            token: "Token Here"
                        });
                        var map = new L.map('map', {
                            center:[43.10361493125458,89.52398300170898],
                            zoom: 18,
                            layers: [layer],
                        });

                        L.geoJson(features).addTo(map);

我关注了不同的网站,但无法找到正确的解决方案,所以我请求人们请帮我如何在地图上显示自定义标记。

2 个答案:

答案 0 :(得分:0)

您需要使用pointToLayer的{​​{1}}(http://leafletjs.com/reference.html#geojson-pointtolayer)选项。 Leafet没有通过检查GeoJSON功能的属性哈希来计算自定义标记设置,您需要自己设置它。下面的代码。

L.geoJson

答案 1 :(得分:0)

我这样做了我得到了答案

var myIcon = L.icon({
"className": "",
"iconUrl": "/hb/assets/leaflet/images/d.png",
"iconSize": [ 64, 64],
"iconAnchor": [ 32, 32],
"popupAnchor": [  0, -24 ]
});

L.marker([44.86475133784528,-88.98447811603546],{icon:myIcon }).addTo(map);