Openlayers v4.0.1 support Google Maps Javascript API?

后端 未结 2 660
南笙
南笙 2021-02-06 17:31

I wonder know if the last version of Openlayers (v4.0.1) supports Google Maps as a Tile Layer. I can\'t find any documention about this. If Openlayers doesn\'t support Google Ma

相关标签:
2条回答
  • 2021-02-06 17:57

    For the Google's satellite data you can go with TileImage source, specifying pattern url's:

    var map = new ol.Map({
            layers: [
              new ol.layer.Tile({
                source: new ol.source.TileImage({url: 'http://khm0.googleapis.com/kh?v=717&hl=pl&&x={x}&y={y}&z={z}'})
              })
            ],
            target: 'map',
            view: new ol.View({
              center: ol.proj.fromLonLat([19.2, 52]),
              zoom: 6
            })
    		});

    EDIT: For the Google's plain map data you can go with TileImage source, specifying pattern url's for the parts of pb argument:

    var map = new ol.Map({
            layers: [
              new ol.layer.Tile({
                source: new ol.source.TileImage({url: 'http://maps.google.com/maps/vt?pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i375060738!3m9!2spl!3sUS!5e18!12m1!1e47!12m3!1e37!2m1!1ssmartmaps!4e0'})
              })
            ],
            target: 'map',
            view: new ol.View({
              center: ol.proj.fromLonLat([19.2, 52]),
              zoom: 6
            })
    		});

    0 讨论(0)
  • 2021-02-06 18:21

    OpenLayers has a written consent for using the api, which they used for OL2 and OL3. The support for it was stopped because of recurring issues with said api.

    We are not allowed to use the tiles directly, the answer is not legal.

    However, you may use Google's Map api and write your own OL source implementation with it or use an existing extension like ol3-google-maps

    More information can be found here: https://github.com/openlayers/openlayers/issues/2205

    0 讨论(0)
提交回复
热议问题