I need to do a selectFeatures on a featureLayer based on a geocoded point. I also want them to be able to get information when they click around on the map, so I have a infoTemplate set on the featureLayer.
If the user enters an address, the anchor to the popup appears where I expect, tied to the geocoded symbol. If the user then clicks around on the map and then goes back to entering an address, the anchor to the popup ends up set to the last map click, rather than the geocoded location.
What am I doing wrong?
Here are my definitions:
var popup = new Popup({
markerSymbol: new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 22,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 255, 0]), 2),
new Color([255, 255, 0, 0.5])),
fillSymbol: highlightFillSymbol}, domConstruct.create("div"));
var infoTemplate = new InfoTemplate("Poverty Status");
infoTemplate.setContent(setInfoContent);
var featureLayer = new FeatureLayer(featureLayerUrl, { mode: FeatureLayer.MODE_ONDEMAND, outFields: ['*'],
infoTemplate: infoTemplate,
opacity: 0.6
});
Here are the relevant functions:
function setInfoContent(graphic){
var per = formatPercentage(graphic.attributes.pov_perc);
return "Percentage Poverty: " + per;
}
function showLocation(evt){
map.graphics.clear();
var startPoint = evt.result.feature.geometry;
addr = evt.result.name;
map.centerAndZoom(startPoint, 13);
var graphic = new Graphic(startPoint, geoSymbol);
map.graphics.add(graphic);
popup.show(startPoint);
var query = new Query();
query.geometry = startPoint;
query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
var per = formatPercentage(results[0].attributes.pov_perc);
popup.setContent(addr + "</br> Percentage Poverty: " + per);
dom.byId('povStatus').innerHTML = "Census tract is eligible, with a poverty percentage of " + per;
});
}Here is a link:Poverty Tract Search
Suggested input address: 301 W High St, Jefferson City, MO