Select to view content in your preferred language

Silverlight Equivalent to Flex API's map.extent.containsExtent Method

620
3
10-28-2010 02:39 PM
AndyWright
Frequent Contributor
I have a situation where after the user performs a search, I automatically zoom to the location of the selected feature at a pre-defined scale.  Every once in a while the extent of the polygon feature is larger than the map extent after it has been zoomed to the pre-defined scale.  In the Flex API there was a nice method on the map extent called containsExtent.  You passed in another extent to that method and it would return a boolean saying whether or not the current map extent fully contained the passed in map extent.

So I could run this code that would let me know if the extent of my selected polygon was not contained by the current map extent.  Then I could back the map's level out a notch so the current map view would display my selected feature in its entirety.

if (!map.extent.containsExtent(selectedFeatureExtent))
{
     map.level--;
}

The only semi-valuable property I see on envelope objects in the Silverlight API is intersects, but this won't perform the same type of function that containsExtent does.  Can anyone provide me with a nudge in the right direction on this one?

Thanks a ton ...


Andy
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
You can call Map.ZoomTo(Geometry geometry) to zoom to the feature's geometry.

To check whether the feature's geometry is within the map's extent, you can do where env is the graphic's Geometry.Extent
  private bool IsWithin(Envelope env)
  {
   return (env.XMin >= Map.Extent.XMin &&
    env.XMax <= Map.Extent.XMax &&
    env.YMin >= Map.Extent.YMin &&
    env.YMax <= Map.Extent.YMax);
  }
0 Kudos
AndyWright
Frequent Contributor
Thanks for the workaround Jennifer, I really appreciate the code sample.  That will get me where I need to be on this.  It would be great though if there were more similarities between methods in the Flex and Silverlight APIs.  You would think the two would have a ton of the same type of functionality.
0 Kudos
JenniferNery
Esri Regular Contributor
I failed to mention about Intersects method http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Geometry.E...

To figure out if the graphic's geometry belongs in the map's extent you can use this check:
 if (graphic.Geometry.Extent.Intersects(Map.Extent)) 


Intersects also check for the SpatialReference.
0 Kudos