<small id='PZo4L'></small><noframes id='PZo4L'>

      <tfoot id='PZo4L'></tfoot>
      • <bdo id='PZo4L'></bdo><ul id='PZo4L'></ul>

    1. <legend id='PZo4L'><style id='PZo4L'><dir id='PZo4L'><q id='PZo4L'></q></dir></style></legend>

        <i id='PZo4L'><tr id='PZo4L'><dt id='PZo4L'><q id='PZo4L'><span id='PZo4L'><b id='PZo4L'><form id='PZo4L'><ins id='PZo4L'></ins><ul id='PZo4L'></ul><sub id='PZo4L'></sub></form><legend id='PZo4L'></legend><bdo id='PZo4L'><pre id='PZo4L'><center id='PZo4L'></center></pre></bdo></b><th id='PZo4L'></th></span></q></dt></tr></i><div id='PZo4L'><tfoot id='PZo4L'></tfoot><dl id='PZo4L'><fieldset id='PZo4L'></fieldset></dl></div>

        传单:如何交换从 ajax 调用接收到的坐标

        时间:2023-08-09

          1. <small id='cyw1U'></small><noframes id='cyw1U'>

                  <tbody id='cyw1U'></tbody>
                • <bdo id='cyw1U'></bdo><ul id='cyw1U'></ul>
                  <tfoot id='cyw1U'></tfoot>

                  <i id='cyw1U'><tr id='cyw1U'><dt id='cyw1U'><q id='cyw1U'><span id='cyw1U'><b id='cyw1U'><form id='cyw1U'><ins id='cyw1U'></ins><ul id='cyw1U'></ul><sub id='cyw1U'></sub></form><legend id='cyw1U'></legend><bdo id='cyw1U'><pre id='cyw1U'><center id='cyw1U'></center></pre></bdo></b><th id='cyw1U'></th></span></q></dt></tr></i><div id='cyw1U'><tfoot id='cyw1U'></tfoot><dl id='cyw1U'><fieldset id='cyw1U'></fieldset></dl></div>

                • <legend id='cyw1U'><style id='cyw1U'><dir id='cyw1U'><q id='cyw1U'></q></dir></style></legend>
                  本文介绍了传单:如何交换从 ajax 调用接收到的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 Leaflet 1.0.3 和一些插件,包括 Leaflet.ajax.我的 L.geo.ajax 调用正在工作并返回 geojson 对象,但是坐标是相反的.我创建了一个函数来解决这个问题:

                  I am using Leaflet 1.0.3 and a few plugins including Leaflet.ajax. My L.geo.ajax call is working and returning geojson objects, however, the coordinates are reversed. I created a function to fix this:

                      var convertLatLng = function (latlng) {
                      var temp = latlng[y];
                      latlng[y] = latlng[x];
                      latlng[x] = temp;
                      convertedLatLng = latlng;
                      return convertedLatLng;
                      console.log('this function is running')
                      }

                  但我的问题是我不知道该放在哪里.我是否在我的 geoJson 调用中运行它?如果有,在哪里?这是 ajax 调用的片段:

                  But my problem is I don't know where to put it. Do I run it inside my geoJson call? If so, where? Here is a snippet of the ajax call:

                      var geojson = L.geoJson.ajax('http://www.iotwf.com/deployment_map/json', {
                  
                      pointToLayer: function (feature, latlng) {
                      convertLatLng(latlng);
                      ...
                      },
                      onEachFeature: function(feature, layer) {
                   
                      ...
                      }
                      });

                  我也愿意接受其他可以解决问题的建议.

                  I am also open to other suggestions for what may fix it.

                  推荐答案

                  欢迎来到 SO!

                  首先确保你的坐标确实是颠倒的.

                  First make sure that your coordinates are indeed reversed.

                  请注意,GeoJSON 格式需要 [longitude, latitude],而 Leaflet 通常需要 [latitude, longitude],除了 L.geoJSON() 工厂(和插件 L.geoJson.ajax()),它会自动读取 GeoJSON 顺序并在正确的坐标处构建图层.

                  Note that the GeoJSON format expects [longitude, latitude], whereas Leaflet usually expects [latitude, longitude], EXCEPT in the case of L.geoJSON() factory (and the plugin L.geoJson.ajax()), where it automatically reads the GeoJSON order and builds the layers at the correct coordinates.

                  如果您的坐标仍然是反向的,那么适当的更正显然是直接更正数据源中的顺序(或任何服务输出您的数据),以便您获得实际兼容的 GeoJSON 数据.这将解决许多未来的难题.

                  If your coordinates are still reversed, the appropriate correction would be obviously to correct the order in your data source directly (or whatever service outputs your data), so that you get actually compliant GeoJSON data. That would solve many future headaches.

                  如果这不可能,那么您确实可以在脚本中尝试解决方法.

                  If that is not possible, then indeed you could try a workaround within your script.

                  最合适的方法可能是使用 L.geoJSON 工厂的>coordsToLatLng 选项.

                  The most appropriate way to do so would probably be to use the coordsToLatLng option of the L.geoJSON factory.

                  更改其 默认实现,你会得到类似的东西:

                  Changing its default implementation, you would get something like:

                  L.geoJson.ajax(url, {
                      coordsToLatLng: function (coords) {
                          //                    latitude , longitude, altitude
                          //return new L.LatLng(coords[1], coords[0], coords[2]); //Normal behavior
                          return new L.LatLng(coords[0], coords[1], coords[2]);
                      }
                  });
                  

                  这篇关于传单:如何交换从 ajax 调用接收到的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:沿两点之间的直线获取纬度和经度点,按百分比 下一篇:Leaflet:当边界改变时触发一个事件

                  相关文章

                  最新文章

                  <tfoot id='PZKWK'></tfoot>

                    <i id='PZKWK'><tr id='PZKWK'><dt id='PZKWK'><q id='PZKWK'><span id='PZKWK'><b id='PZKWK'><form id='PZKWK'><ins id='PZKWK'></ins><ul id='PZKWK'></ul><sub id='PZKWK'></sub></form><legend id='PZKWK'></legend><bdo id='PZKWK'><pre id='PZKWK'><center id='PZKWK'></center></pre></bdo></b><th id='PZKWK'></th></span></q></dt></tr></i><div id='PZKWK'><tfoot id='PZKWK'></tfoot><dl id='PZKWK'><fieldset id='PZKWK'></fieldset></dl></div>
                    • <bdo id='PZKWK'></bdo><ul id='PZKWK'></ul>
                  1. <legend id='PZKWK'><style id='PZKWK'><dir id='PZKWK'><q id='PZKWK'></q></dir></style></legend>

                      <small id='PZKWK'></small><noframes id='PZKWK'>