function startGeocoder() { geocoder = new Geocoder({ map : map, arcgisGeocoder : { placeholder : "Address search", sourceCountry : "GBR" } }, "search"); geocoder.autoComplete = true; geocoder.startup(); geocoder.on("select", queryLayer); } function queryLayer(evt){ popup.hide(); selectTariffLayer.clearSelection(); var point = evt.result.feature.geometry; var query = Query(); query.geometry = point; selectTariffLayer.selectFeatures(query, selectTariffLayer.SELECTION_NEW, function(results){ var charge = results[0].attributes["Charge"]; var price = results[0].attributes["Cost"]; popup.setTitle("Parking tariffs"); popup.setContent(charge + "<br/>" + price); popup.show(point); }); }
Hi, really sorry for the delay in getting back to you, I got pulled onto another project. Yeah, here it is:
Edit fiddle - JSFiddlehttp://jsfiddle.net/nPqS8/
There seems to be two problems.
1. If searching for addresses in the same polygon, sometimes after searching for a second consecutive address in the same polygon, the map starts to zoom to the second address and then the zoom jumps back to the first address.
2. If searching for addresses in the same polygon in the feature layer that is being queried, sometimes after searching for a new address in the same polygon, the extent changes to centre on the new address but the popup containing the information about that polygon remains displayed over the old address.
Here are some example addresses that should highlight the problems:
These problems don't seem to occur if searching for addresses that fall into different polygons from the previously selected polygon.
Cheers
I don't know if this would be a solution for you, but when I have problems with anything that generates output results, like featureLayer.selectFeatures, it helps me to separate it out to an event listener and an resultsHandler. You could try adding a selection-complete handler on your featureLayer and move your function to a separate resultsHandler that would execute only when your selection is complete. Sometimes the problem is the results handler is running before the execute is really fully finished.
The frustrating thing too is that if you add breakpoints it sometimes works! It can be because the pause of a breakpoint was just enough time for the query to finish.
Hmmm, if you comment out popup.show(point) the error goes away, seems like the error is coming from the calling popup.show so it could be something funky with the point your passing to it although the json for that looks fine.
I think I have a solution for you. Try out this fiddle and see if it works, I was able to get it to not show the onAnimateEnd errors. I took the popup show out of the callback you had passed to selectFeatures and set the response as a deferred which you then pass into the popup via popup.setFeatures([def]); I then added a popup.clearFeatures() to the beginning of the queryLayer function to make sure there are no previously selected features there. Here is the fiddle url and the relevant code is below. http://jsfiddle.net/nPqS8/4/
function queryLayer(evt){ popup.hide(); popup.clearFeatures(); selectTariffLayer.clearSelection(); var point = evt.result.feature.geometry; var query = Query(); query.geometry = point; var def = selectTariffLayer.selectFeatures(query, selectTariffLayer.SELECTION_NEW, function(results){ var charge = results[0].attributes["Charge"]; var price = results[0].attributes["Cost"]; popup.setTitle("Parking tariffs"); popup.setContent(charge + "<br/>" + price); }); popup.setFeatures([def]); popup.show(point); }
Thanks very much Robert for the fix and thanks Tracey for the suggestions. Yes Robert, it does work just fine.
That's great both of you, really appreciated.
Cheers,
Mike