简体   繁体   English

leaflet.js显示空地图:未捕获错误:无效的LatLng对象:(NaN,NaN)

[英]leaflet.js is showing empty map: Uncaught Error: Invalid LatLng object: (NaN, NaN)

I was just trying to setup my first map display with mapbox.js . 我只是想用mapbox.js设置我的第一个地图显示。 Unfortunately it's just not working and I don't know why. 不幸的是,它只是无法正常工作,我也不知道为什么。

I tried to reduce it to a very basic setup but still no luck (full source may be found here ). 我试图将其简化为一个非常基本的设置,但是仍然没有运气(可以在此处找到完整的源代码)。

The most essential parts of it: 它最重要的部分:

var mapconfig = { "tilejson": "2.0.0",
    "scheme": "xyz",
    "tiles": ["/proxy.php?z={z}&x={x}&y={y}"],
    "maxzoom": 18,
    "center": [12.93509,50.88306,12]
};
var map = L.mapbox.map('map', mapconfig);

While the error console doesn't show any error messages, it isn't showing any tiles. 错误控制台未显示任何错误消息,但未显示任何切片。 What I do see are the outlines of the map view as well as the zoom-box. 我看到的是地图视图的轮廓以及缩放框。 Also there are no requests to the proxy-script (which is working fine, btw - I've been using Open Layers 3 [see: ol3js.org] before and there the proxy did just fine). 也没有对proxy-script的请求(很好,顺便说一句-我之前一直在使用Open Layers 3 [见:ol3js.org],那里的proxy很好。)

At the moment I move the cursor over the map, the error console gets spilled with messages telling me 在我将光标移到地图上的那一刻,错误控制台出现了提示我的错误消息

Uncaught Error: Invalid LatLng object: (NaN, NaN) 未捕获的错误:无效的LatLng对象:(NaN,NaN)

I got stuck on the same problem for a short while. 我在同一问题上停留了片刻。 Turns out I was just missing a setView() call after initializing the map. 事实证明,初始化地图后我只是错过了setView()调用。

I finally found the answer: 我终于找到了答案:

var mapconfig = { "tilejson": "2.0.0",
"scheme": "xyz",
"tiles": ["/proxy.php?z={z}&x={x}&y={y}"],
"minzoom": 0,
"maxzoom": 18,
"center": [12.93509,50.88306,12]
};
var map = L.mapbox.map('map', mapconfig);

See the difference? 看到不同? Well, here you are: 好吧,这里是:

"minzoom": 0, “最小缩放”:0,

I don't know why this is required, but without this mapbox doesn't work as I want it to ... 我不知道为什么这是必需的,但是没有这个mapbox不能正常工作,因为我想要它...

Obviously there are a few TileJSON properties to be seen as a must have in order to get mapbox.js doing it's work: without center , for example, it's not doing anything either. 显然,为了使mapbox.js能够正常工作, 必须将一些TileJSON属性视为必需的:例如,如果没有center ,那么它也不做任何事情。 But with this missing it does give you an error at least instead of failing silently... 但是缺少此功能确实会给您至少一个错误,而不是无声地失败...

Maybe anybody can shed some light on this? 也许有人可以对此有所了解?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM