使用geoJson时传单交换坐标

Leaflet swap the coordinates when use geoJson(使用geoJson时传单交换坐标)
本文介绍了使用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-纬度.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)