ArcGIS JavaScript API: Issues with displaying the correct figures of selected features as text

2518
6
Jump to solution
10-08-2014 06:34 AM
HabG_
by
Occasional Contributor

Hi All,

I have a web map and the issue I'm having is, when I select features using either Polygon, Circle or Freehand Polygon  buttons for the first time as shown in Figure A, it displays the correct figures for (Total features selected, FeatureLayer1, FeatureLayer2 and  FeatureLayer3). However, when I clear selection (using the Clear Selection button) and make another selection (Figure B) the figures displayed are incorrect. The Total features selected from the previous selection is added to the current Total features selected figures. The figures of FeatureLayer1, FeatureLayer2 and FeatureLayer3 are also not correct. This is the link to the web map‌, similar to the one I'm using. Can anyone please show me how to correct this issue?

Thanks

Figure A

firstselection.jpg

Figure B

secondselection.jpg

0 Kudos
1 Solution

Accepted Solutions
RiyasDeen
Occasional Contributor III

Hi Hab,

You are not resetting your promises array on draw end event, because of which your promises just keeps adding on top of each other.

I have updated the fiddle have a look Edit fiddle - JSFiddle

View solution in original post

0 Kudos
6 Replies
RiyasDeen
Occasional Contributor III

Hi Hab,

You are not resetting your promises array on draw end event, because of which your promises just keeps adding on top of each other.

I have updated the fiddle have a look Edit fiddle - JSFiddle

0 Kudos
TimWitt2
MVP Alum

Riyas,

you are just too fast with your answers!!!

Tim

0 Kudos
RiyasDeen
Occasional Contributor III

Tim,

Just happened to cast my eyes couple of minutes earlier

0 Kudos
KenBuja
MVP Esteemed Contributor

And that's why I refreshed the page so I didn't post the same answer. You posted just a minute before I was going to

0 Kudos
TimWitt2
MVP Alum

Hab,

your issue lies here:

    function showselResults(results) {

        var featureLayer1Message = results[0].length;

        var featureLayer2Message = results[1].length;

        var featureLayer3Message = results[2].length;

        var count = 0;

        for (var i = 0; i < results.length; i++) {

            count = count + results.length;

        }

        dom.byId("messages").innerHTML = "Total features selected:  <b>" + count + "</b><br>  FeatureLayer1:  <b>" + featureLayer1Message + "</b><br>  FeatureLayer2:  <b>" + featureLayer2Message + "</b><br>  FeatureLayer3:  " + featureLayer3Message;

    }

Your results keep the previous selections. That is also why the count for each feature layer in future selections is wrong, because it will keep showing the count of your first selection.

Looking at my screenshot, there should only be 3 arrays, but there are 9 because I did 3 selections.

0 Kudos
HabG_
by
Occasional Contributor

Thanks Riyas.

0 Kudos