Leaflet Map API with Google Satellite Layer

前端 未结 6 1987
刺人心
刺人心 2020-12-02 04:53

I\'m very interested in the Leaflet Map API.

However, I need to be able to use the Google Satellite Layer. I have not been able to find an example on how to add a Go

6条回答
  •  失恋的感觉
    2020-12-02 06:00

    You don't need a plugin or the Google API, you can add it as a XYZ tile layer.

    Streets

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

    Hybrid:

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

    Satellite:

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

    Terrain

    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;
    

提交回复
热议问题