react-leaflet - 如何将我的自定义地图图块的返回 url 传递给 react-leaflet?
问题描述
// 传单:
L.TileLayer.Custom = L.TileLayer.extend({
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
getTileUrl({x, y, z}) {
if (y < 0) {
y = 0;
}
const _x = 'C' + padStart(correctEdges(z, x).toString(16), 8, '0');
const _y = 'R' + padStart(y.toString(16), 8, '0');
const _z = 'L' + padStart(z.toString(10), 2, '0');
return `${url()}${this.options.path}/${_z}/${_y}/${_x}.${this.options.imgType}`;
}
});
我正在传单中生成一个磁贴 url。如何将返回的自定义地图图块的 url 传递给 react-leaflet TileLayer 元素?我不会使用http://{s}.tile.osm.org/{z}/{x}/{y}.png.
相反,字符串是动态更新的
${url()}${this.options.path}/${_z}/${_y}/${_x}.${this.options.imgType}
url = <string>
// 反应传单:
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"
/>
解决方案
只需保存url
in 状态和何时
<TileLayer
..
url={this.state.url}
/>
这是你要求的吗?
推荐阅读
- javascript - 为什么在 flyTo 动画后 MouseWheel zoomOut 被阻止?
- java - 如何将 Sig 从 Alloy 传递到 Java 并从 Java 执行合金模型
- php - 致命错误:require_once() [function.require]:无法打开所需的“languages/Array.php”(include_path='.:/usr/share/pear/')
- python - 如何将 Tfidf_vectorizer 应用于整个 pandas 列?
- java - 从网页读取数据并在excel中写入
- react-native - 将焦点转移到下一个 TextInput [error = this2.refs.LastName.focus 不是函数]
- javascript - “TypeError: fsevents is not a constructor”——已经尝试了一堆解决方案
- c++ - 如何在不使用 tensorflow 的情况下构建 tf_tensor 并将其提供给我的 docker 服务器
- ios - 通过描述文件管理器作为 MDM 更新 iOS
- c++ - 打包结构和不打包没有代码重复