传单在使用geoJson时交换坐标 [英] Leaflet swap the coordinates when use geoJson

查看:111
本文介绍了传单在使用geoJson时交换坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很小的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-lat .

这篇关于传单在使用geoJson时交换坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆