Select to view content in your preferred language

need map to include all surrounding areas

1127
7
Jump to solution
01-23-2012 05:48 AM
TonyRopson
Emerging Contributor
I am attempting to have a map that highlights areas within a certain mile radius of a user selected point.  I am using a query task to return the geometry of those areas but I am having some trouble expanding the map to include all the areas returned by the query task.  Code snippets:
  function init() {             map = new esri.Map("mapDiv");             var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://lrs.co.columbia.wi.us/ArcGIS/rest/services/LRS/TaxParcels_Parcels/MapServer")             map.addLayer(layer);     for (j = 0; j < parnums.length; j++) {                 queryTask = new esri.tasks.QueryTask("http://lrs.co.columbia.wi.us/ArcGIS/rest/services/LRS/TaxParcels_Parcels/MapServer/1");                 query = new esri.tasks.Query();                 query.returnGeometry = true;                 query.text = parnums                 queryTask.execute(query, gettingResults);      function gettingResults(resultFeatures) {    featholding.push(resultFeatures); // this is the area the end user selected  var newExtent = esri.graphicsExtent(SearchPar[0].features)  //this is where I attempt to enclude the other areas that were returned by the  queryTask  for (j = 0; j < featholding.length; j++){                 var Uextent=esri.graphicsExtent(featholding.features)                 newExtent.union(Uextent)              }                               map.setExtent(newExtent.expand(1.1),true); }


I found union in the api docs but I am wondering if I am using it correctly
Thanks
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Deactivated User
Ah, OK. So you're doing multiple queries and want to zoom to the extent of the features returned by all queries, correct?

If that's the case, i'd recommend using a deferredList so that you know when all the queries finish. We discussed this approach on the forums before...see this thread:  http://forums.arcgis.com/threads/37417

View solution in original post

0 Kudos
7 Replies
derekswingley1
Deactivated User
You're on the right track. Instead of looping through all your features and unioning their extents, pass all your features to esri.graphicsExtent. Then set the map's extent, something like...
var newExtent = esri.graphicsExtent(resultFeatures);
map.setExtent(newExtent, true);
0 Kudos
TonyRopson
Emerging Contributor
I switched things up a bit and have this
function init() {
            map = new esri.Map("mapDiv");
            var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://lrs.co.columbia.wi.us/ArcGIS/rest/services/LRS/TaxParcels_Parcels/MapServer")
            map.addLayer(layer);


  for (j = 0; j < parnums.length; j++) {
                queryTask = new esri.tasks.QueryTask("http://lrs.co.columbia.wi.us/ArcGIS/rest/services/LRS/TaxParcels_Parcels/MapServer/1");
                query = new esri.tasks.Query();
                query.returnGeometry = true;
                query.text = parnums
                queryTask.execute(query, gettingResults);


   function gettingResults(resultFeatures) {
   featholding.push(resultFeatures);
// this is the area the end user selected
 var newExtent = esri.graphicsExtent(SearchPar[0].features)

//this is where I attempt to enclude the other areas that were returned by the  queryTask
 for (j = 0; j < featholding.length; j++){
                 newExtent = esri.graphicsExtent(featholding.features);             }
             }

map.setExtent(newExtent.expand(1.1),true);


however it appears that the map.setExtent is being set to the last piece of geometry in the array.  Is there are way to have the map include all the extents being passed in instead of the last one.

Also I tried
  newExtent=esri.graphicsExtent(resultFeatures);
            map.setExtent(newExtent, true);

but the map was not doing any focusing at all.
0 Kudos
derekswingley1
Deactivated User
In your gettingResults function, wouldn't you just want to use the extent of resultFeatures?
0 Kudos
TonyRopson
Emerging Contributor
yes I would but when I use
function gettingResults(resultFeatures) {

 featholding.push(resultFeatures);
                newExtent = esri.graphicsExtent(resultFeatures.features)
                map.setExtent(newExtent, true);
}

All it is doing is showing the last piece of geometry that it was sent by the query task.  The query task is sending gettingResults about 8-10 separate pieces of geometry and I would like the map to be expanded to show them all. 

   This is the last piece of the puzzle before this goes into production, so I very much appreciate the help everyone is giving me on this.
0 Kudos
derekswingley1
Deactivated User
Are you running more than one query task?
0 Kudos
TonyRopson
Emerging Contributor
one query task but it does get called many times
  for (j = 0; j < parnums.length; j++) {
                queryTask = new esri.tasks.QueryTask("http://lrs.co.columbia.wi.us/ArcGIS/rest/services/LRS/TaxParcels_Parcels/MapServer/1");
                query = new esri.tasks.Query();
                query.returnGeometry = true;
                query.text = parnums
                queryTask.execute(query, gettingResults);
}

I will like to fit the results of the returned geometry into the viewer.
0 Kudos
derekswingley1
Deactivated User
Ah, OK. So you're doing multiple queries and want to zoom to the extent of the features returned by all queries, correct?

If that's the case, i'd recommend using a deferredList so that you know when all the queries finish. We discussed this approach on the forums before...see this thread:  http://forums.arcgis.com/threads/37417
0 Kudos