From 023f5f4e077709837a077026a396c6b4277bea0a Mon Sep 17 00:00:00 2001 From: Tim McGee Date: Tue, 8 Sep 2015 21:56:51 -0700 Subject: [PATCH] Allow `mapStartBasemap` & `basemapsToShow` as optional in basemap widget. Also clean up some unused properties and code. --- viewer/js/config/basemaps.js | 18 ++++++++++++----- viewer/js/gis/dijit/Basemaps.js | 35 ++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/viewer/js/config/basemaps.js b/viewer/js/config/basemaps.js index 49a91a5cf..7cafcaf89 100644 --- a/viewer/js/config/basemaps.js +++ b/viewer/js/config/basemaps.js @@ -6,11 +6,19 @@ define([ return { map: true, // needs a refrence to the map mode: 'agol', //must be either 'agol' or 'custom' - title: 'Basemaps', // tilte for widget - mapStartBasemap: 'streets', // must match one of the basemap keys below - //basemaps to show in menu. define in basemaps object below and reference by name here - // TODO Is this array necessary when the same keys are explicitly included/excluded below? - basemapsToShow: ['streets', 'satellite', 'hybrid', 'topo', 'lightGray', 'gray', 'national-geographic', 'osm', 'oceans'], + title: 'Basemaps', // title for widget + + /* optional starting basemap + / otherwise uses the basemap from the map + / must match one of the keys in basemaps object below + */ + //mapStartBasemap: 'streets', + + /* optional array of basemaps to show in menu. + / otherwise uses keys in basemaps object below + / values in array must match keys in basemaps object + */ + //basemapsToShow: ['streets', 'satellite', 'hybrid', 'topo', 'lightGray', 'gray', 'national-geographic', 'osm', 'oceans'], // define all valid custom basemaps here. Object of Basemap objects. For custom basemaps, the key name and basemap id must match. basemaps: { // agol basemaps diff --git a/viewer/js/gis/dijit/Basemaps.js b/viewer/js/gis/dijit/Basemaps.js index 12cfc45ad..9ee9335f5 100644 --- a/viewer/js/gis/dijit/Basemaps.js +++ b/viewer/js/gis/dijit/Basemaps.js @@ -23,14 +23,31 @@ define([ i18n: i18n, mode: 'agol', title: i18n.title, - //baseClass: 'gis_Basemaps_Dijit', - //buttonClass: 'gis_Basemaps_Button', - //menuClass: 'gis_Basemaps_Menu', - mapStartBasemap: 'streets', - basemapsToShow: ['streets', 'satellite', 'hybrid', 'topo', 'gray', 'oceans', 'national-geographic', 'osm'], - validBasemaps: [], + + mapStartBasemap: null, + basemapsToShow: null, + postCreate: function () { this.inherited(arguments); + + // if the basemaps to show is not explicitly set, + // get them from the basemap object + if (!this.basemapsToShow) { + this.basemapsToShow = Object.keys(this.basemaps); + } + + // if the starting basemap is not explicitly set, + // get it from the map + if (!this.mapStartBasemap) { + this.mapStartBasemap = this.map.getBasemap(); + } + + // check to make sure the starting basemap + // is found in the basemaps object + if (!this.basemaps.hasOwnProperty(this.mapStartBasemap)) { + this.mapStartBasemap = this.basemapsToShow[0]; + } + this.currentBasemap = this.mapStartBasemap || null; if (this.mode === 'custom') { @@ -41,15 +58,11 @@ define([ return map.basemap; }) }); - // if (this.map.getBasemap() !== this.mapStartBasemap) { //based off the title of custom basemaps in viewer.js config - // this.gallery.select(this.mapStartBasemap); - // } this.gallery.startup(); } this.menu = new DropDownMenu({ - style: 'display: none;' //, - //baseClass: this.menuClass + style: 'display: none;' }); array.forEach(this.basemapsToShow, function (basemap) {