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

  • <legend id='TIrrg'><style id='TIrrg'><dir id='TIrrg'><q id='TIrrg'></q></dir></style></legend>
      <bdo id='TIrrg'></bdo><ul id='TIrrg'></ul>

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

        javascript中(多维)数组中的反向条目

        时间:2023-08-08

          • <bdo id='XHXHT'></bdo><ul id='XHXHT'></ul>

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

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

              • <tfoot id='XHXHT'></tfoot>

                • 本文介绍了javascript中(多维)数组中的反向条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 Leafletjs 在 openstretmap 上显示一些多边形.

                  I'm using leafletjs to display some polygons on an openstretmap.

                  我有一个外部数据资源,它为我提供了多边形的坐标.不幸的是,这个数组的坐标顺序错误.

                  I have an external data ressource which gives me the coordinates for the polygons. Unfortunately this array has the wrong order for the coordinates.

                  示例:我明白了:

                  [[10.5254913,52.2734311],[10.5258872,52.2734632]]

                  [[10.5254913,52.2734311],[10.5258872,52.2734632]]

                  我需要:

                  [[52.2734311,10.5254913],[52.2734632,10.5258872]]

                  [[52.2734311,10.5254913],[52.2734632,10.5258872]]

                  所以我给自己写了一个小函数,它遍历数组并反转条目:

                  So I wrote myself a little function which iterates through the array and reverses the entries:

                  var polCoords = [];
                  $.each(value.polygon[0], function(key,value){
                  polCoords[key] = [value[1],value[0]]; 
                  });
                  

                  这很好用.但是现在我发现多边形的一些数组是多维的!所以我有一个这样的数组:

                  This works just fine. But now I discovered that some arrays for the polygons are multidimensional! So I have an array like this:

                  [[[10.5261828,52.2726556],[10.5263222,52.2726767],[10.5263578,52.2726821],[10.5263637,52.2726677],[10.5263738,52.2726428],[10.5264042,52.2725678],[10.526186,52.2725346],[10.5261395,52.272649],[10.5261828,52.2726556]],[[10.5261828,52.2726556],[10.5261713,52.2726821],[10.5261621,52.2727047],[10.5259248,52.2726687],[10.5257879,52.2726479],[10.5257435,52.2727573],[10.5258014,52.2727661],[10.5257967,52.2727777],[10.5260173,52.2728113],[10.5261107,52.2728254],[10.5260641,52.2729403],[10.5259711,52.2729262],[10.5259526,52.2729234],[10.5258101,52.2732746],[10.5258697,52.2732837],[10.5260636,52.2733132],[10.5261371,52.2733243],[10.5262746,52.2729854],[10.5262888,52.2729876],[10.526312,52.2729304],[10.5262636,52.2729231],[10.5262239,52.272917],[10.5263222,52.2726767],[10.5261828,52.2726556]],[[10.5260636,52.2733132],[10.5260595,52.2733365],[10.5260575,52.2733486],[10.5258607,52.2733326],[10.5258631,52.2733195],[10.5258697,52.2732837],[10.5260636,52.2733132]]]
                  

                  它似乎由多个多边形组成.

                  Which seems to consist of more than one polygon.

                  如何反转这个多维数组的每个条目?

                  How can I reverse every entry of this multidimensional array?

                  推荐答案

                  假设 array 是您的数据,尝试类似:

                  Assuming array is your data, try something like:

                  var reversed = array.map(function reverse(item) {
                      return Array.isArray(item) && Array.isArray(item[0]) 
                                 ? item.map(reverse) 
                                 : item.reverse();
                  });
                  

                  这是普通的 JavaScript.我认为在 jquery 中会是这样的:

                  This is vanilla JavaScript. I think in jquery would be something like:

                  var reversed = $.map(array, function reverse(item) {
                      return $.isArray(item) && $.isArray(item[0])
                                 ? $.map(item, reverse)
                                 : item.reverse();
                  });
                  

                  我没有尝试,但应该可以同时使用它们.告诉我.

                  I didn't try but should works both of them. Let me know.

                  这篇关于javascript中(多维)数组中的反向条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何检查 svg 路径是否具有与数组中的值匹配的类 下一篇:结合 React 和 Leaflet 的好方法

                  相关文章

                  最新文章

                    <bdo id='T5r12'></bdo><ul id='T5r12'></ul>
                  <tfoot id='T5r12'></tfoot>

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

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

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