javascript - {z}/{x}/{y} 在 "tiles": [location. origin+location.pathname +"countries/{z}/{x}/{y}.pbf"中是什么意思],

标签 javascript

我是 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/

相关文章:

javascript - 无法解决 redux reducer 函数中的 axios promise

javascript - 如何在字符串中的值之前删除字符串中的动态数据?/将 Lodash 的 _.trimStart 与动态数据一起使用?

javascript - 将文本添加到动态创建的 DOM 元素

javascript - Lodash 'get' 在箭头函数(React)中使用时不起作用

javascript - 仅通过正确的键系列执行功能

javascript - 检查 = "checked"与检查 = 真

javascript math.round 和 math.floor 在 IE 和 Opera 中工作正常,但在 Chrome、Safari 或 Firefox 中不行。得到 NaN

JavaScript 减少函数问题

javascript - 找不到 Angular 导出

javascript - 有人可以向我解释为什么这个按钮不起作用吗?