Retour à la documentation
/**
* @class spw.widgets.SpwAdvancedQueryResult
*/
define([
'dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array',
'spw/api/SpwBaseTemplatedWidget',
'dojo/text!./templates/SpwAdvancedQueryResult.html',
'dojo/dom-construct', 'dojo/on', 'spw/api/ProjectionManager', 'dojo/date/locale',
'spw/api/CollapserItem'
], function(declare, lang, array, _Templated, tmpl, domConstruct, on, ProjectionManager, locale, CollapserItem) {
return declare(_Templated, {
templateString: tmpl,
typesConditionsMapping: null,
resultTables: null,
postCreate: function() {
this.inherited(arguments);
this.resultTables = {};
},
onActivate: function() {
this.inherited(arguments);
// this.removeFeatures();
},
onDeactivate: function() {
this.inherited(arguments);
// this.removeFeatures();
},
removeFeatures: function() {
array.forEach(this.features, lang.hitch(this, function(f) {
this.spwViewer.get('spwMap').removeFeature(f);
}));
this.features = [];
},
showResults: function(featureSet, layer) {
var resultTable = this.resultTables[layer.id];
if (resultTable == null) {
var collapserItem = new CollapserItem({
_label: layer.name
});
domConstruct.place(collapserItem.domNode, this.domNode, 'last');
var resultTable = domConstruct.create('table', {
'style': 'width: 100%; height: 100%;',
'class': 'SpwIdentifyResultTable'
}, collapserItem.itemContentBlock);
resultTable._collapserItem = collapserItem;
collapserItem.on('destroy', lang.hitch(this, function() {
this.resultTables[layer.id] = null;
var ok = false;
for (var key in this.resultTables) {
if (this.resultTables.hasOwnProperty(key)) {
if (this.resultTables[key]) {
ok = true;
break;
}
}
}
if (!ok) {
this.onDeactivate();
}
}));
this.resultTables[layer.id] = resultTable;
}
else {
domConstruct.empty(resultTable);
}
this.addResultsToTable(featureSet, resultTable, layer);
},
addResultsToTable: function(featureSet, resultTable, layer) {
var aliases = featureSet.fieldAliases;
var fields = featureSet.fields;
var tr = domConstruct.create('tr', null, resultTable);
array.forEach(fields, lang.hitch(this, function(field) {
domConstruct.create('th', {
innerHTML: aliases[field.name] || field.name
}, tr);
}));
resultTable._collapserItem.set('title', layer.name + ' (' + featureSet.features.length + ')');
array.forEach(featureSet.features, lang.hitch(this, function(feature) {
tr = domConstruct.create('tr', {
'style': 'cursor: pointer;'
}, resultTable);
array.forEach(fields, lang.hitch(this, function(field) {
var buildInfo = this.typesConditionsMapping[field.type];
var value = feature.attributes[field.name];
if (value == null) {
value = '';
}
else if (buildInfo.type === 'date') {
value = locale.format(new Date(value));
}
domConstruct.create('td', {
innerHTML: value
}, tr);
}));
var map = this.spwViewer.get('spwMap');
on(tr, 'click', lang.hitch(this, function() {
// this.features = this.features || [];
// if (this.features.indexOf(feature) < 0) {
var srid = lang.getObject('geometry.spatialReference.wkid', false, feature);
var mapSrid = map.getSpatialReferenceSRID();
if (srid !== mapSrid) {
feature.setGeometry(ProjectionManager.getInstance().transform(srid, mapSrid, feature.geometry));
}
map.highlightFeature(feature);
map.zoomToFeature(feature);
// this.features.push(feature);
setTimeout(lang.hitch(this, function() {
map.removeFeature(feature);
}), 2000);
// }
}));
}));
}
});
});