coincident points - extent

3804
4
Jump to solution
03-10-2015 07:15 AM
PeggyCorey
New Contributor

I need to check for coincident points being returned from a FindTask, in order to zoom to the proper extent.  I am currently zooming using a centerAndZoom for single points, and using a setExtent for lines, polygons and multiple points.  But this will not work properly if the results set is a pair of coincident points, for example.  Below is a sample of my current zoom code, but I need a solution for this coincident point scenario. 

Anyone solved this kind of problem? 

Thanks!

if (graphictype == "point" && map.graphics.graphics.length == 1) {

  map.centerAndZoom(map.graphics.graphics[0].geometry,20);

}

else {

  var extent = esri.graphicsExtent(map.graphics.graphics);

  map.setExtent(extent.expand(2), true);

}

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Peggy,

  Try something like this:

if (graphictype == "point" && map.graphics.graphics.length == 1) {
  map.centerAndZoom(map.graphics.graphics[0].geometry,20);
} else if (graphictype == "point" && map.graphics.graphics.length > 1 && !esri.graphicsExtent(map.graphics.graphics)){
  map.centerAndZoom(map.graphics.graphics[0].geometry,20);
} else {
  var extent = esri.graphicsExtent(map.graphics.graphics);
  map.setExtent(extent.expand(2), true);
}

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Peggy,

   So does the coincident points produce an extent using graphicsExtent? if they do then you can check the width of the extent and if it does not return a predetermined size then fallback to using centerAndZoom. If the coincident points  do not produce an extent using graphicsExtent then same thing fallback to centerAndZoom.

0 Kudos
PeggyCorey
New Contributor

Thanks for the suggestions Robert.

No, the coincident points do not produce and extent using graphicsExtent.

I know how to use centerAndZoom to zoom to 1 graphic.  But how do I use it to zoom to multiples?

OR

How do I check for coincidence?

Thanks!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Peggy,

  Try something like this:

if (graphictype == "point" && map.graphics.graphics.length == 1) {
  map.centerAndZoom(map.graphics.graphics[0].geometry,20);
} else if (graphictype == "point" && map.graphics.graphics.length > 1 && !esri.graphicsExtent(map.graphics.graphics)){
  map.centerAndZoom(map.graphics.graphics[0].geometry,20);
} else {
  var extent = esri.graphicsExtent(map.graphics.graphics);
  map.setExtent(extent.expand(2), true);
}
PeggyCorey
New Contributor

Robert,

Thanks... that worked perfectly!

0 Kudos