开发者

Google Maps in Grayscale

Is there any way to display a Google Map (embedded via the Javascript API) in grayscale with开发者_开发百科out losing any other functionality?


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');


There's a little shorter way (comparing to @Roatin Marth's best answer) to make your Google map grayscale with Google Maps JavaScript API v3 by directly including styles you generated with Google Maps API Styled Map Wizard into google.maps.MapOptions object:

var container = document.getElementById('map_canvas');
var mapOptions = {
  zoom: 11,
  center: new google.maps.LatLng(40.6743890, -73.9455),
  styles: [{
    stylers: [{
      saturation: -100
    }]
  }]
};

var map = new google.maps.Map(container, mapOptions);

You get the array set under styles property in mapOptions variable by clicking onto "Show JSON" button inside Map Style panel when finishing your styles customisation using Google Maps API Styled Map Wizard.

Google Maps in Grayscale


Just use CSS3 grayscale() filter effect for the Google maps iframe element! It works because the js code prints images.

iframe { 
  -webkit-filter: grayscale(100%);
  -moz-filter: grayscale(100%);
  -ms-filter: grayscale(100%);
  -o-filter: grayscale(100%);
  filter: grayscale(100%);
  filter: url(grayscale.svg); /* Firefox 4+ */
  filter: gray; /* IE 6-9 */
}

Try also to target only the background images by applying this to the very first div element under the div.gm-style (or any other wrapper). I don't know if Google changes the dom structure often but at the moment speaking (25 Nov 2014) this works fine.

iframe .gm-style > div:first-child {
  // Same code here
}


Use the CSS filter property to convert the google map to black and white. 100% is completely black and white

selector {
  -webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
  filter: grayscale(100%);
}


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.


Check out this:

http://snazzymaps.com/style/15/subtle-grayscale

Works like a charm :)


Yes, there is a third party API for Google maps that provides gray-scale (snazzymaps).

Its very simple. You can use this website to get the different color scheme for google maps.

http://snazzymaps.com


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜