Skip to content

Commit

Permalink
Merge pull request #545 from cmv/feature/support-user-defined-layer-t…
Browse files Browse the repository at this point in the history
…ypes-and-wdiget-types

Add support for user-defined layer types and widget types
  • Loading branch information
DavidSpriggs committed Apr 20, 2016
2 parents fc53a9f + 3bba918 commit 0bdc6c0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
24 changes: 24 additions & 0 deletions viewer/js/config/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ define([
zoom: 5,
sliderStyle: 'small'
},

// panes: {
// left: {
// splitter: true
Expand Down Expand Up @@ -81,6 +82,29 @@ define([
// },
// collapseButtonsPane: 'center', //center or outer

// custom titles
/*
titles: {
header: 'My App',
subHeader: 'My GIS App is the best!',
pageTitle: 'My App'
},
*/

// user-defined layer types
/*
layerTypes: {
myCustomLayer: 'widgets/MyCustomLayer'
},
*/

// user-defined widget types
/*
widgetTypes: [
'myWidgetType'
],
*/

// operationalLayers: Array of Layers to load on top of the basemap: valid 'type' options: 'dynamic', 'tiled', 'feature'.
// The 'options' object is passed as the layers options for constructor. Title will be used in the legend only. id's must be unique and have no spaces.
// 3 'mode' options: MODE_SNAPSHOT = 0, MODE_ONDEMAND = 1, MODE_SELECTION = 2
Expand Down
2 changes: 2 additions & 0 deletions viewer/js/gis/dijit/LayerControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ define([
});
return;
}
// add any user-defined controls - possibly for user-defined layers
this._controls = lang.mixin(this._controls, options.controls || {});
},
postCreate: function () {
this.inherited(arguments);
Expand Down
46 changes: 24 additions & 22 deletions viewer/js/viewer/_MapMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,42 +60,44 @@ define([
_initLayers: function (returnWarnings) {
this.layers = [];
var layerTypes = {
csv: 'CSV',
dataadapter: 'DataAdapterFeature', //untested
dynamic: 'ArcGISDynamicMapService',
feature: 'Feature',
georss: 'GeoRSS',
image: 'ArcGISImageService',
imagevector: 'ArcGISImageServiceVector',
kml: 'KML',
label: 'Label', //untested
mapimage: 'MapImage', //untested
osm: 'OpenStreetMap',
raster: 'Raster',
stream: 'Stream',
tiled: 'ArcGISTiledMapService',
vectortile: 'VectorTile',
webtiled: 'WebTiled',
wfs: 'WFS',
wms: 'WMS',
wmts: 'WMTS' //untested
csv: 'esri/layers/CSVLayer',
dataadapter: 'esri/layers/DataAdapterFeatureLayer', //untested
dynamic: 'esri/layers/ArcGISDynamicMapServiceLayer',
feature: 'esri/layers/FeatureLayer',
georss: 'esri/layers/GeoRSSLayer',
image: 'esri/layers/ArcGISImageServiceLayer',
imagevector: 'esri/layers/ArcGISImageServiceVectorLayer',
kml: 'esri/layers/KMLLayer',
label: 'esri/layers/LabelLayer', //untested
mapimage: 'esri/layers/MapImageLayer', //untested
osm: 'esri/layers/OpenStreetMapLayer',
raster: 'esri/layers/RasterLayer',
stream: 'esri/layers/StreamLayer',
tiled: 'esri/layers/ArcGISTiledMapServiceLayer',
vectortile: 'esri/layers/VectorTileLayer',
webtiled: 'esri/layers/WebTiledLayer',
wfs: 'esri/layers/WFSLayer',
wms: 'esri/layers/WMSLayer',
wmts: 'esri/layers/WMTSLayer' //untested
};
// add any user-defined layer types such as https://github.com/Esri/geojson-layer-js
layerTypes = lang.mixin(layerTypes, this.config.layerTypes || {});
// loading all the required modules first ensures the layer order is maintained
var modules = [];
array.forEach(this.config.operationalLayers, function (layer) {
var type = layerTypes[layer.type];
if (type) {
modules.push('esri/layers/' + type + 'Layer');
modules.push(type);
} else {
returnWarnings.push('Layer type "' + layer.type + '"" isnot supported: ');
returnWarnings.push('Layer type "' + layer.type + '" is not supported: ');
}
}, this);

require(modules, lang.hitch(this, function () {
array.forEach(this.config.operationalLayers, function (layer) {
var type = layerTypes[layer.type];
if (type) {
require(['esri/layers/' + type + 'Layer'], lang.hitch(this, '_initLayer', layer));
require([type], lang.hitch(this, '_initLayer', layer));
}
}, this);
this.map.addLayers(this.layers);
Expand Down
4 changes: 3 additions & 1 deletion viewer/js/viewer/_WidgetsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ define([
widgetLoader: function (widgetConfig, position) {
var parentId, pnl;

// only proceed for valid widget types
var widgetTypes = ['titlePane', 'contentPane', 'floating', 'domNode', 'invisible', 'map'];
// add any user-defined widget types
widgetTypes = widgetTypes.concat(this.config.widgetTypes || []);
// only proceed for valid widget types
if (array.indexOf(widgetTypes, widgetConfig.type) < 0) {
this.handleError({
source: 'Controller',
Expand Down

0 comments on commit 0bdc6c0

Please sign in to comment.