2014-02-18 46 views
1

是否可以在GeoJSON中定义自己的标记图标?角度传单geojson自定义标记

我已经尝试了许多方法来获得预期的效果,但没有工作..从GeoJSON的地方的FeatureCollection我想添加自定义图标

示例代码:

{ 
    "type": "Feature", 
    "id": "Point1", 
    "properties": { 
     "name": "Last point" 
    }, 
    "geometry": { 
     "type": "Point", 
     "coordinates": [22.57031047873893, 51.25080964529834] 
    } 
} 

回答

0

MapBox已经为单张创造了CustomMarker plugin这应该做的伎俩。

而且从Mapbox另一个很好的例子,GeoJSON Custom Markers and Style

下面是该网站的一些示例代码:

var geoJsonData = { 
    "type": "FeatureCollection", 
    "features": [{ 
     "type": "Feature", 
     "properties": { 
     "fillColor": "#eeffee", 
     "fillOpacity": 0.8 
     }, 
     "geometry": { 
     "type": "Polygon", 
     "coordinates": [ 
      [ 
      [119.2895599, 21.718679], 
      [119.2895599, 25.373809], 
      [122.61840, 25.37380917], 
      [122.61840, 21.71867980], 
      [119.2895599, 21.718679] 
      ] 
     ] 
     } 
    }, { 
     "type": "Feature", 
     "properties": { 
     "marker-color": "#00ff00" 
     }, 
     "geometry": { 
     "type": "Point", 
     "coordinates": [120.89355, 23.68477] 
     } 
    }] 
}; 

var geoJson = L.geoJson(geoJsonData, { 
    pointToLayer: L.mapbox.marker.style, 
    style: function(feature) { return feature.properties; } 
}).addTo(map); 

注意:这是不是核心LeafletJS库的一部分,它需要mapbox.js(和mapbox.css)

0

如果您更新到最新版本(本文发稿时),您的geojson对象中的pointToLayer回调将开始工作。它似乎没有在0.7.7中实现,但是现在可以在主设备上使用,我认为它将在0.8+以上。

如果您只是将一个geoJSON定义分配给您的示波器的geojson属性,功能出现小册子将现在正确渲染它。