infowindow.select(index) highlighting features out of order

2909
13
Jump to solution
08-19-2014 07:53 AM
JeffPace
MVP Alum

using javascript api 3.10

I am using a popup in a sidepanel.  When I click "next" (using the sample integrated in my application) it calls

map.infoWindow.selectNext();
onResultSummaryItemClick(map.infoWindow.selectedIndex);



which then calls

function onResultSummaryItemClick(idx) { // alert(idx);
 map.infoWindow.select(idx); // alert("index:"+map.infoWindow.selectedIndex); 
var extent = map.infoWindow.getSelectedFeature().geometry.getExtent();
 if (!extent) { // alert(map.infoWindow.getSelectedFeature()+":"+map.infoWindow.getSelectedFeature().geometry); 
map.centerAndZoom(map.infoWindow.getSelectedFeature().geometry, 18); 
} 
else 
{ 
map.setExtent(extent, true); 
 }



However the selected feature highlight symbol is ending up first in the list, instead of last, so it is drawing UNDER the feature, and therefore isnt appearing highlighted.  If i click the feature, the highlight moves to the bottom of the list, and draws correctly.

PATHS after hitting next

selected_wrong_order.JPG

PATHS after clicking to select

selected_right order.JPG

any ideas? Kelly HutchinsDerek SwingleyJonathan Uihlein

0 Kudos
1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor

Jeff, my guess is that the creation of the selection graphic is probably not working because the location is not on the screen; you'll have to select it again after you've navigated to the graphic.

View solution in original post

0 Kudos
13 Replies
KellyHutchins
Esri Frequent Contributor

Can you try moving the selected graphic to the front.  You can do this using

var graphic = popup.getSelectedFeature();

graphic.getShape().moveToFront();

JeffPace
MVP Alum

map.infoWindow.select(idx);

var extent = map.infoWindow.getSelectedFeature().geometry.getExtent();

console.log(extent);

var graphic = map.infoWindow.getSelectedFeature();

results in good extent, so map.infoWindow.getSelectedFeature() is fine, but then

Object { type="extent", xmin=-9191676.043059396, ymin=3183521.7840280095, more...}

TypeError: graphic.getShape(...) is null

graphic.getShape().moveToFront();

So it is selecting, it can get the selectedfeature to get an extent (its a polygon) but getShape is returning null

)

0 Kudos
KellyHutchins
Esri Frequent Contributor

Do you have a code sample that shows the problem you can post?

0 Kudos
JeffPace
MVP Alum

Unfortunately I dont, its in a rather complicated app.

When i console.dir(graphic) prior to trying getShape (also tried getShapes) I get a valid graphic.  But even in firebug commandline if I call $p.getShape() it returns null

0 Kudos
JohnGrayson
Esri Regular Contributor

Jeff, this typically happens when the graphic is not currently loaded into the display.  You should first navigate to the appropriate location and then access the shape.  For point data you might have to use some other way of navigating to the location of the graphic, but the logic is the same.

map.infoWindow.select(idx);

var selectedFeature = map.infoWindow.getSelectedFeature();

map.setExtent(selectedFeature.geometry.getExtent()).then(lang.hitch(this,function(){

  selectedFeature.getShape().moveToFront();

});

0 Kudos
JeffPace
MVP Alum

still no go

I tried

  popup.select(idx);

         var extent = popup.getSelectedFeature().geometry.getExtent();

                  

                                    if (!extent) {

                                        map.centerAndZoom(popup.getSelectedFeature().geometry, 18).then(lang.hitch(this,function(){

                                            popup.getSelectedFeature().getShape().moveToFront();

                                        })) ;

                                      

                                    } else {

                                        map.setExtent(extent, true).then(lang.hitch(this,function(){

                                            popup.getSelectedFeature().getShape().moveToFront();

                                        }));

                                    }

But it just wont highlight.  If the feature is on the screen when i select it from the list, it works.

If it is off the screen, it does not.  Even though I am moving to it prior to selecting it. 

The if(!extent) above is to handle point data

0 Kudos
JeffPace
MVP Alum

actually, i dont think this is right.  This is moving the selectedfeature to the front, which it is now doing.  However it is not moving the HIGHLIGHT graphic, which is what I need.

When i run this from the command line

popup.getSelectedFeature().getShape().moveToFront()

I see the graphic being moved, but its the feature, not the highlight.

0 Kudos
JohnGrayson
Esri Regular Contributor

Jeff, my guess is that the creation of the selection graphic is probably not working because the location is not on the screen; you'll have to select it again after you've navigated to the graphic.

0 Kudos
JeffPace
MVP Alum

Baffling as to why I have to do this, but here is the working code.  Thanks Kelly and John

popup.select(idx);

var extent = popup.getSelectedFeature().geometry.getExtent();

if (!extent) {

        map.centerAndZoom(popup.getSelectedFeature().geometry,18).then(lang.hitch(this,function(){

              popup.select(popup.selectedIndex);                                          

          })) ;                        

} else {

          map.setExtent(extent, true).then(lang.hitch(this,function(){

                popup.select(popup.selectedIndex);

          }));

}