I'm having a similar problem with map.setExtent().It will work the first time that I try it, but will refuse to set the extent after that.Here is how I load my features into my map.
function onResults(results) {
var features = results.features;
var len = features.length;
annexDict = {};
map.graphics.clear();
var sel = dojo.byId("annexSelect");
while (sel.hasChildNodes()) {
sel.removeChild(sel.lastChild);
}
var j = 0;
for (j = 0; j < features.length; j++) {
var feature = features;
var item = feature.attributes;
var c = dojo.doc.createElement("option");
c.innerHTML = "TEST: " + item.ANNEXATION;
c.value = item.ANNEXATION;
sel.appendChild(c);
annexDict[c.value] = {
annex: item.ANNEXATION,
graphic: feature
}
map.graphics.add(feature);
}
}
My results get added a Multiselect list and a dictionary object.Then when an item in the list is clicked, I handle it like this.
function onAnnexInListClicked(e) {
console.log("option was clicked");
if (e.target) {
try {
var targ = e.target;
console.log(targ.value);
var item = annexDict[targ.value];
console.log("from dictionary: Annexation = " + item.annex);
var g = item.graphic;
var geom = g.geometry;
var ext = geom.getExtent();
// tried to explicitly create a new extent, but same result
var xmin = ext.xmin;
var ymin = ext.ymin;
var xmax = ext.xmax;
var ymax = ext.ymax;
var sr = new esri.SpatialReference({wkid: 102100});
var gExt = new esri.geometry.Extent(xmin, ymin, xmax, ymax, sr);
map.setExtent(gExt);
// map.setExtent(ext); // this had the same result
console.log("map extent changed");
} catch(err) {
console.log("error in setting map extent to graphic extent");
console.log(err);
}
}
}
The first time an item is clicked, the map will zoom to the proper location.After that, all subsequent requests to change the map extent seem to have no effect. My console traces show that I am clicking on a new item and no errors are being thrown, so I'm a bit stumped at this point.Any help would be appreciated, thanks.