views:

55

answers:

3

Hi!

Is there any way to display a Google Map (embedded via the Javascript API) in grayscale without losing any other functionality?

Thanks,

DLiKS

A: 

Apart from writing the good people at Google and asking them to create grey-scale versions of all of their image tiles and an optional API parameter, no.

Stan Rogers
A: 

IE has the filter: gray directive.

It renders any HTML element in grayscale. JSFiddle here.

You may be able to apply this to the map's parent DIV. It may turn the map it contains in to a grayscale represtenation. I can't say whether this will work without side effects - you'd have to try. But it's well possible.

IE only, though, but supported since Version 4.

Grayscale Filter docs at MSDN

Other than that, I think there is a Flash API for Maps, isn't there? It might be easier to achieve there.

Pekka
Having the map in grayscale for IE only wouldn't be particularly helpful seeing as the rest of the application is being coded using HTML5 and Canvas - thanks for the answer though!
DLiKS
@DliKS yeah. I don't think there is a cross-browser way to do this, the `filter` stuff never caught on in other browsers. Sadly! ... It may be possible in Flash, I don't know.
Pekka
+5  A: 

Yes, in V3 of the api they have introduced StyledMaps.

They've even provided a tool for you to generate the code for the styles you like. Slide the "Saturation" all the way down and you've got grayscale going on!

The following example displays a grayscale map of Brooklyn:

var map;
var brooklyn = new google.maps.LatLng(40.6743890, -73.9455);

var stylez = [
    {
      featureType: "all",
      elementType: "all",
      stylers: [
        { saturation: -100 } // <-- THIS
      ]
    }
];

var mapOptions = {
    zoom: 11,
    center: brooklyn,
    mapTypeControlOptions: {
         mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'tehgrayz']
    }
};

map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

var mapType = new google.maps.StyledMapType(stylez, { name:"Grayscale" });    
map.mapTypes.set('tehgrayz', mapType);
map.setMapTypeId('tehgrayz');
Roatin Marth
Very nice! ` ` ` `
Pekka