AnsweredAssumed Answered

How can I get the search widget to work again once I have destroyed and recreated a map?

Question asked by on May 6, 2016
Latest reply on May 9, 2016 by

I am a GIS Specialist but a relative noob when it comes to JavaScript, so bear with me...


I am writing a script that allows users to choose between two different maps, using two different projections, by choosing between two radio buttons. When the user clicks on a radio button, the previous map is destroyed and a new one is created. I can get an on-click event to work on the new map, and I can get the scalebar to work on the new map. However, even though I can see the Search widget, and it does list addresses correctly, when I click on an address, nothing happens.


The refresh of the map is done like this:


map = new Map("map", {extent: mapextent});



The scalebar code, which works, is


scalebar = new Scalebar({map: map, scalebarUnit: "dual"});


If I try the same with the Search widget...


search = new Search({map: map}, "search");



...then the search isn't displayed at all. If I declare search as a new variable...


var search = new Search({map: map}, "search");



...then I can see the search widget, and it will list results, but when I click on a result, nothing happens (i.e. no marker is placed on the map and the map doesn't zoom to the location. I would guess it is something to do with the search widget not recognising the new map object, but then why does the scalebar work?


Any help much appreciated.