问题描述
我有一个小 Leaflet 应用程序,该应用程序从服务器获取 geoJson 对象并显示它,特别是 LineString
.我在服务器端使用的 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()
时我不知道该怎么做.
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);
});
因为我不想在服务器端更改任何内容,所以我尝试了这个:
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 对象和其他一些数据中访问坐标数组,并将折线直接绘制到地图上.问题是它把我的路线放在中东中部而不是匈牙利,所以它实际上是交换坐标.为什么 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()
并阅读 为什么有时坐标是 lat-lng 有时是 lng-纬度.
这篇关于使用geoJson时传单交换坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!