使用GeoJSON的坐标连接传单中的2个或更多标记

时间:2015-09-08 16:50:48

标签: leaflet point geojson marker polyline

我必须在2个或更多点(标记)之间画一条线。坐标位于GeoJSON文件中(附加)。我试图为属性做一个任务:这些是“节点工作者”一个点“主人”,另一个和“结工人”连接“主人”。 但是没有用,这就是我需要你帮助的原因......我怎样才能实现它?

{"type": "FeatureCollection", "features": [
{"type": "Feature","properties": {"id":"1","name":"Berlin","wert":"","pc":"master"},"geometry": {"type": "Point","coordinates": [13.523563700000068,52.4909447]}},
{"type": "Feature","properties": {"id":"2","name":"Hamburg","wert":"0","pc":"wn"},"geometry": {"type": "Point","coordinates": [9.99368179999999,53.5510846]}},
{"type": "Feature","properties": {"id":"3","name":"München","wert":"128","pc":"wn"},"geometry": {"type": "Point","coordinates": [11.581980599999952,48.1351253]}},
{"type": "Feature","properties": {"id":"4","name":"Frankfurt am Main","wert":"-128","pc":"wn"},"geometry": {"type": "Point","coordinates": [8.682126700000026,50.1109221]}}
]}

1 个答案:

答案 0 :(得分:0)

为您的featurecollection添加LineString个功能:this line Leaflet的L.GeoJSON图层会将它们转换为折线:http://geojson.org/geojson-spec.html#id3

如果无法更改GeoJSON文件。您可以编写循环遍历图层中要素的逻辑,然后将主要和客户分开,然后在它们之间绘制折线。

评论后:

您已经提供了具有主PC坐标的GeoJSON。 13.523563700000068,52.4909447您想通过Polyline与客户端PC连接。我将选择第一个坐标:9.99368179999999,53.5510846。因此,您为GeoJSON集合添加了另一个功能,即折线:

{
    "type": "Feature",
    "geometry": {
        "type": "LineString",
        "coordinates": [
            [13.523563700000068,52.4909447], // Master PC coordinates
            [9.99368179999999,53.5510846] // WN1 Coordinates
        ]
    },
    "properties": {
        "label": "From Master to First client"
    }
}

你是金子。这是一个有效的例子:http://leafletjs.com/reference.html#polyline