From 1c9c6f9774fccd88d7bbb432d054d5fcd4ec7e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Dub=C3=A9?= Date: Fri, 23 Oct 2015 15:03:20 -0400 Subject: [PATCH] Add themed gmap support, i.e. styles for Google Maps --- externs/olgmx.js | 11 ++++++++++- src/herald/layersherald.js | 8 ++++++++ src/layer/googlelayer.js | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/externs/olgmx.js b/externs/olgmx.js index 6d6f9d3..f2fa976 100644 --- a/externs/olgmx.js +++ b/externs/olgmx.js @@ -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.|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.|undefined} + * @api + */ +olgmx.layer.GoogleOptions.prototype.styles; diff --git a/src/herald/layersherald.js b/src/herald/layersherald.js index cbeb4b5..fe2ab20 100644 --- a/src/herald/layersherald.js +++ b/src/herald/layersherald.js @@ -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 { diff --git a/src/layer/googlelayer.js b/src/layer/googlelayer.js index b87e920..28513ed 100644 --- a/src/layer/googlelayer.js +++ b/src/layer/googlelayer.js @@ -25,6 +25,12 @@ olgm.layer.Google = function(opt_options) { this.mapTypeId_ = options.mapTypeId !== undefined ? options.mapTypeId : google.maps.MapTypeId.ROADMAP; + /** + * @type {?Array.} + * @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.} + */ +olgm.layer.Google.prototype.getStyles = function() { + return this.styles_; +};