問題描述
我有一個(gè)小 Leaflet 應(yīng)用程序,該應(yīng)用程序從服務(wù)器獲取 geoJson 對象并顯示它,特別是 LineString
.我在服務(wù)器端使用的 JSON 解析器工作正常.客戶端腳本也沒問題.
I have little Leaflet application where the app get geoJson objects from server, and display it, specially LineString
. The JSON parser that i use on server side works properly. And the client side script was ok too.
但由于某些原因,我想在路線上畫箭頭,但在使用 L.geoJson()
時(shí)我不知道該怎么做.
But some reasons I would like to draw arrow on the routes, and I can't figure out how to do it when using L.geoJson()
.
帶有L.geoJson()
的代碼:
getJsonFrom(routeQueryURL, params, function(data) {
var a = L.geoJson(data, {
onEachFeature: bindRouteDirection,
}).addTo(map);
});
因?yàn)槲也幌朐诜?wù)器端更改任何內(nèi)容,所以我嘗試了這個(gè):
Because I don't want to change anything on server side, I tried this:
getJsonFrom(routeQueryURL, param, function(data) {
$.each(data, function(index, feature) {
var polyline = new L.Polyline(feature.geometry.coordinates, {
color: feature.properties.color,
opacity: 0.8
}).addTo(routeMapLayer);
var decorator = L.polylineDecorator(polyline, {
patterns: [{
offset: 25,
repeat: 50,
symbol: L.Symbol.arrowHead({
pixelSize: 15,
pathOptions: {
stroke: true,
color: feature.properties.color,
fillOpacity: 0.8,
polygon: false,
weight: 3
}
})
}]
}).addTo(routeMapLayer);
map.addLayer(routeMapLayer);
});
});
所以我從 geoJson 對象和其他一些數(shù)據(jù)中訪問坐標(biāo)數(shù)組,并將折線直接繪制到地圖上.問題是它把我的路線放在中東中部而不是匈牙利,所以它實(shí)際上是交換坐標(biāo).為什么 L.Polyline
處理不同的形式 L.geoJson()
?
So i access the array of coordinates from the geoJson object, and some other data, and draw the polyline directly on to map.The problem is that it's put my route into the middle of middle east instead of Hungary, so it's actually swap the coordinates. Why does L.Polyline
handle the different form L.geoJson()
?
推薦答案
使用L.GeoJSON.coordsToLatLng()
并閱讀 為什么有時(shí)坐標(biāo)是 lat-lng 有時(shí)是 lng-緯度.
這篇關(guān)于使用geoJson時(shí)傳單交換坐標(biāo)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!