1

私が欲しいのは、2 つの異なるIdentifyTasks の値を使用する情報ウィンドウを開きたいということです。

これが私のコードです:

dojo.connect(map, "onClick", executeIdentifyTask);

identifyTask = new esri.tasks.IdentifyTask("https://server.com/ArcGIS/rest/services/POI_Data/MapServer");

identifyTask2 = new esri.tasks.IdentifyTask("https://server.com/ArcGIS/rest/services/ProRail_Data/MapServer");

identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = 15;
identifyParams.returnGeometry = true;
identifyParams.layerIds = [0];
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.width = map.width;
identifyParams.height = map.height;

identifyParams2 = new esri.tasks.IdentifyParameters();
identifyParams2.tolerance = 10;
identifyParams2.returnGeometry = true;
identifyParams.layerIds = [23, 26, 31, 33];
identifyParams2.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
identifyParams2.width = map.width;
identifyParams2.height = map.height;

function executeIdentifyTask(evt) {

    identifyParams.geometry = evt.mapPoint;
    identifyParams.mapExtent = map.extent;
    var deferred = identifyTask.execute(identifyParams);
    identifyParams2.geometry = evt.mapPoint;
    identifyParams2.mapExtent = map.extent;

    var deferred2 = identifyTask2.execute(identifyParams2);

    deferred.addCallback(function (response) {
        // response is an array of identify result objects    
        // Let's return an array of features.
        return dojo.map(response, function (result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
            if (result.layerName === 'Spoortoegang') {
                console.log(feature.attributes.PARCELID);
                var template = new esri.InfoTemplate("ToegangsNummer ${ToegangsNr}", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak},  <br/> Geocode: ${Geocode},  <br/> Kilometer: ${Kilometrering}");
                feature.setInfoTemplate(template);
                alert("Spoortoegang");
            }
            else if (result.layerName === 'sein') {
                var template = new esri.InfoTemplate("", "Parcel ID: ${NUMMER}");
                feature.setInfoTemplate(template);
            }
            return feature;
        });
    });

    deferred2.addCallback(function (response) {
        // response is an array of identify result objects    
        // Let's return an array of features.
        return dojo.map(response, function (result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
            if (result.layerName === 'Wissels') {
                console.log(feature.attributes.PARCELID);
                var template = new esri.InfoTemplate("Wissel", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak},  <br/> Geocode: ${Geocode},  <br/> Kilometer: ${Kilometrering}");
                feature.setInfoTemplate(template);
                alert("Wissels");

            }
            else if (result.layerName === 'sein') {
                var template = new esri.InfoTemplate("", "Sein Nummer: ${NUMMER}");
                feature.setInfoTemplate(template);
                alert("sein");
            }
            else if (result.layerName === 'Sporen') {
                console.log(feature.attributes.PARCELID);
                var template = new esri.InfoTemplate("Wissel", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak},  <br/> Geocode: ${Geocode},  <br/> Kilometer: ${Kilometrering}");
                feature.setInfoTemplate(template);
                alert("Sporen");
            }
            else if (result.layerName === 'bovenleidingpaal') {
                console.log(feature.attributes.PARCELID);
                var template = new esri.InfoTemplate("Wissel", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak},  <br/> Geocode: ${Geocode},  <br/> Kilometer: ${Kilometrering}");
                feature.setInfoTemplate(template);
                alert("bovenleidingspaal");
            }

            return feature;
        });
    });


    // InfoWindow expects an array of features from each deferred
    // object that you pass. If the response from the task execution 
    // above is not an array of features, then you need to add a callback
    // like the one above to post-process the response and return an
    // array of features.
    map.infoWindow.resize(195, 75);
    map.infoWindow.setFeatures([deferred]);
    map.infoWindow.show(evt.mapPoint);

    map.infoWindow.resize(195, 75);
    map.infoWindow.setFeatures([deferred2]);
    map.infoWindow.show(evt.mapPoint);
}

からアラートとinfowindowコンテンツのみを取得し、の何も取得しdeferred2ませんdeferred

4

1 に答える 1

1

次のコードを短縮できますdeferred2

deferred2.addCallback(function (response) {
    // response is an array of identify result objects    
    // Let's return an array of features.
    return dojo.map(response, function (result) {
        var feature = result.feature;
        feature.attributes.layerName = result.layerName;
        var template;
        switch(result.layerName){
            case 'Wissels':
            case 'Sporen':
            case 'bovenleidingpaal':
                template = new esri.InfoTemplate("Wissel", "Toegangsnummer ${ToegangsNr} <br/> Baanvak: ${Baanvak},  <br/> Geocode: ${Geocode},  <br/> Kilometer: ${Kilometrering}");
            break;
            case 'sein':
                var template = new esri.InfoTemplate("", "Sein Nummer: ${NUMMER}");
            break;
        }
        console.log(feature.attributes.PARCELID);
        feature.setInfoTemplate(template);
        alert(result.layerName);

        return feature;
    });
});

これは同じように機能するはずです。

于 2012-11-27T08:46:42.427 に答える