Skip to content

Commit

Permalink
Update the basemap via publish
Browse files Browse the repository at this point in the history
We can change the basemap with events

dojo.publish('basemaps/updateBasemap',['gray'])
  • Loading branch information
AlexThomasEOG committed Mar 3, 2016
1 parent 9c93231 commit cd1e2b9
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions viewer/js/gis/dijit/Basemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ define([
'dijit/DropDownMenu',
'dijit/MenuItem',
'dojo/_base/array',
'dojo/topic',
'dojox/lang/functional',
'dojo/text!./Basemaps/templates/Basemaps.html',
'esri/dijit/BasemapGallery',
'dojo/i18n!./Basemaps/nls/resource',

'dijit/form/DropDownButton',
'xstyle/css!./Basemaps/css/Basemaps.css'
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, lang, DropDownMenu, MenuItem, array, functional, template, BasemapGallery, i18n) {
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, lang, DropDownMenu, MenuItem, array, topic, functional, template, BasemapGallery, i18n) {

// main basemap widget
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
Expand Down Expand Up @@ -72,31 +73,32 @@ define([
id: basemap,
label: this.basemaps[basemap].title,
iconClass: (basemap === this.mapStartBasemap) ? 'selectedIcon' : 'emptyIcon',
onClick: lang.hitch(this, function () {
if (basemap !== this.currentBasemap) {
this.currentBasemap = basemap;
if (this.mode === 'custom') {
this.gallery.select(basemap);
} else {
this.map.setBasemap(basemap);
}
var ch = this.menu.getChildren();
array.forEach(ch, function (c) {
if (c.id === basemap) {
c.set('iconClass', 'selectedIcon');
} else {
c.set('iconClass', 'emptyIcon');
}
});
}
})
onClick: lang.hitch(this, 'updateBasemap', basemap)
});
this.menu.addChild(menuItem);
}
}, this);

topic.subscribe('basemaps/updateBasemap', lang.hitch(this, 'updateBasemap'));
this.dropDownButton.set('dropDown', this.menu);
},
updateBasemap: function (basemap) {
if (basemap !== this.currentBasemap && (array.indexOf(this.basemapsToShow, basemap) !== -1)) {
this.currentBasemap = basemap;
if (this.mode === 'custom') {
this.gallery.select(basemap);
} else {
this.map.setBasemap(basemap);
}
var ch = this.menu.getChildren();
array.forEach(ch, function (c) {
if (c.id === basemap) {
c.set('iconClass', 'selectedIcon');
} else {
c.set('iconClass', 'emptyIcon');
}
});
}
},
startup: function () {
this.inherited(arguments);
if (this.mode === 'custom') {
Expand Down

0 comments on commit cd1e2b9

Please sign in to comment.