我是 javascript 的新手,正在尝试弄清楚一些代码的语法。曾尝试用谷歌搜索类似问题,但似乎找不到任何相关问题。也许我没有使用正确的关键字进行搜索:(
我试图从以下位置理解代码:
https://github.com/klokantech/mapbox-gl-js-offline-example/blob/gh-pages/index.html
这是代码的摘录:
<script>
// mapboxgl.accessToken = 'pk.your-own-code-here-for-online-maps';
mapboxgl.accessToken = 'NOT-REQUIRED-WITH-YOUR-VECTOR-TILES-DATA';
var style = {
"version": 8,
"sources": {
"countries": {
"type": "vector",
// "url": "mapbox://map-id"
// "url": "http://tileserver.com/layer.json",
"tiles": [location.origin+location.pathname+"countries/{z}/{x}/{y}.pbf"],
"maxzoom": 6
}
},
我试图理解的代码行就是这个问题的标题中所描述的。
有人能给我解释一下吗?
非常感谢。
最佳答案
这些只是(子)字符串,稍后会被相应的值替换。它们本身没有任何意义或功能。
Mapbox Style Specification导致 TileJSON specification其中说:
[..] {z}, {x} and {y}, if present, are replaced with the corresponding integers.
然后图书馆可能会按照以下方式做一些事情:
let url = "{x}/{y}/{z}".replace( "{x}", 1337 ).replace("{y}", -99).replace("{z}", 1.333)
您当然会在现实世界的设置中使用变量而不是数字文字。
关于javascript - {z}/{x}/{y} 在 "tiles": [location. origin+location.pathname +"countries/{z}/{x}/{y}.pbf"中是什么意思],,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55692220/