Skip to content

Commit

Permalink
Add support for webmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgee committed Nov 1, 2016
1 parent 5d79b34 commit 0ffeae6
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 33 deletions.
10 changes: 7 additions & 3 deletions viewer/js/config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
'viewer/_ConfigMixin', // manage the Configuration
'viewer/_LayoutMixin', // build and manage the Page Layout and User Interface
'viewer/_MapMixin', // build and manage the Map
'viewer/_WidgetsMixin' // build and manage the Widgets
'viewer/_WidgetsMixin', // build and manage the Widgets

'viewer/_WebMapMixin' // for WebMaps
//'config/_customMixin'

], function (
Expand All @@ -50,8 +51,9 @@
_ConfigMixin,
_LayoutMixin,
_MapMixin,
_WidgetsMixin
_WidgetsMixin,

_WebMapMixin
//_MyCustomMixin

) {
Expand All @@ -60,7 +62,9 @@
_ConfigMixin,
_LayoutMixin,
_MapMixin,
_WidgetsMixin
_WidgetsMixin,

_WebMapMixin
]))();
controller.startup();
});
Expand Down
13 changes: 4 additions & 9 deletions viewer/js/config/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ define([
sliderStyle: 'small'
},

//webMapId: 'ef9c7fbda731474d98647bebb4b33c20', // High Cost Mortgage
// webMapOptions: {},

// panes: {
// left: {
// splitter: true
Expand Down Expand Up @@ -278,7 +281,7 @@ define([
srcNodeRef: 'growlerDijit',
options: {}
},
geocoder: {
search: {
include: true,
type: 'domNode',
path: 'esri/dijit/Search',
Expand All @@ -301,14 +304,6 @@ define([
position: 3,
options: 'config/identify'
},
basemaps: {

This comment has been minimized.

Copy link
@green3g

green3g Nov 17, 2016

Member

Just wondering, why did we get rid of the basemap widget?

This comment has been minimized.

Copy link
@tmcgee

tmcgee Nov 17, 2016

Author Member

@roemhildtg That is not intentional. Original basemap should remain as a widget included by default.

That widget was removed only for testing the automatic addition of a Basemap Gallery widget from the webmap. But only if there wasn't a basemap widget or basemap gallery widget already included in the app determined by widget id.

This comment has been minimized.

Copy link
@green3g

green3g Nov 17, 2016

Member

Ah, This is so cool by the way, it works really well in the little test I did!

This comment has been minimized.

Copy link
@tmcgee

tmcgee Nov 17, 2016

Author Member

Great! I added this functionality in as complete form as I could with that exact intent to get more feedback, adoption and contribution. 😄

include: true,
id: 'basemaps',
type: 'domNode',
path: 'gis/dijit/Basemaps',
srcNodeRef: 'basemapsDijit',
options: 'config/basemaps'
},
mapInfo: {
include: false,
id: 'mapInfo',
Expand Down
20 changes: 20 additions & 0 deletions viewer/js/viewer/_ControllerBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ define([
// add growler here?
return;
}
},

mixinDeep: function (dest, source) {
//Recursively mix the properties of two objects
var empty = {};
for (var name in source) {
if (!(name in dest) || (dest[name] !== source[name] && (!(name in empty) || empty[name] !== source[name]))) {
try {
if (source[name].constructor === Object) {
dest[name] = this.mixinDeep(dest[name], source[name]);
} else {
dest[name] = source[name];
}
} catch (e) {
// Property in destination object not set. Create it and set its value.
dest[name] = source[name];
}
}
}
return dest;
}
});
});
67 changes: 46 additions & 21 deletions viewer/js/viewer/_MapMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,49 @@ define([
var returnDeferred = new Deferred();
var returnWarnings = [];

this._createMap();
this._createMap(returnWarnings).then(
lang.hitch(this, '_createMapResult', returnDeferred, returnWarnings)
);
return returnDeferred;
},

_createMap: function (returnWarnings) {
var mapDeferred = new Deferred(),
container = dom.byId(this.config.layout.map) || 'mapCenter';

if (this.config.mapOptions.basemap) {
this.map.on('load', lang.hitch(this, '_initLayers', returnWarnings));
if (this.config.webMapId) {
if (this._initWebMap) {
mapDeferred = this._initWebMap(this.config.webMapId, container, this.config.webMapOptions);
} else {
returnWarnings.push('The "_WebMapMixin" Controller Mixin is required to use a webmap');
mapDeferred.resolve(returnWarnings);
}
} else {
this._initLayers(returnWarnings);
this.map = new Map(container, this.config.mapOptions);
mapDeferred.resolve(returnWarnings);
}
return mapDeferred;
},

_createMapResult: function (returnDeferred, returnWarnings) {
if (this.map) {
if (!this.config.webMapId && this.config.mapOptions && this.config.mapOptions.basemap) {
this.map.on('load', lang.hitch(this, '_initLayers', returnWarnings));
} else {
this._initLayers(returnWarnings);
}

if (this.config.operationalLayers && this.config.operationalLayers.length > 0) {
on.once(this.map, 'layers-add-result', lang.hitch(this, '_onLayersAddResult', returnDeferred, returnWarnings));
if (this.config.operationalLayers && this.config.operationalLayers.length > 0) {
on.once(this.map, 'layers-add-result', lang.hitch(this, '_onLayersAddResult', returnDeferred, returnWarnings));
} else {
returnDeferred.resolve(returnWarnings);
}
} else {
returnDeferred.resolve(returnWarnings);
}
return returnDeferred;
},

_createMap: function () {
var container = dom.byId(this.config.layout.map) || 'mapCenter';
this.map = new Map(container, this.config.mapOptions);
},

_onLayersAddResult: function (returnDeferred, returnWarnings, lyrsResult) {
array.forEach(lyrsResult.layers, function (addedLayer) {
if (addedLayer.success !== true) {
Expand Down Expand Up @@ -171,18 +193,21 @@ define([
});
}

this.map.on('resize', function (evt) {
var pnt = evt.target.extent.getCenter();
setTimeout(function () {
evt.target.centerAt(pnt);
}, 100);
});
if (this.map) {
this.map.on('resize', function (evt) {
var pnt = evt.target.extent.getCenter();
setTimeout(function () {
evt.target.centerAt(pnt);
}, 100);
});

// in _LayoutsMixin
this.createPanes();
// in _LayoutsMixin
this.createPanes();

// in _WidgetsMixin
this.initWidgets();
}

// in _WidgetsMixin
this.initWidgets();
},

initMapError: function (err) {
Expand Down
Loading

0 comments on commit 0ffeae6

Please sign in to comment.