Add themed gmap support, i.e. styles for Google Maps

This commit is contained in:
Alexandre Dubé 2015-10-23 15:03:20 -04:00
parent 4fb95e65db
commit 1c9c6f9774
3 changed files with 32 additions and 1 deletions

View File

@ -31,7 +31,8 @@ olgmx.layer = {};
/**
* @typedef {{
* mapTypeId: (google.maps.MapTypeId.<(number|string)>|string|undefined)
* mapTypeId: (google.maps.MapTypeId.<(number|string)>|string|undefined),
* styles: (Array.<google.maps.MapTypeStyle>|undefined)
* }}
* @api
*/
@ -45,3 +46,11 @@ olgmx.layer.GoogleOptions;
* @api
*/
olgmx.layer.GoogleOptions.prototype.mapTypeId;
/**
* The Google Maps styles to apply to the map
* @type {Array.<google.maps.MapTypeStyle>|undefined}
* @api
*/
olgmx.layer.GoogleOptions.prototype.styles;

View File

@ -410,6 +410,14 @@ olgm.herald.Layers.prototype.toggleGoogleMaps_ = function() {
if (found) {
// set mapTypeId
this.gmap.setMapTypeId(found.getMapTypeId());
// set styles
var styles = found.getStyles();
if (styles) {
this.gmap.setOptions({'styles': styles});
} else {
this.gmap.setOptions({'styles': null});
}
// activate
this.activateGoogleMaps_();
} else {

View File

@ -25,6 +25,12 @@ olgm.layer.Google = function(opt_options) {
this.mapTypeId_ = options.mapTypeId !== undefined ? options.mapTypeId :
google.maps.MapTypeId.ROADMAP;
/**
* @type {?Array.<google.maps.MapTypeStyle>}
* @private
*/
this.styles_ = options.styles ? options.styles : null;
};
goog.inherits(olgm.layer.Google, ol.layer.Group);
@ -35,3 +41,11 @@ goog.inherits(olgm.layer.Google, ol.layer.Group);
olgm.layer.Google.prototype.getMapTypeId = function() {
return this.mapTypeId_;
};
/**
* @return {?Array.<google.maps.MapTypeStyle>}
*/
olgm.layer.Google.prototype.getStyles = function() {
return this.styles_;
};