Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Google basemaps in openlayers-3?

In openlayers-2, we can add google basemaps(satellite,physical,hybrid,etc.). I need to add google basemaps in openlayer-3. How can I add google basemaps???

CODE in openlayers-3

map = new ol.Map({
      layers: [
         new ol.layer.Group({
            layers: [
               new ol.layer.Tile({
                  source: null,
                  visible:false
                  }),
                  new ol.layer.Tile({
                  source: new ol.source.MapQuest({layer: 'sat'})
                  }),
                  new ol.layer.Tile({
                  source: new ol.source.OSM(),
                  visible:false
                    })
                 ]})
                ],
                target: 'map',
                view: new ol.View({
                    center:[28.566667, 4.01666699999998],
                    zoom:7
                    }),
                controls: ol.control.defaults({

                       attribution:false

                }).extend([
                    scaleLineControl
                ]),
            });

        lyr=new ol.layer.Tile({  source: new ol.source.TileWMS({
            url: 'http://localhost:8080/geoserver/wms',
            params: {'LAYERS': 'test:test', 'TILED': true},
            serverType: 'geoserver'
            })
        });
map.addLayer(lyr);

I need to google basemaps instead of osm and mapquest.

like image 551
shrestha Avatar asked Feb 26 '15 09:02

shrestha


2 Answers

Google Maps is officially not supported by ol3, see https://gist.github.com/elemoine/e82c7dd4b1d0ef45a9a4

like image 163
tsauerwein Avatar answered Sep 23 '22 08:09

tsauerwein


it's totally possible to do this, even though it's not supported.

here's an example of integrating google maps with openlayers 3.

be aware: the level of detail available in Google Maps website doesn't correspond to the level of detail available through their Google Maps API. they seem to be using some extra google earth details in their customer facing maps.

like image 23
lazaruslarue Avatar answered Sep 25 '22 08:09

lazaruslarue