2015-02-08 65 views
0

我有折線列表。我想讓它更有條理。我怎樣才能讓我的折線列表進入GeoJSON?leafletjs:折線列表到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/

回答

0

只會有被傳遞的一個參數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] 
}; 

N OTE:在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/

+0

非常感謝你,拯救生命! – 2015-02-08 21:41:03