带有Google卫星图层的Leaflet Map API

use*_*194 42 satellite google-maps-api-3 leaflet

我对Leaflet Map API很感兴趣.

但是,我需要能够使用Google卫星图层.我无法找到有关如何将Google卫星图层添加到Leaflet的示例.我知道我仍然需要加载Google Maps API才能执行此操作(OpenLayers有一个示例).

小智 122

您不需要插件或Google API,可以将其添加为XYZ切片图层.

街道

googleStreets = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
    maxZoom: 20,
    subdomains:['mt0','mt1','mt2','mt3']
});
Run Code Online (Sandbox Code Playgroud)

混合型:

googleHybrid = L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',{
    maxZoom: 20,
    subdomains:['mt0','mt1','mt2','mt3']
});
Run Code Online (Sandbox Code Playgroud)

卫星:

googleSat = L.tileLayer('http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{
    maxZoom: 20,
    subdomains:['mt0','mt1','mt2','mt3']
});
Run Code Online (Sandbox Code Playgroud)

地形

googleTerrain = L.tileLayer('http://{s}.google.com/vt/lyrs=p&x={x}&y={y}&z={z}',{
    maxZoom: 20,
    subdomains:['mt0','mt1','mt2','mt3']
});


Note the difference in the "lyrs" parameter in the URL:
Hybrid: s,h;
Satellite: s;
Streets: m;
Terrain: p;
Run Code Online (Sandbox Code Playgroud)

  • 可能值得一提的是,Google的使用条款禁止通过谷歌地图API以外的任何平铺访问方式. (13认同)
  • 谢谢,这是一个非常好的方法,比添加更多插件要好得多. (2认同)
  • @Andi,https://developers.google.com/maps/terms查看第10.4e节. (2认同)
  • @TimAutin 当前 ToS 中的相关条款似乎是:[3.2.4] (e) 不得与非 Google 地图一起使用。客户不得在包含非 Google 地图的客户应用程序中使用 Google 地图核心服务。例如,客户不得 (i) 在非 Google 地图上显示地点列表,或 (ii) 在同一客户应用程序中显示街景图像和非 Google 地图。 (2认同)
  • 自由主义的解释是,可以使用 XYZ 图块 url,因为它们是公开的(不需要密钥,因此您甚至不需要 Google 帐户) (2认同)

Mou*_*ner 11

有一个第三方插件:演示:http://psha.org.ru/leaflet/bel.html(切换器切换到谷歌地图)来源:http://psha.org.ru/leaflet/Google .js文件


Bru*_*ros 7

用于卫星层的 Google 地图 API 的替代方案:带有 Esri 世界图像图块的 Leaflet.js

<script>

    var map = L.map('map').setView([-41.2858, 174.78682], 14);

    var mapLink = '<a href="http://www.esri.com/">Esri</a>';
    var wholink = 'i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community';

    L.tileLayer(
        'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
        attribution: '&copy; '+mapLink+', '+wholink,
        maxZoom: 18,
        }).addTo(map);

</script>
Run Code Online (Sandbox Code Playgroud)


Ste*_*ini 6

此存储库包含几个瓷砖图层谷歌和其他非常有用的其他插件:https: //github.com/shramov/leaflet-plugins


Eti*_*gné 5

Leaflet 有一个用于发布所有可用插件的官方页面:http : //leafletjs.com/plugins.html

您会在那里找到用于向 Leaflet 添加 Google 图层支持的插件。