Openlayers v4.0.1 support Google Maps Javascript API?

后端 未结 2 661
南笙
南笙 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
            })
    		});

提交回复
热议问题