Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for "group" layers provided by @carrbrpoa #721

Merged
merged 1 commit into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions viewer/js/config/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ define([
opacity: 1.0,
visible: true,
outFields: ['*'],
mode: 0
mode: 0,
groupID: 'Grouped Feature Layers'
},
editorLayerInfos: {
disableGeometryUpdate: false
Expand All @@ -166,7 +167,8 @@ define([
opacity: 1.0,
visible: true,
outFields: ['req_type', 'req_date', 'req_time', 'address', 'district'],
mode: 0
mode: 0,
groupID: 'Grouped Feature Layers'
},
layerControlLayerInfos: {
menu: [{
Expand Down
46 changes: 45 additions & 1 deletion viewer/js/gis/dijit/LayerControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ define([
_overlayContainer: null,
_swiper: null,
_swipeLayerToggleHandle: null,
_groupedLayerInfos: {},
_controls: {
dynamic: './LayerControl/controls/Dynamic',
feature: './LayerControl/controls/Feature',
Expand All @@ -75,7 +76,8 @@ define([
webtiled: './LayerControl/controls/WebTiled',
imagevector: './LayerControl/controls/ImageVector',
raster: './LayerControl/controls/Raster',
stream: './LayerControl/controls/Stream'
stream: './LayerControl/controls/Stream',
grouped: './LayerControl/controls/Grouped'
},
constructor: function (options) {
options = options || {};
Expand Down Expand Up @@ -165,6 +167,30 @@ define([
require([control], lang.hitch(this, '_addControl', layerInfo));
}
}, this);

for (var key in this._groupedLayerInfos) {
if (this._groupedLayerInfos.hasOwnProperty(key)) {
var control = this._controls.grouped;
var hasAnyVisibleLayer = this._groupedLayerInfos[key].some(function (layerDetail) {
return layerDetail.layerInfo.layer.visible;
});

var layerInfo = {
title: key,
layer: {
id: key.replace(/\s/g, ''),
loaded: true,
minScale: 0,
maxScale: 0,
_params: {},
visible: hasAnyVisibleLayer // initial visibility depends on grouped layers
},
layerDetails: this._groupedLayerInfos[key]
};
require([control], lang.hitch(this, '_addControl', layerInfo));
}
}

this._checkReorder();
}));
},
Expand Down Expand Up @@ -214,6 +240,7 @@ define([
controller: this,
layer: layer,
layerTitle: layerInfo.title,
layerDetails: layerInfo.layerDetails,
controlOptions: lang.mixin({
noLegend: null,
noZoom: null,
Expand All @@ -236,6 +263,23 @@ define([
} else {
this.addChild(layerControl, position);
}
this._storeGroupedLayerInfo(layerInfo, layerControl);
},
_storeGroupedLayerInfo: function (layerInfo, layerControl) {
var groupID = layerInfo.layer._params.groupID;
if (!groupID) {
// Not a grouped layer
return;
}

if (!this._groupedLayerInfos.hasOwnProperty(groupID)) {
this._groupedLayerInfos[groupID] = [];
}

this._groupedLayerInfos[groupID].push({
layerInfo: layerInfo,
layerControl: layerControl
});
},
_applyLayerControlOptions: function (controlOptions, layer) {
if (typeof controlOptions.includeUnspecifiedLayers === 'undefined' && typeof controlOptions.subLayerInfos === 'undefined' && typeof controlOptions.excludedLayers === 'undefined') {
Expand Down
130 changes: 130 additions & 0 deletions viewer/js/gis/dijit/LayerControl/controls/Grouped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
define([
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/on',
'dojo/topic',
'dojo/html',
'dojo/dom-class',
'dojo/dom-style',
'dojo/dom-construct',
'dijit/_WidgetBase',
'dijit/_TemplatedMixin',
'dijit/_Contained',
'./_Control' // layer control base class
], function (
declare,
lang,
on,
topic,
html,
domClass,
domStyle,
domConstruct,
_WidgetBase,
_TemplatedMixin,
_Contained,
_Control
) {
var GroupedControl = declare([_WidgetBase, _TemplatedMixin, _Contained, _Control], {
layerDetails: null,
_layerType: 'grouped', // constant
_esriLayerType: null, // constant

// create and legend
_layerTypePreInit: function () {
this.layerDetails.forEach(lang.hitch(this, function (layerDetail) {
domConstruct.place(layerDetail.layerControl.domNode, this.expandNode, 'first');
}));
},

_layerTypeInit: function () {
this._expandClick();
},

hasAnyVisibleLayer: function () {
return this.layerDetails.some(function (layerDetail) {
return layerDetail.layerInfo.layer.visible;
});
},

hasAnyInvisibleLayer: function () {
return this.layerDetails.some(function (layerDetail) {
return !layerDetail.layerInfo.layer.visible;
});
},

_initialize: function () {
// an optional function in each control widget called before widget init
if (this._layerTypePreInit) {
this._layerTypePreInit();
}
var layer = this.layer,
controlOptions = this.controlOptions,
layerDetails = this.layerDetails;

// set checkbox
this._setLayerCheckbox(layer, this.checkNode);

// wire up layer visibility
on(this.checkNode, 'click', lang.hitch(this, '_setLayerVisibility', layerDetails, this.checkNode));

// set title
html.set(this.labelNode, this.layerTitle);

// create layer menu
domClass.remove(this.menuNode, 'fa, layerControlMenuIcon, ' + this.icons.menu);
domStyle.set(this.menuClickNode, 'cursor', 'default');

// if layer has scales set
if (layer.minScale !== 0 || layer.maxScale !== 0) {
this._checkboxScaleRange();
this._scaleRangeHandler = layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange'));
}

// a function in each control widget for layer type specifics like legends and such
this._layerTypeInit();

// show expandNode
// no harm if click handler wasn't created
if (controlOptions.expanded) {
this.expandClickNode.click();
}

topic.subscribe('layerControl/layerToggle', lang.hitch(this, function (options) {
if (options.params && !options.forced && options.id !== layer.id && options.params.groupID === this.layerTitle) {
var layerVisible = this.layer.visible;
if (layerVisible && !this.hasAnyVisibleLayer()) {
this.toggleVisibility();
} else if (!layerVisible && !this.hasAnyInvisibleLayer()) {
this.toggleVisibility();
}
}
}));
},

toggleVisibility: function () {
var layer = this.layer;
layer.visible = !layer.visible;

this._setLayerCheckbox(layer, this.checkNode);
topic.publish('layerControl/layerToggle', {
id: layer.id,
visible: layer.visible,
forced: true
});
},

_setLayerVisibility: function (layerDetails, checkNode, event) {
this.toggleSelfVisibility();

var _arguments = arguments;
// Calls _setLayerVisibility for each grouped layer
layerDetails.forEach(lang.hitch(this, function (layerDetail) {
if (this.layer.visible !== layerDetail.layerInfo.layer.visible) {
this.inherited(_arguments, [layerDetail.layerInfo.layer, layerDetail.layerControl.checkNode, event]);
}
}));
}
});
return GroupedControl;
});
6 changes: 4 additions & 2 deletions viewer/js/gis/dijit/LayerControl/controls/_Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,16 @@ define([
layer.hide();
topic.publish('layerControl/layerToggle', {
id: layer.id,
visible: layer.visible
visible: layer.visible,
params: layer._params
});
} else {
this._setLayerCheckbox(layer, checkNode);
layer.show();
topic.publish('layerControl/layerToggle', {
id: layer.id,
visible: layer.visible
visible: layer.visible,
params: layer._params
});
}
if (layer.minScale !== 0 || layer.maxScale !== 0) {
Expand Down