ダイナミック マップ サービス レイヤーで識別ツールを使用して、レコードに添付されている画像を示す情報ウィンドウを表示しようとしています。色々と操作してフィーチャ レイヤーを取得する必要がありますが、問題なく動作します。私は遅延物に問題があります。
ここに問題があります。identify タスクは Dojo の据え置きオブジェクトを返します。遅延が解決されたときに実行するコールバックがあります。そのコールバック関数で、queryAttachmentInfos という別の関数を実行します。これが実行されると、queryAttachmentInfos 関数の前に「return feature」という行が起動します。どうしてか分かりません。コールバック内のすべてが同期的に発生するべきではありませんか? queryAttachmentInfo が完了するまでコールバック関数を待機させるにはどうすればよいですか? setTimeout を使用して、スクリプトを 1 秒間待機させるようにしていますが、これは時々機能しますが、それは良い解決策ではないことはわかっています。
どんな助けでも大歓迎です。
以下のコード...
function executeIdentifyTask(evt) {
identifyParams.geometry = evt.mapPoint;
identifyParams.mapExtent = map.extent;
var deferred = identifyTask.execute(identifyParams);
deferred.addCallback(function(response) {
return dojo.map(response, function(result) {
var feature = result.feature;
var fLayerPath = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0"
var featureLayer = new esri.layers.FeatureLayer(fLayerPath);
var objID = feature.attributes.OBJECTID;
feature.attributes.layerName = result.layerName;
//alert(result.layerId);
if(result.layerName === 'Tax Parcels'){
featureLayer.queryAttachmentInfos(6737858, function (infos) {
if (infos.length>0) {
el = document.createElement('img');
el.setAttribute('src', infos[0].url);
t = document.createElement('table');
//first row Request Type
r = t.insertRow(0);
r.bgColor="#00FFFF";
c = r.insertCell(0);
c1 = r.insertCell(1);
c.innerHTML="Request Type";
c1.innerHTML=feature.attributes.building;
//second row District
r1 = t.insertRow(-1);
c2 = r1.insertCell(0);
c2_1 = r1.insertCell(1);
c2.innerHTML="District";
c2_1.innerHTML=feature.attributes.UNIT;
//third row Status
r2 = t.insertRow(-1);
r2.bgColor="#00FFFF";
c3 = r2.insertCell(0);
c3_1 = r2.insertCell(1);
c3.innerHTML="Status";
c3_1.innerHTML=feature.attributes.PARCELID ;
var len = infos.length;
for (var i = 0; i < len;i++)
{
newRow = t.insertRow(-1);
newCell = newRow.insertCell(0);
newCell.colSpan=2;
newCell.innerHTML="<a href="+infos[i].url+"/><img src="+infos[i].url+"/>";
//els[i]= document.createElement('img');
//els[i].setAttribute('src', infos[i].url);
//alert(infos[i].url);
}
var template = new esri.InfoTemplate("", t);
feature.setInfoTemplate(template);
//return feature;
}
else
{
var template = new esri.InfoTemplate("", "${Postal Address} <br/> Different: ${First Owner Name}");
feature.setInfoTemplate(template);
//eturn feature;
}
});
console.log(feature.attributes.PARCELID);
}
else if (result.layerName === 'Building Footprints'){
var template = new esri.InfoTemplate("", "Parcel ID: ${PARCELID}");
feature.setInfoTemplate(template);
//return feature;
}
return feature;
});
});
setTimeout(function(){map.infoWindow.setFeatures([ deferred ])},1000);
map.infoWindow.show(evt.mapPoint);
}