0

ダイナミック マップ サービス レイヤーで識別ツールを使用して、レコードに添付されている画像を示す情報ウィンドウを表示しようとしています。色々と操作してフィーチャ レイヤーを取得する必要がありますが、問題なく動作します。私は遅延物に問題があります。

ここに問題があります。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);
      }
4

2 に答える 2

1

問題featureLayer.queryAttachmentInfos()はそれ自体が非同期であるように見えるため、「Tax Parcels」の場合、map.infoWindow.setFeatures()そのmap.infoWindow.show()非同期アクティビティが完了したときにのみ呼び出すことができます。

一方、「Building Footprints」の場合は、(外側の非同期コールバック内で) 同期的に呼び出すことができますmap.infoWindow.setFeatures()map.infoWindow.show(evt.mapPoint)

これは、2 つの場所から呼び出す必要がある小さなコード ブロックがあることを意味します。次のように、数行のコードを繰り返すか、ワーカー関数を記述できます。

var showInfoWindow = function(feature, tpl) {
    // A utility function which creates and populates an infowindow
    // and shows it at evt.mapPoint
    feature.setInfoTemplate( new esri.InfoTemplate("", tpl) );
    map.infoWindow.setFeatures(feature);
    map.infoWindow.show(evt.mapPoint);
}

そして、ここにコンテキストがあります(わかりやすくするために、かさばるDOM構築はすべて削除されています):

function executeIdentifyTask(evt) {
    identifyParams.geometry = evt.mapPoint;
    identifyParams.mapExtent = map.extent;

    var showInfoWindow = function(feature, tpl) {
        // A utility function which creates and populates an infowindow
        // and shows it at evt.mapPoint
        feature.setInfoTemplate( new esri.InfoTemplate("", tpl) );
        map.infoWindow.setFeatures(feature);
        map.infoWindow.show(evt.mapPoint);
    }

    var deferred = identifyTask.execute(identifyParams);

    deferred.addCallback(function(response) {
        return dojo.map(response, function(result) {
            var feature = result.feature;
            //var objID = feature.attributes.OBJECTID;//???
            feature.attributes.layerName = result.layerName;
            if(result.layerName === 'Tax Parcels') {
                var fLayerPath = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0";
                var featureLayer = new esri.layers.FeatureLayer(fLayerPath);
                featureLayer.queryAttachmentInfos(6737858, function(infos) {
                    var t, tpl;
                    if(infos.length > 0) {
                        t = document.createElement('table');
                        //***** Reinsert several lines of code here *****
                        //***** Remember to localize variables with `var` *****
                        tpl = t;
                    }
                    else {
                        tpl = "${Postal Address} <br/> Different: ${First Owner Name}";
                    }
                    showInfoWindow(feature, tpl);//<<<<< create, populate and display an infowindow
                });
            }
            else if (result.layerName === 'Building Footprints') {
                showInfoWindow(feature, "Parcel ID: ${PARCELID}");//<<<<< create, populate and display an infowindow
            }
            //return feature;//???
        });
    });
}

私がやったのは、道場やアークギスの特別な知識がなくても、物事をシャッフルすることだけです。私の側にエラーがなければ、すべてがうまくいくはずです。とはいえ、構文エラーのテストしかできていないので、デバッグを行う準備をしてください。そして、かさばるテーブル構築行を貼り付けることを忘れないでください.

于 2013-06-02T23:20:24.027 に答える