Skip to content

Commit

Permalink
support for 'showAttachments' for dynamic layers
Browse files Browse the repository at this point in the history
fixes #177
  • Loading branch information
tmcgee committed Sep 12, 2016
1 parent 59b5ebb commit a84cec7
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 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 @@ -416,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 @@ -553,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 a84cec7

Please sign in to comment.