ImageServiceIdentifyTask doesn't execute

469
6
Jump to solution
09-11-2018 01:20 PM
NaciDilekli
Occasional Contributor

I would like to calculate the elevation of each point during an edit session. I am capturing the location of the edited point using the before-apply-edits event. However, I could not get the ImageServiceIdentifyTask to execute (Also tried IdentifyTask in case I was missing something).

I can manually query my imageservice at demImageURL successfully from the ArcGIS REST Services Directory on my server.

I am adding the code. What am I missing? Thanks.

    systemEditor.startup();

    identifyDemTask = new ImageServiceIdentifyTask(demImageURL);
    identifyTask = new IdentifyTask(demImageURL);

    identifyParams = new IdentifyParameters();
    identifyParams.tolerance = 3;
    identifyParams.width = map.width;
    identifyParams.height = map.height;
    
    systemEditor.templatePicker.on("selection-change", lang.hitch(this, function () {
     
        var selected = systemEditor.templatePicker.getSelected();
        if (selected) {
            var featureLayer = selected.featureLayer;

            On.once(featureLayer, "before-apply-edits", lang.hitch(this, function (evt) {
                if (evt.adds && evt.adds.length > 0) {
                    var imageParams = new ImageServiceIdentifyParameters();
                    var point = new Point(evt.adds[0].geometry.x, evt.adds[0].geometry.y, evt.adds[0].geometry.spatialReference);
                    imageParams.geometry = point;
                    imageParams.mapExtent = map.extent;

                    identifyParams.geometry = point;
                    identifyParams.mapExtent = map.extent;
                    var deferred = identifyTask
                    .execute(identifyParams)
                    .addCallback(function (response) {
                        // I see nothing here
                        console.log(response);
                    });
                  
                    var deferred2 = identifyDemTask
                    .execute(imageParams)
                    .addCallback(function (response) {
                        // I see nothing here
                        console.log(response);
                    });

                    if (evt.adds[0].attributes.hasOwnProperty('elevation')) {
                        // to go inside the deferred execution
                    }
                    systemEditor.attributeInspector.refresh();
                }
            }));
        }
    }));‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Naci,

  Here are the changes I would make:

    systemEditor.startup();

    identifyDemTask = new ImageServiceIdentifyTask(demImageURL);
    
    systemEditor.templatePicker.on("selection-change", lang.hitch(this, function () {
     
        var selected = systemEditor.templatePicker.getSelected();
        if (selected) {
            var featureLayer = selected.featureLayer;

            On.once(featureLayer, "before-apply-edits", lang.hitch(this, function (evt) {
                if (evt.adds && evt.adds.length > 0) {
                    var imageParams = new ImageServiceIdentifyParameters();
                    var point = new Point(evt.adds[0].geometry.x, evt.adds[0].geometry.y, evt.adds[0].geometry.spatialReference);
                    imageParams.geometry = point;
                  
                    identifyDemTask.execute(imageParams, function(response) {
                        // I see nothing here
                        console.log(response);
                    }, function(err){
                        console.error(err);
                    });

                    if (evt.adds[0].attributes.hasOwnProperty('elevation')) {
                        // to go inside the deferred execution
                    }
                    systemEditor.attributeInspector.refresh();
                }
            }));
        }
    }));‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Naci,

  Here are the changes I would make:

    systemEditor.startup();

    identifyDemTask = new ImageServiceIdentifyTask(demImageURL);
    
    systemEditor.templatePicker.on("selection-change", lang.hitch(this, function () {
     
        var selected = systemEditor.templatePicker.getSelected();
        if (selected) {
            var featureLayer = selected.featureLayer;

            On.once(featureLayer, "before-apply-edits", lang.hitch(this, function (evt) {
                if (evt.adds && evt.adds.length > 0) {
                    var imageParams = new ImageServiceIdentifyParameters();
                    var point = new Point(evt.adds[0].geometry.x, evt.adds[0].geometry.y, evt.adds[0].geometry.spatialReference);
                    imageParams.geometry = point;
                  
                    identifyDemTask.execute(imageParams, function(response) {
                        // I see nothing here
                        console.log(response);
                    }, function(err){
                        console.error(err);
                    });

                    if (evt.adds[0].attributes.hasOwnProperty('elevation')) {
                        // to go inside the deferred execution
                    }
                    systemEditor.attributeInspector.refresh();
                }
            }));
        }
    }));‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
NaciDilekli
Occasional Contributor

Thanks Robert! I am curious though as I followed this example: Display identify results in popup | ArcGIS API for JavaScript 3.25 

How come that didn't work?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Naci,

  Because you can not use an IdentifyTask on an Image Service

0 Kudos
NaciDilekli
Occasional Contributor

Robert,

Well, I was trying to use the ImageServiceIdentityTask, too.

 identifyDemTask = new ImageServiceIdentifyTask(demImageURL);

...

                    var deferred2 = identifyDemTask
                    .execute(imageParams)
                    .addCallback(function (response) {
                        // I see nothing here
                        console.log(response);
                    });

That didn't execute either. The difference I see is the use of the addCallback method.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

I am not sure what was going wrong but I never use .addCallback personally.

NaciDilekli
Occasional Contributor

Noted, thanks!!

0 Kudos