我正在使用 leaflet.draw 插件,使用 L.CRS.Simple
处理简单的图像。
除了绘制圆圈之外,绘图工具栏工作正常。
http://playground-leaflet.rhcloud.com/kapi/edit?html,output
使用L.CRS.Simple
时,如何使用Leaflet.draw插件在Leaflet map 上绘制圆圈?
最佳答案
问题在于使用 L.CRS.simple 并尝试绘制圆形。 当绘制圆时(L.Draw.circle_drawShape()),半径是根据L.LatLng.distanceTo的结果设置的,并且这个距离实际上是根据L.CRS.Earth计算的
当使用 L.CRS.Smple 时,半径变得非常大,超出范围。 在绘制其他形状时,这不会成为问题,因为它们不使用 L.LatLng.distanceTo 方法。
作为解决方法,您可以执行此覆盖:
L.LatLng.prototype.distanceTo = function (currentPostion) {
var dx = currentPostion.lng - this.lng;
var dy = currentPostion.lat - this.lat;
return Math.sqrt(dx*dx + dy*dy);
}
这样就可以了。
以下链接给出了该问题的详细说明: https://github.com/Leaflet/Leaflet.draw/issues/611
希望这有帮助!!!
关于javascript - 如何用leaflet.draw和CRS.Simple画圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44403775/