leafletjs:折线列表到geojson

leafletjs: polyline list into geojson

我有折线列表。我想让它更有条理。如何将我的多段线列表放入 GeoJSON 中?

var point1 = new coordsToLatLngArray(0, 100);
var point2 = new coordsToLatLngArray(200, 150);
var point3 = new coordsToLatLngArray(400, 70);
var point4 = new coordsToLatLngArray(10, 70);
var point5 = new coordsToLatLngArray(90, 50);
var pointList = [point1, point2, point3, point4, point5];

var firstpolyline = new L.polyline(pointList, {
color: 'red',
weight: 3,
opacity: 0.5,
smoothFactor: 1

});
firstpolyline.addTo(map);

我正在尝试使用:http://leafletjs.com/examples/geojson.html 但它没有用。我的路线在地图之外:

var geojsonFeature = [{
    "type": "LineString",
    "coordinates":
    [
        [0,0], 
        [-100,100]
    ]
}];
var myStyle = {
    "color": "#ff7800",
    "weight": 5,
    "opacity": 0.65
};
var myLayer = L.geoJson(coordsToLatLngArray(), {style: myStyle }).addTo(l);
myLayer.addData(geojsonFeature);

问题演示: http://jsfiddle.net/n4k1psuh/

只会向coordsToLatLngArray传递一个参数,一个数组:

[longitude,latitude]

函数必须如下所示:

var coordsToLatLngArray = function(c) {
    var e = fixLat(c[1]),
        t = c[0],
        n = e / latScale + latScaleVal / 2 / latScale,
        r = t / longScale + longScaleVal / 2 / longScale;
    return [-n, r]
};

注意:在 geoJSON 中,坐标具有相反的顺序,[longitude,latitude],因此坐标必须是:

        [
            [100, 0],
            [150, 200],
            [70,400],
            [70,10],
            [50,90]
        ]

绘制特征调用:

    var myLayer = L.geoJson(geojsonFeature, {
        style: myStyle,
        coordsToLatLng:coordsToLatLngArray
    }).addTo(l);

演示:http://jsfiddle.net/Ltaw5teo/