Skip to content

Commit

Permalink
Merge pull request #626 from cmv/feature/add-support-for-webmaps
Browse files Browse the repository at this point in the history
Add support for webmaps
  • Loading branch information
DavidSpriggs authored Nov 2, 2016
2 parents 209d264 + a24fc95 commit a91290c
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: {
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 a91290c

Please sign in to comment.