Skip to content

Commit

Permalink
Merge pull request #597 from cmv/feature/identify-dynamic-layer-infoT…
Browse files Browse the repository at this point in the history
…emplates-and-showAttachments

identify widget - support dynamic layer infoTemplates and showAttachments
  • Loading branch information
DavidSpriggs authored Sep 20, 2016
2 parents dd02194 + 8fd614c commit 425af7f
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions viewer/js/gis/dijit/Identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ define([
'esri/tasks/IdentifyTask',
'esri/tasks/IdentifyParameters',
'esri/dijit/PopupTemplate',
'esri/layers/FeatureLayer',
'esri/TimeExtent',
'dojo/text!./Identify/templates/Identify.html',
'dojo/i18n!./Identify/nls/resource',

'dijit/form/Form',
'dijit/form/FilteringSelect',
'xstyle/css!./Identify/css/Identify.css'
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, MenuItem, lang, array, all, topic, query, domStyle, domClass, Moveable, Memory, IdentifyTask, IdentifyParameters, PopupTemplate, TimeExtent, IdentifyTemplate, i18n) {
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, MenuItem, lang, array, all, topic, query, domStyle, domClass, Moveable, Memory, IdentifyTask, IdentifyParameters, PopupTemplate, FeatureLayer, TimeExtent, IdentifyTemplate, i18n) {

return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
widgetsInTemplate: true,
Expand All @@ -34,6 +35,7 @@ define([
mapClickMode: null,
identifies: {},
infoTemplates: {},
featureLayers: {},
ignoreOtherGraphics: true,
createDefaultInfoTemplates: true,
draggable: false,
Expand All @@ -53,8 +55,7 @@ define([
}
this.layers = [];
array.forEach(this.layerInfos, function (layerInfo) {
var lyrId = layerInfo.layer.id;
var layer = this.map.getLayer(lyrId);
var lyrId = layerInfo.layer.id, layer = this.map.getLayer(lyrId), infoTemplate;
if (layer) {
var url = layer.url;

Expand All @@ -67,7 +68,7 @@ define([
// it only if one does not already exist.
if (layer.capabilities && array.indexOf(layer.capabilities.toLowerCase(), 'data') < 0) {
if (!layer.infoTemplate) {
var infoTemplate = this.getInfoTemplate(layer, layer.layerId);
infoTemplate = this.getInfoTemplate(layer, layer.layerId);
if (infoTemplate) {
layer.setInfoTemplate(infoTemplate);
return;
Expand All @@ -81,6 +82,13 @@ define([
if (lastSL > 0) {
url = url.substring(0, lastSL);
}
} else if (layer.layerInfos) {
array.forEach(layer.layerInfos, lang.hitch(this, function (subLayerInfo) {
var subLayerId = subLayerInfo.id;
if ((layerInfo.layerIds === null) || (array.indexOf(layerInfo.layerIds, subLayerId) >= 0)) {
this.getFeatureLayerForDynamicSublayer(layer, subLayerId);
}
}));
}

this.layers.push({
Expand Down Expand Up @@ -297,6 +305,9 @@ define([
if (result.feature.infoTemplate === undefined) {
var infoTemplate = this.getInfoTemplate(ref, null, result);
if (infoTemplate) {
if (result.layerId && ref.layerInfos && infoTemplate.info.showAttachments) {
result.feature._layer = this.getFeatureLayerForDynamicSublayer(ref, result.layerId);
}
result.feature.setInfoTemplate(infoTemplate);
} else {
return;
Expand Down Expand Up @@ -327,6 +338,15 @@ define([
layerId = layer.layerId;
}

// get infoTemplate from the layer's infoTemplates array
if (layer.infoTemplates) {
if (layer.infoTemplates.hasOwnProperty(layerId)) {
return layer.infoTemplates[layerId].infoTemplate;
} else {
return null;
}
}

// see if we have a Popup config defined for this layer
if (this.identifies.hasOwnProperty(layer.id)) {
if (this.identifies[layer.id].hasOwnProperty(layerId)) {
Expand Down Expand Up @@ -407,10 +427,11 @@ define([
}

if (fieldInfos.length > 0) {
var featLayer = this.getFeatureLayerForDynamicSublayer(layer, layerId);
popup = new PopupTemplate({
title: layerName,
fieldInfos: fieldInfos,
showAttachments: (layer.hasAttachments)
showAttachments: (layer.hasAttachments || featLayer.hasAttachments)
});
if (!this.identifies[layer.id]) {
this.identifies[layer.id] = {};
Expand Down Expand Up @@ -544,6 +565,17 @@ define([
return name;
},

getFeatureLayerForDynamicSublayer: function (layer, layerId) {
if (!layer.layerInfos) {
return false;
}
var key = layer.url + '/' + layerId;
if (!this.featureLayers.hasOwnProperty(key)) {
this.featureLayers[key] = new FeatureLayer(key);
}
return this.featureLayers[key];
},

layerVisibleAtCurrentScale: function (layer) {
var mapScale = this.map.getScale();
return !(((layer.maxScale !== 0 && mapScale < layer.maxScale) || (layer.minScale !== 0 && mapScale > layer.minScale)));
Expand Down

0 comments on commit 425af7f

Please sign in to comment.