Does the BaseMap Gallery support Google Maps as a Basemap?

3217
9
08-08-2011 09:17 PM
StephenLead
Regular Contributor III
A while ago, Derek Swingley showed how to use Google Maps as a background layer:

How about moving to the full ArcGIS API for JavaScript and using this sample to get Google Maps in your JS app:  http://gmaps-utility-gis.googlecode.com/svn/tags/gmapslayer/1.0/docs/examples.html


<script type="text/javascript" src="http://gmaps-utility-gis.googlecode.com/svn/tags/gmapslayer/1.0/src/gmapslayer_compiled.js" ></script>
var gMapLayer = new gmaps.GoogleMapsLayer({visible:false, id:'googlemaps'});
map.addLayer(gMapLayer);


This works really well when it's hard-coded (as long as your application is located on an externally-facing server - ie it won't work while testing on your hard drive).

Can this be integrated with the BaseMap Gallery? The BaseMap Gallery reference shows how to add a new basemap:

var layer = new esri.dijit.BasemapLayer({
  url:"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyBasemap/MapServer"
});
var basemap = new esri.dijit.Basemap({
  layers:[layer],
  title:"Public Safety",
  thumbnailUrl:"images/safetyThumb.png"
});
basemapGallery.add(basemap);


How can the Google Maps layer be used as the Basemap (which is expecting a BasemapLayer object)?

Thanks,
Steve
0 Kudos
9 Replies
DurrantWilliams
New Contributor
When you say that my google maps wouldn't work off my hard drive, does that also mean that the bing maps won't work with the map gallery?  Cause they aren't, and I'm trying to figure out why.  All the other background imagery works, except any bing backgrounds.  Google images would be ideal.

I've tried it from a folder on my hard drive, just opening the index.html
and
I've tried it from withing WebMatrix.  no go.
0 Kudos
StephenLead
Regular Contributor III
Hi there,

I'm not an expert on this, but I've had success using the Bing maps samples:

- Add Bing Maps Layer
- Basemap Gallery Button

I didn't get Google Maps to work as a backdrop using this method, yet.

Steve
0 Kudos
KellyHutchins
Esri Frequent Contributor
In order for the Bing Maps to work you have to provide a valid bing maps key when the basemap gallery is constructed.

        basemapGallery = new esri.dijit.BasemapGallery({

          showArcGISBasemaps: false,

          basemaps: basemaps,

          bingMapsKey: bingKey,

          map: map

        });




When you say that my google maps wouldn't work off my hard drive, does that also mean that the bing maps won't work with the map gallery?  Cause they aren't, and I'm trying to figure out why.  All the other background imagery works, except any bing backgrounds.  Google images would be ideal.

I've tried it from a folder on my hard drive, just opening the index.html
and
I've tried it from withing WebMatrix.  no go.
0 Kudos
NianweiLiu
Occasional Contributor II
Steven,

Try this example:

http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/1.07/examples/gmapsgallery.html

The google maps are at end of the available list.
0 Kudos
RatikantaLenka
New Contributor
0 Kudos
StephenLead
Regular Contributor III
Thanks Nianwei, looks good.
0 Kudos
Shingo-Ikeda
New Contributor III
Hi Nianwei,

Thanks for your google map api.
Your code (GoogleMapsLayer.js.) was working fine in all browsers (FF, Chrome, IE), but I noticed streetmap mode in the Chrome stopped working after I upgraded esri JavaScript API from 3.5 to 3.7. When pegman is moved on the map and streetview is activated, my dynamic layers are still visible along with other map components as zoom buttons and mouse control is still focused on map. This prohibits navigation on streetview.

I am not sure if this is only my instance or anybody else is experiencing the same.

Thanks,
Shingo
Shingo Ikeda
Geospatial Data Scientist/Developer - Geographical Information Platform
Global Power Generation - Digital Satellite USA and Canada
0 Kudos
JeffPace
MVP Alum
onStreetViewVisibilityChange: function(turnOff) {
     //   alert('herechange');
        if(dojo.isChrome){
        if(turnOff){
            if(dojo.byId('map_Google Road')){
                  dojo.style(dojo.byId('map_Google Road'),'zIndex','15');
                  if(dojo.byId('gmaps_controls_')){
                  dojo.style(dojo.byId('gmaps_controls_'),'display','none');
                  }
                  }
         }else{
             if(dojo.byId('gmaps_controls_')){
                  dojo.style(dojo.byId('gmaps_controls_'),'zIndex','15');
                  dojo.style(dojo.byId('gmaps_controls_'),'display','block');

                  }
                   if(dojo.byId('map_Google Road')){
                     dojo.style(dojo.byId('map_Google Road'),'zIndex','0');
                    }
         }
         }
    },
0 Kudos
Rhys-Donoghue
New Contributor III

Hi All, it is quite easy to add Google's basemap to ArcMap, ArcGIS Online, Portal for ArcGIS, or an app using Esri's JavaScript API (including Web AppBuilder).  It only takes a couple of lines of code.  The problem is Google do not allow their basemap to be used unless you are using Google Maps' API for your application, or unless you get a letter from Google saying it is okay (their Terms and Conditions actually say this).  I tried to get the letter from Google because I was using their imagery basemap for a Leaflet application I developed.  They said no because our company was too small.  If someone can point me to Google's Terms and Conditions or provide confirmation from Google that they allow their basemap to be used outside of a non-Google Maps API application, then I will be happy to put the details here to show you how to do it.  It is very quick and only takes a couple of minutes.  Note that when I first asked Google for permission to consume their tiled service directly outside of their API, they said it was technically not possible.  I had to have a debate with them and prove that I had already done it before they believed me, and then they told me to stop using their tiled service immediately, unless I used the Google Maps API.  If you really want to use Google's basemap, and you can't consume their service directly because of breaking their T&Cs, you can wrap their basemap in a Google Maps API app, and then put that inside your own app.  This is a dirty hack, which is what we ended up doing.

0 Kudos