Skip to content

Commit

Permalink
Merge pull request #648 from roemhildtg/identify-layer-add-topic
Browse files Browse the repository at this point in the history
make identify listen for new layer contol layer adds
  • Loading branch information
tmcgee authored Dec 18, 2016
2 parents 10e93b8 + 4c2a037 commit cfd44b2
Showing 1 changed file with 71 additions and 55 deletions.
126 changes: 71 additions & 55 deletions viewer/js/gis/dijit/Identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,62 +68,10 @@ define([
this.identifies = {};
}
this.layers = [];
array.forEach(this.layerInfos, function (layerInfo) {
var lyrId = layerInfo.layer.id, layer = this.map.getLayer(lyrId), infoTemplate;
if (layer) {
var url = layer.url;

// handle feature layers
if (layer.declaredClass === 'esri.layers.FeatureLayer') {

// If is a feature layer that does not support
// Identify (Feature Service), create an
// infoTemplate for the graphic features. Create
// it only if one does not already exist.
if (layer.capabilities && array.indexOf(layer.capabilities.toLowerCase(), 'data') < 0) {
if (!layer.infoTemplate) {
infoTemplate = this.getInfoTemplate(layer, layer.layerId);
if (infoTemplate) {
layer.setInfoTemplate(infoTemplate);
return;
}
}
}

// If it is a feature Layer, we get the base url
// for the map service by removing the layerId.
var lastSL = url.lastIndexOf('/' + layer.layerId);
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({
ref: layer,
layerInfo: layerInfo,
identifyTask: new IdentifyTask(url)
});

// rebuild the layer selection list when any layer is hidden
// but only if we have a UI
if (this.parentWidget) {
layer.on('visibility-change', lang.hitch(this, function (evt) {
if (evt.visible === false) {
this.createIdentifyLayerList();
}
}));
}
}
}, this);
this.addLayerInfos(this.layerInfos);

this.own(topic.subscribe('mapClickMode/currentSet', lang.hitch(this, 'setMapClickMode')));
this.own(topic.subscribe('identify/addLayerInfos', lang.hitch(this, 'addLayerInfos')));

this.map.on('click', lang.hitch(this, function (evt) {
if (this.mapClickMode === 'identify') {
Expand All @@ -147,6 +95,74 @@ define([
this.setupDraggable();
}
},
/**
* handles an array of layerInfos to call addLayerInfo for each layerInfo
* @param {Array<layerInfo>} layerInfos The array of layer infos
* @returns {undefined}
*/
addLayerInfos: function (layerInfos) {
array.forEach(layerInfos, lang.hitch(this, 'addLayerInfo'));
},
/**
* Initializes an infoTemplate on a layerInfo.layer object if it doesn't
* exist already.
* @param {object} layerInfo A cmv layerInfo object that contains a layer property
* @return {undefined}
*/
addLayerInfo: function (layerInfo) {
var lyrId = layerInfo.layer.id, layer = this.map.getLayer(lyrId), infoTemplate;
if (layer) {
var url = layer.url;

// handle feature layers
if (layer.declaredClass === 'esri.layers.FeatureLayer') {

// If is a feature layer that does not support
// Identify (Feature Service), create an
// infoTemplate for the graphic features. Create
// it only if one does not already exist.
if (layer.capabilities && array.indexOf(layer.capabilities.toLowerCase(), 'data') < 0) {
if (!layer.infoTemplate) {
infoTemplate = this.getInfoTemplate(layer, layer.layerId);
if (infoTemplate) {
layer.setInfoTemplate(infoTemplate);
return;
}
}
}

// If it is a feature Layer, we get the base url
// for the map service by removing the layerId.
var lastSL = url.lastIndexOf('/' + layer.layerId);
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({
ref: layer,
layerInfo: layerInfo,
identifyTask: new IdentifyTask(url)
});

// rebuild the layer selection list when any layer is hidden
// but only if we have a UI
if (this.parentWidget) {
layer.on('visibility-change', lang.hitch(this, function (evt) {
if (evt.visible === false) {
this.createIdentifyLayerList();
}
}));
}
}
},
addRightClickMenu: function () {
this.map.on('MouseDown', lang.hitch(this, function (evt) {
this.mapRightClick = evt;
Expand Down Expand Up @@ -666,4 +682,4 @@ define([
}, this);
}
});
});
});

0 comments on commit cfd44b2

Please sign in to comment.