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());
}
});
}
Solved! Go to Solution.
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.
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.
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);
});
}
}
That works like a charm. Thanks Robert!
Alex,
SO are you good now or do you still have an issue with removing the loop?
I am good. I was able to remove the loop. Thanks for all your help Robert!