小叶圆半径无关紧要 [英] Leaflet circle radius doesn't matter

查看:169
本文介绍了小叶圆半径无关紧要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个游戏地图的扩展名,它从服务器显示一个活动的地图。地图正在工作,不是来自我的。重要的是说他们正在使用简单的CRS解决游戏坐标。

I'm working on an extension for a game map which displays an active map from server. The map is working and isn't from me. Important is to say that they're using simple CRS to work around the game coordinates.

现在我想创建一个半径为圆的圆。半径应该绑定到地图单位(latlng),而不是像素,所以如果放大圆圈应该在屏幕上有一个更大的半径,但相对于世界地图,半径相同。

Now I want to create a circle with a radius. The radius should bind to the map unit (latlng) and not to pixels, so if you zoom in the circle should have a bigger radius on screen, but relative to the world map the same radius.

所以我有这个代码作为地图的扩展名:

So I've this code as extension for the map:

var bla = L.circle([0,0], 1000, {'color': '#ffffff'}).addTo(map);

正如你所看到的,这只是一个测试。现在应该有半径为1000的圆(我认为它是在地图单位,因为文档中的值被命名为米)。但是我可以看到只是一个圆圈,但不能超过一个点。

As you can see, this is a test only. Now there should be a circle with the radius 1000 (I think it's in map "units" because the value in the docs is named as "meters"). But what I can see is only a circle but it isn't more than a dot.

如果我将半径设置为另一个大小,则没有效果: p>

If I set the radius to another size, there is no effect:

var bla = L.circle([0,0], 100000, {'color': '#ffffff'}).addTo(map);

即使半径为1000000000000000,半径计算也无关紧要。
负半径也不起作用。

And even a radius of 1000000000000000 doesn't matter for radius calculation. Negative radius doesn't work, too.

有什么想法吗?

推荐答案

当您使用0.7小册子与L.CRS.Simple投影时,会发生这种情况。

This happens when you use the 0.7 leaflet with the L.CRS.Simple projection.

他们已经在1.0测试版中修复了这个问题,但添加了一些新的错误(例如 - 很多leaflet.draw插件功能拒绝使用新版本)

They've fixed this in 1.0 beta but added a bunch of new bugs (for example - lots of leaflet.draw plugin features refuse to work with the new version)

我已经设法找到2个解决方法:

I've managed to find 2 workarounds for this:

选项1:升级到1.0 beta或更高版本

Option 1: Upgrading to a 1.0 beta or higher

选项2:由于他们有地球投影硬编码到L.Circle,我们也可以这样hack the leaflet-src.js:

Option 2: Since they've got an Earth projection hardcoded into the L.Circle, we can also hack the leaflet-src.js like this:

更改FROM

_getLatRadius: function () {
    return (this._mRadius / 40075017) * 360;
},

_getLngRadius: function () {
    return this._getLatRadius() / Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
},

TO

_getLatRadius: function () {
    return this._mRadius;
},

_getLngRadius: function () {
    return this._mRadius;
},

希望这有助于某人

这篇关于小叶圆半径无关紧要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆