How to get extent out of

1305
8
Jump to solution
04-28-2014 01:25 PM
GyeyoungChoi
Deactivated User
function getLocRes(results) {  map.graphics.clear();  var geom;  var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([80, 0, 0]), 2), new dojo.Color([80, 0, 0, 0.5]));  var res = results.features;  for (var i = 0;i < res.length; i++) {   geom += results.features.geometry;   var graphic = results.features;   //var graphic = new Graphic(reGeo,symbol);   graphic.setSymbol(symbol);   map.graphics.add(graphic);  }  var extent = geom.getExtent();  map.setExtent(extent, true); }


query.where = Abbrev = 'abc' OR Abbrev = 'def' OR Abbrev = 'ghi'
selected features are polygons
did some stupid thinking like
 geom += results.features.geometry; 

but didnt work

Can you help me with this?

Thank you for your time
0 Kudos
1 Solution

Accepted Solutions
JeffPace
MVP Alum
like i said, i wasnt sure if you could union a null extent and a valid extent

try calling  graphicsUtils.graphicsExtent() on your "res" variable to give you the extent

https://developers.arcgis.com/javascript/jsapi/esri.graphicsutils-amd.html#graphicsextent

View solution in original post

0 Kudos
8 Replies
JeffPace
MVP Alum
you cant just append a bunch of geometries together and get the combined extent.

try (not sure union will work with an inital null extent)

function getLocRes(results) {
 map.graphics.clear();
 var geom;
       var combinedExtent = new Extent();
 var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([80, 0, 0]), 2), new dojo.Color([80, 0, 0, 0.5]));
 var res = results.features;
 for (var i = 0;i < res.length; i++) {
  geom = results.features.geometry.getExtent();
                combinedExtent = combinedExtent.union(geom);
  var graphic = results.features;
  //var graphic = new Graphic(reGeo,symbol);
  graphic.setSymbol(symbol);
  map.graphics.add(graphic);
 }
 
 map.setExtent(combinedExtent , true);
}
0 Kudos
JonathanUihlein
Esri Regular Contributor
This is a function I use to calculate the extent of an array of Graphic objects.

    _calcGraphicsExtent: function (graphicsArray) {
      var g = graphicsArray[0].geometry,
        fullExt = g.getExtent(),
        ext, i, il = graphicsArray.length;
      if (fullExt === null) {
        fullExt = new Extent(g.x, g.y, g.x, g.y, g.spatialReference);
      }
      for (i = 1; i < il; i++) {
        g = graphicsArray.geometry;
        ext = g.getExtent();
        if (ext === null) {
          ext = new Extent(g.x, g.y, g.x, g.y, g.spatialReference);
        }
        fullExt = fullExt.union(ext);
      }
      return fullExt;
    }


0 Kudos
JeffPace
MVP Alum
sure jon, way to post something functional and elegant and make mine look like ***

🙂

OP, use jon's solution. Its much more complete.
0 Kudos
JohnGravois
Deactivated User
haha.

perhaps im missing something, but why not just use graphicsUtils.graphicsExtent() ?
0 Kudos
GyeyoungChoi
Deactivated User





Thank you y'all

I'll try both!
0 Kudos
GyeyoungChoi
Deactivated User
you cant just append a bunch of geometries together and get the combined extent.

try (not sure union will work with an inital null extent)

function getLocRes(results) {
 map.graphics.clear();
 var geom;
       var combinedExtent = new Extent();
 var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([80, 0, 0]), 2), new dojo.Color([80, 0, 0, 0.5]));
 var res = results.features;
 for (var i = 0;i < res.length; i++) {
  geom = results.features.geometry.getExtent();
                combinedExtent = combinedExtent.union(geom);
  var graphic = results.features;
  //var graphic = new Graphic(reGeo,symbol);
  graphic.setSymbol(symbol);
  map.graphics.add(graphic);
 }
 
 map.setExtent(combinedExtent , true);
}


function getLocRes(results) {
 //map.graphics.clear();
 var geom;
 //
 var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([80, 0, 0]), 2), new dojo.Color([80, 0, 0, 0.5]));
 var res = results.features;
 var combinedExtent = new esri.geometry.Extent();
 for (var i = 0;i < res.length; i++) {
  geom = results.features.geometry.getExtent();
  combinedExtent = combinedExtent.union(geom);
  var graphic = results.features;
  //var graphic = new Graphic(reGeo,symbol);
  graphic.setSymbol(symbol);
  map.graphics.add(graphic);
 }
 var extent = geom.getExtent();
 //alert(map.graphics.graphics.length);
 map.setExtent(combinedExtent, true);
}

[ATTACH=CONFIG]33429[/ATTACH]
got an error 😞 that I don't understand  :0
0 Kudos
JeffPace
MVP Alum
like i said, i wasnt sure if you could union a null extent and a valid extent

try calling  graphicsUtils.graphicsExtent() on your "res" variable to give you the extent

https://developers.arcgis.com/javascript/jsapi/esri.graphicsutils-amd.html#graphicsextent
0 Kudos
GyeyoungChoi
Deactivated User
like i said, i wasnt sure if you could union a null extent and a valid extent

try calling  graphicsUtils.graphicsExtent() on your "res" variable to give you the extent

https://developers.arcgis.com/javascript/jsapi/esri.graphicsutils-amd.html#graphicsextent


Thanks Jeff, finally made it
0 Kudos