Hi,
I am running a query to select a number of polygons based on an intersecting polygon. The selected polygons are contiguous and are highlighted when the query is complete. I am trying to set the map extent to the extent of all these polygons combined together but have been unsuccessful. I have tried suggestions posted on these forums and using samples provided by ESRI but am still unable to get the map to zoom to this area. I have tried creating an array to push graphics inside it. I have also tried creating a polygon feature, a feature set and a graphicsLayer as a container to hold all the selected graphics, but it didn't work. I am using ArcGIS Server 9.3 with JavaScript API. Please help.
(Note: The code below has been extracted from a longer version. It might be missing some braces)
function findPolygonsInExtent(extent) {
var graphics = map.graphics.graphics;
var attr =[];
var items = [];
var graphic;
var len=0;
for (var i=0, il=graphics.length; i<il; i++) {
graphic = graphics;
if (extent.intersects(graphic.geometry)) {
len = len + 1;
var results = [];
graphic.setSymbol(highlightSymbol);
var featureAttributes = graphic.attributes;
for (att in featureAttributes) {
var s = featureAttributes[att];
results.push(s);
}
attr = results.slice(0,10);
for(var j=0, jl=10; j<jl; j++)
{
items.push(attr);
}
} //if
else if (graphic.symbol == highlightSymbol) {
graphic.setSymbol(symbol);
}
} //for
map.setExtent(//some polygon feature//.geometry.getExtent());
}
Thanks Heming,
I looked up ARcGIS resource Center but could not find any example to use esri.graphicsExtent function. I'll really appreciate it if you can guide me a bit more.
Thanks
Samir
Hi,
I am running a query to select a number of polygons based on an intersecting polygon. The selected polygons are contiguous and are highlighted when the query is complete. I am trying to set the map extent to the extent of all these polygons combined together but have been unsuccessful. I have tried suggestions posted on these forums and using samples provided by ESRI but am still unable to get the map to zoom to this area. I have tried creating an array to push graphics inside it. I have also tried creating a polygon feature, a feature set and a graphicsLayer as a container to hold all the selected graphics, but it didn't work. I am using ArcGIS Server 9.3 with JavaScript API. Please help.
(Note: The code below has been extracted from a longer version. It might be missing some braces)
function findPolygonsInExtent(extent) {
var graphics = map.graphics.graphics;
var attr =[];
var items = [];
var graphic;
var len=0;
var intersectedGraphics =[];
for (var i=0, il=graphics.length; i<il; i++) {
graphic = graphics;
if (extent.intersects(graphic.geometry)) {
intersectedGraphics.push(graphic);
len = len + 1;
var results = [];
graphic.setSymbol(highlightSymbol);
var featureAttributes = graphic.attributes;
for (att in featureAttributes) {
var s = featureAttributes[att];
results.push(s);
}
attr = results.slice(0,10);
for(var j=0, jl=10; j<jl; j++)
{
items.push(attr);
}
} //if
else if (graphic.symbol == highlightSymbol) {
graphic.setSymbol(symbol);
}
} //for
var extent =esri.graphicsExtent(intersectedGraphics);
map.setExtent(extent);
}
I'm doing this same thing, using the same method. It works for me some of the time. I have a map that puts a route on there, similar to driving directions you'd get from Google maps and whatnot. Sometimes, it zooms in perfectly. Sometimes it zooms in too far, so it cuts the part of the route off. Any idea what would cause this?