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 Maps, someone could tell me if there is any way to do this.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
})
});
回答2:
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