Select to view content in your preferred language

InfoWindow not showing up, help!

2450
11
01-18-2012 05:39 AM
by Anonymous User
Not applicable
So I've been using a few of the samples to put an application together, I'm not a JavaScript coding expert, so this should be easy for those who are.
I want the app to Geocode, then do a spatial query on that geocoded point, highlight the feature and show an infoWindow. I also would like to be able to query by clicking. Bottom line: all of that works EXCEPT showing the infoWindow after the geocde spatial query, the info window DOES show when I click on the map. I think it has to do with this line:
(evt) ? map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)) : null;

Below is the relevant code, please help! (some code has been removed because I know it works and is not relevant to te problem)
 
//Click Query Functions
function clickQuery(evt) {
esri.show(dojo.byId('loadingImg'));
map.infoWindow.hide();
map.graphics.clear();
featureSet = null;
//onClick event returns the evt point where the user clicked on the map.
//This contains the mapPoint (esri.geometry.point) and the screenPoint (pixel xy where the user clicked).
//set query geometry = to evt.mapPoint Geometry
geom = evt.mapPoint;
query.geometry = geom;
query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
//Execute task and call showResults on completion
queryTask.execute(query, function(fset) {
if (fset.features.length === 1) {
showFeature(fset.features[0],evt);} 
else {esri.hide(dojo.byId('loadingImg'));
}
});
}
 
//Geocode query function
function geoQuery(loc) { 
var geom = new esri.geometry.Point(loc.x,loc.y, map.spatialReference);  
query.geometry = geom;
query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
queryTask.execute(query, function(fset) {
if (fset.features.length === 0) {
showError();
} 
else if (fset.features.length === 1) {
showFeature(fset.features[0],evt);
} 
else {
esri.hide(dojo.byId('loadingImg'));
}
});
}
 
// Query Show Feature
function showFeature(feature,evt) {

//set symbol
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, 
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, 
new dojo.Color([102,204,0]),3), new dojo.Color([102,204,0,0.6]));
  
feature.setSymbol(symbol);
    
//construct infowindow title and content
var attr = feature.attributes;
 
map.infoWindow.setTitle("My Title");
map.infoWindow.setContent("My infoWindow Content");

map.graphics.add(feature);

(evt) ? map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)) : null;

map.setExtent(feature.geometry.getExtent(),true);  
}
0 Kudos
11 Replies
derekswingley1
Deactivated User
Using evt as a global is still likely the root of the problem. Try using some console.log statements in your showFeature function to see what evt actually is. Or you could use breakpoints, whatever you're comfortable with.
0 Kudos
by Anonymous User
Not applicable
I got it to work!!

Although I don't really know what I'm doing, I've been looking at an app that does the same thing. I kept evt as a global variable, and this is at the end of my showFeature function:
var point = map.toScreen(geom)
map.infoWindow.show(point,map.getInfoWindowAnchor(point));


It won't work without evt  being a global.
0 Kudos