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.destroy();
map = new Map("map", {extent: mapextent});
map.addLayer(baseMapLayer);
The scalebar code, which works, is
scalebar.destroy()
scalebar = new Scalebar({map: map, scalebarUnit: "dual"});
If I try the same with the Search widget...
search.destroy();
search = new Search({map: map}, "search");
search.startup();
...then the search isn't displayed at all. If I declare search as a new variable...
search.destroy();
var search = new Search({map: map}, "search");
search.startup();
...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.