javascript - react 传单-图层控制-卫星 View

标签 javascript reactjs dictionary leaflet react-leaflet

我想在我的 react 项目上使用传单 map ,并且我想添加一个图层控件,用户可以在街景和卫星 View 之间切换。 我正在尝试使用谷歌卫星 View ,但它似乎不起作用。

这是我的代码

function App() {
  
  return (
    <div className="App">
      <MapContainer center={[40.44695, -345.23437]} zoom={2}>
        <LayersControl>
          <BaseLayer checked name="OpenStreetMap">
            <TileLayer
              url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
              attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
            />
          </BaseLayer>

          <BaseLayer name="Satellite View">
            <TileLayer
                url='https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}'
                maxZoom= {20}
              />
            
          </BaseLayer>
        </LayersControl>
      </MapContainer>
    </div>
  );
}

export default App;

Satellite View

非常感谢

最佳答案

您用于 Google map 的图 block 网址不存在:

https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}

来自传单文档:

{s} means one of the available subdomains (used sequentially to help with browser parallel requests per domain limitation; subdomain values are specified in options; a, b or c by default, can be omitted), {z} — zoom level, {x} and {y} — tile coordinates. {r} can be used to add "@2x" to the URL to load retina tiles.

您请求的网址使用默认子域 abc,这些子域均已损坏:

看起来正确的子域是 mt1mt2mt3。您可以使用 subdomains 属性指定它们:

<TileLayer
   url='https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}'
   maxZoom= {20}
   subdomains={['mt1','mt2','mt3']}
/>

https://mt1.google.com/vt/lyrs=s&x=1&y=1&z=1

关于javascript - react 传单-图层控制-卫星 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69558520/

相关文章:

javascript - react .js : removing a component

reactjs - 为什么我在 Mapbox GL 中设置了我的数据集要素 ID 却未定义它们?

python - 制作 Counter.most_common 返回字典

javascript - 获取当前时间并与数组进行比较

javascript - Javascript 中的“This”选择器

reactjs - 从所选项目中删除项目时如何捕获 react 选择中的删除事件?

java - 在 map 中组合两个不同的字符串

python - 字典为空时如何避免错误?

javascript - 样式不适用于 Safari/Firefox 中的 LitElement

javascript - 一次向上滚动一个 div(包含一个表格)一行