Select to view content in your preferred language

Trying to show Infowindow on query callback

1327
5
Jump to solution
02-28-2017 08:34 AM
by Anonymous User
Not applicable

Hi all,

I am having trouble getting the infowindow to show up at the query callback. My goal is to zoom to a point and open infowindow immediately.  Is there a way?

function queryCallbackrc(featureSet) {
            arrayUtil.forEach(featureSet.features, function (feature) {
            var graphic = feature;
           map.infoWindow.show(graphic, InfoWindow.ANCHOR_UPPERRIGHT);
           if (graphic.geometry.type === 'point') {
           
           var mz = map.getMaxZoom() ;  
           if (mz > -1) {  
           map.centerAndZoom(graphic.geometry, mz - 2);  
           } else {  
           map.centerAndZoom(graphic.geometry, 0.25);  
           }  
           }          
            else {  
            map.setExtent(graphic.geometry.getExtent());  
            }
            });
         }
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Alex,

   You should wait for the map to complete it zooming before trying to show the info window:

function queryCallbackrc(featureSet) {
  arrayUtil.forEach(featureSet.features, function (feature) {
    var graphic = feature;
    if (graphic.geometry.type === 'point') {
      var mz = map.getMaxZoom() ;  
      if (mz > -1) {  
        map.centerAndZoom(graphic.geometry, mz - 2).then(function(){
          map.infoWindow.show(graphic.geometry, InfoWindow.ANCHOR_UPPERRIGHT);
        });
      } else {  
        map.centerAndZoom(graphic.geometry, 0.25).then(function(){
          map.infoWindow.show(graphic.geometry, InfoWindow.ANCHOR_UPPERRIGHT);
        });  
      }  
    } else {  
       map.setExtent(graphic.geometry.getExtent()).then(function(){
         map.infoWindow.show(graphic.geometry.getExtent().getCenter(), InfoWindow.ANCHOR_UPPERRIGHT);
       });
    }
  });
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

BTW: you can only show one info window on the map so there is really no point in the forEach loop as only the last result will stay end up getting the infowindow.

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Alex,

   You should wait for the map to complete it zooming before trying to show the info window:

function queryCallbackrc(featureSet) {
  arrayUtil.forEach(featureSet.features, function (feature) {
    var graphic = feature;
    if (graphic.geometry.type === 'point') {
      var mz = map.getMaxZoom() ;  
      if (mz > -1) {  
        map.centerAndZoom(graphic.geometry, mz - 2).then(function(){
          map.infoWindow.show(graphic.geometry, InfoWindow.ANCHOR_UPPERRIGHT);
        });
      } else {  
        map.centerAndZoom(graphic.geometry, 0.25).then(function(){
          map.infoWindow.show(graphic.geometry, InfoWindow.ANCHOR_UPPERRIGHT);
        });  
      }  
    } else {  
       map.setExtent(graphic.geometry.getExtent()).then(function(){
         map.infoWindow.show(graphic.geometry.getExtent().getCenter(), InfoWindow.ANCHOR_UPPERRIGHT);
       });
    }
  });
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

BTW: you can only show one info window on the map so there is really no point in the forEach loop as only the last result will stay end up getting the infowindow.

by Anonymous User
Not applicable

I am trying to get away from that foreach loop but I am running into errors when I do.

function queryCallbackrc(feature) {
        var graphic = feature.geometry;
        if (graphic.geometry.type === 'point') {
        var mz = map.getMaxZoom() ;  
        if (mz > -1) {  
        map.centerAndZoom(graphic.geometry, 14).then(function(){
        map.infoWindow.setTitle("Road Status");
        map.infoWindow.setContent(getTextContent3(graphic));
        map.infoWindow.show(graphic.geometry, InfoWindow.ANCHOR_UPPERRIGHT);
        });
         } else {  
         map.centerAndZoom(graphic.geometry, 14).then(function(){
         map.infoWindow.setTitle("Road Status");
         map.infoWindow.setContent(getTextContent3(graphic));
         map.infoWindow.show(graphic.geometry, InfoWindow.ANCHOR_UPPERRIGHT);
         });  
         }  } else {  
         map.centerAndZoom(graphic.geometry, 14).then(function(){
         map.infoWindow.setTitle("Road Status");
         map.infoWindow.setContent(getTextContent3(graphic));
         map.infoWindow.show(graphic.geometry, InfoWindow.ANCHOR_UPPERRIGHT);
         });
         }
         }
0 Kudos
by Anonymous User
Not applicable

That works like a charm. Thanks Robert!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

   SO are you good now or do you still have an issue with removing the loop?

0 Kudos
by Anonymous User
Not applicable

I am good. I was able to remove the loop. Thanks for all your help Robert!

0 Kudos