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

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

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

        传单正方形给定中心和正方形宽度

        时间:2023-08-09

          <bdo id='tt2kx'></bdo><ul id='tt2kx'></ul>

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

              <legend id='tt2kx'><style id='tt2kx'><dir id='tt2kx'><q id='tt2kx'></q></dir></style></legend>

                • <small id='tt2kx'></small><noframes id='tt2kx'>

                  <tfoot id='tt2kx'></tfoot>
                  本文介绍了传单正方形给定中心和正方形宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 Leaflet 上,给定中心和半径,我可以轻松创建一个新圆:

                  On Leaflet I can create a new circle easily given the centre and the radius:

                  // Circle
                  var radius = 500; // [metres]
                  var circleLocation = new L.LatLng(centreLat, centreLon);
                  var circleOptions = {
                      color: 'red',
                      fillColor: '#f03',
                      fillOpacity: 0.5
                  };
                  var circle = new L.Circle(circleLocation, radius, circleOptions);
                  map.addLayer(circle);
                  

                  上面的圆圈创建和绘制没有问题,所以就是这样.

                  The circle above is created and drawn without problems, so it is all.

                  但是,如果我现在想创建并绘制一个与圆为界的矩形,它就行不通了.这是我所做的:

                  However, if I wanted now to create and draw a rectangle that which bounds the circle, it does not work. Here is what I did:

                  // Rectangle
                  var halfside = radius;   // It was 500 metres as reported above
                  // convert from latlng to a point (<-- I think the problem is here!)
                  var centre_point = map.latLngToContainerPoint([newCentreLat, newCentreLon]);
                  // Compute SouthWest and NorthEast points
                  var sw_point = L.point([centre_point.x - halfside, centre_point.y - halfside]);
                  var ne_point = L.point([centre_point.x + halfside, centre_point.y + halfside]);
                  // Convert the obtained points to latlng
                  var sw_LatLng = map.containerPointToLatLng(sw_point);
                  var ne_LatLng = map.containerPointToLatLng(ne_point);
                  // Create bound
                  var bounds = [sw_LatLng, ne_LatLng];
                  var rectangleOptions = {
                      color: 'red',
                      fillColor: '#f03',
                      fillOpacity: 0.5
                  };
                  var rectangle = L.rectangle(bounds, rectangleOptions);
                  map.addLayer(rectangle);
                  

                  我得到的矩形的大小与500米无关.此外,看起来矩形的大小取决于地图的缩放级别.圈子没有出现这些问题.

                  The size of the rectangle that I obtain has nothing to do with 500 metres. Also, it looks like the size of the rectangle depends on the zoom level the map is. None of these problems arose for the circle.

                  我怀疑我将纬度/经度转换为点的方式是错误的,反之亦然.

                  I suspect the way I transform the latitude/longitude to point and viceversa is wrong.

                  推荐答案

                  使用L.Circle继承自L.PathgetBounds方法即可代码>:

                  Just use the getBounds method that L.Circle inherits from L.Path:

                  返回路径的 LatLngBounds.

                  Returns the LatLngBounds of the path.

                  http://leafletjs.com/reference.html#path-getbounds

                  var circle = new L.Circle([0,0], 500).addTo(map);
                  
                  var rectangle = new L.Rectangle(circle.getBounds()).addTo(map);
                  

                  Plunker 上的工作示例:http://plnkr.co/edit/n55xLOIohNMY6sVA3GLT?p=preview

                  Working example on Plunker: http://plnkr.co/edit/n55xLOIohNMY6sVA3GLT?p=preview

                  这篇关于传单正方形给定中心和正方形宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Leaflet Markercluster:从聚类中免除标记 下一篇:如何在 Leaflet.js 中更改地图中心

                  相关文章

                  最新文章

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

                      <bdo id='4Atoj'></bdo><ul id='4Atoj'></ul>
                    <tfoot id='4Atoj'></tfoot>
                  1. <small id='4Atoj'></small><noframes id='4Atoj'>