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

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

      1. 围绕传单地图中的点旋转多边形

        时间:2023-08-09

            <tbody id='Op6T2'></tbody>
                <bdo id='Op6T2'></bdo><ul id='Op6T2'></ul>

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

                  本文介绍了围绕传单地图中的点旋转多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个问题,在我的传单地图中,我从多边形创建了一个三角形:

                  I have an issue, in my leaflet map I've created a triangle from polygon:

                  var polygon = L.polygon([ 
                      [parseFloat(decimal_lat),parseFloat(decimal_lon)], 
                      [parseFloat(decimal_lat) + 1, parseFloat(decimal_lon) - 1], 
                      [parseFloat(decimal_lat) + 1, parseFloat(decimal_lon) + 1] ],       
                      {
                              color:'green'
                      });
                  polygon.addTo(map);
                  

                  我想围绕 Point[decimal_lon, decimal_lat] 旋转这个多边形.但我无法解决它..
                  我创建了 DEMO,我正在旋转多项式,我想旋转我的三角形(多边形)向您展示我的问题.

                  and I want to rotate this polygon around Point[decimal_lon, decimal_lat]. But I'm not able to solve it..
                  I've created DEMO, where I'm rotating polynom the same I want to rotate my triangle (polygon) to show you my problem.

                  推荐答案

                  一种方法是通过矩阵旋转.https://en.wikipedia.org/wiki/Rotation_matrix.您想将该点平移到中心,然后应用旋转,然后将其平移回来.

                  One way to do it is through matrix rotation. https://en.wikipedia.org/wiki/Rotation_matrix. You want to translate the point to the center then apply the rotation, then translate it back.

                  这就是你的代码结尾的样子.

                  This is what the end of your code would look like.

                    //changing polyline with slider but I want to change polygon there
                    range_yaw.onchange = function() {
                      var yawAngle = (parseFloat(range_yaw.value) / (819 / 360) + 90)
                      // line
                      var center = [decimal_lat, decimal_lon]
                      var end = [decimal_lat + 2, decimal_lon + 2]
                      var pointListRotated = rotatePoints(center, [center, end], yawAngle)
                      polyline.setLatLngs(pointListRotated);
                      // polygon
                      var polygonPoints = [
                        center,
                        [center[0] + 1, center[1] - 1],
                        [center[0] + 1, center[1] + 1]
                      ]
                      polygonRotated = rotatePoints(center, polygonPoints, yawAngle)
                      polygon.setLatLngs(polygonRotated)
                    };
                  
                    //
                    // rotate a list of points in [lat, lng] format about the center.
                    //
                    function rotatePoints(center, points, yaw) {
                      var res = []
                      var angle = yaw * (Math.PI / 180)
                      for(var i=0; i<points.length; i++) {
                        var p = points[i]
                        // translate to center
                        var p2 = [ p[0]-center[0], p[1]-center[1] ]
                        // rotate using matrix rotation
                        var p3 = [ Math.cos(angle)*p2[0] - Math.sin(angle)*p2[1], Math.sin(angle)*p2[0] + Math.cos(angle)*p2[1]]
                        // translate back to center
                        var p4 = [ p3[0]+center[0], p3[1]+center[1]]
                        // done with that point
                        res.push(p4)
                      }
                      return res
                    }
                  

                  这是一个演示

                  这篇关于围绕传单地图中的点旋转多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:markercluster 是否与 LeafletProxy() 和选项 iconCreateFu 下一篇:如何使用 Leaflet.draw 从多边形中获取区域字符串

                  相关文章

                  最新文章

                  <legend id='texfH'><style id='texfH'><dir id='texfH'><q id='texfH'></q></dir></style></legend>
                    <bdo id='texfH'></bdo><ul id='texfH'></ul>
                    <tfoot id='texfH'></tfoot>
                  1. <small id='texfH'></small><noframes id='texfH'>

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