# Full Extent Of Map

**URL:** <https://community.thinkgeo.com/t/full-extent-of-map/2773>\
**Category:** WPF\
**Created:** [August 13, 2010, 6:07am UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773 "2010-08-13T06:07:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![G11](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/ba9def/32.png) [@G11](https://community.thinkgeo.com/u/G11)\
**Post date:** [August 13, 2010, 6:07am UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/1 "2010-08-13T06:07:49Z")

</div>

Hi,

&nbsp;&nbsp;&nbsp;I&nbsp;want&nbsp;to&nbsp;view&nbsp;all&nbsp;the&nbsp;layers&nbsp;i&nbsp;loaded&nbsp;into&nbsp;WPFMap&nbsp;control&nbsp;in&nbsp;a&nbsp;full&nbsp;extent.&nbsp;What&nbsp;i&nbsp;mean&nbsp;is,&nbsp;&nbsp;In&nbsp;MapSuiteExplorer&nbsp;(Available&nbsp;with&nbsp;installer)&nbsp;when&nbsp;we&nbsp;add&nbsp;a&nbsp;layer&nbsp;it&nbsp;automatically&nbsp;loads&nbsp;the&nbsp;layer&nbsp;covering&nbsp;the&nbsp;whole&nbsp;WPFMap&nbsp;control.

&nbsp;&nbsp;Here&nbsp;is&nbsp;my&nbsp;code&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mapControl.CurrentExtent&nbsp;=&nbsp;ExtentHelper.GetBoundingBoxOfItems( **rectangleShapes** );

\ ***rectangleShapes&nbsp;** contains&nbsp;all&nbsp;the&nbsp;layers&nbsp;co-ordinates.&nbsp;(rectangleShapes.Add(Layer1.GetBoundingBox());&nbsp;rectangleShapes.Add(Layer2.GetBoundingBox());&nbsp;rectangleShapes.Add(Layer3.GetBoundingBox());)

The&nbsp;above&nbsp;particular&nbsp;code&nbsp;is&nbsp;not&nbsp;strecthing&nbsp;the&nbsp;layers&nbsp;to&nbsp;the&nbsp;wpfMapControl&nbsp;size.&nbsp;  
  
Please&nbsp;help&nbsp;me&nbsp;in&nbsp;achieving&nbsp;this.

Thanks

Ranjith

---

<div class="post-metadata">

**Author:** ![Behnam](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/b4bc9f/32.png) [@Behnam](https://community.thinkgeo.com/u/Behnam)\
**Post date:** [August 13, 2010, 6:42am UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/2 "2010-08-13T06:42:36Z")

</div>

Hi,&nbsp;  
  
  
  
please&nbsp;refer&nbsp;to&nbsp;the&nbsp;below&nbsp;sample:&nbsp;  
  
[code.thinkgeo.com/projects/show/zoomtofullextent&nbsp;](http://code.thinkgeo.com/projects/show/zoomtofullextent)

Regards

---

<div class="post-metadata">

**Author:** ![G11](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/ba9def/32.png) [@G11](https://community.thinkgeo.com/u/G11)\
**Post date:** [August 13, 2010, 7:13am UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/3 "2010-08-13T07:13:03Z")

</div>

Thanks&nbsp;for&nbsp;your&nbsp;quick&nbsp;reply&nbsp;Ben.&nbsp;I&nbsp;am&nbsp;using&nbsp;WPFmapControl&nbsp;in&nbsp;my&nbsp;application&nbsp;to&nbsp;load&nbsp;layers.&nbsp;The&nbsp;one&nbsp;in&nbsp;the&nbsp;website&nbsp;is&nbsp;not&nbsp;helping&nbsp;me&nbsp;as&nbsp;they&nbsp;are&nbsp;using&nbsp;PictureBox&nbsp;control&nbsp;and&nbsp;map&nbsp;engine.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards&nbsp;  
&nbsp;Ranjith&nbsp;

---

<div class="post-metadata">

**Author:** ![Behnam](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/b4bc9f/32.png) [@Behnam](https://community.thinkgeo.com/u/Behnam)\
**Post date:** [August 13, 2010, 7:22am UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/4 "2010-08-13T07:22:08Z")

</div>

you&nbsp;can&nbsp;read&nbsp;the&nbsp;each&nbsp;layer&nbsp;extent&nbsp;by&nbsp;GetBoundingBox()&nbsp;command&nbsp;and&nbsp;then&nbsp;add&nbsp;them&nbsp;to&nbsp;collection&nbsp;of&nbsp;BaseShape,&nbsp;then&nbsp;you&nbsp;can&nbsp;use&nbsp;the&nbsp;&nbsp;ExtentHelper.GetDrawingExtent&nbsp;to&nbsp;obtain&nbsp;the&nbsp;full&nbsp;extent:&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Map.CurrentExtent&nbsp;=&nbsp;ExtentHelper.GetDrawingExtent(ExtentHelper.GetBoundingBoxOfItems(rectangleShapes),&nbsp;(float)Map.width,&nbsp;(float)Map.height);&nbsp;  
&nbsp;Map.Refresh();&nbsp;  
&nbsp;&nbsp;  
&nbsp;regards

---

<div class="post-metadata">

**Author:** ![Val](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e56c9b/32.png) [@Val](https://community.thinkgeo.com/u/Val)\
**Post date:** [August 13, 2010, 12:27pm UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/5 "2010-08-13T12:27:29Z")

</div>

From&nbsp;the&nbsp;code&nbsp;of&nbsp;the&nbsp;Code&nbsp;Community&nbsp;Services&nbsp;edtion&nbsp;project,&nbsp;to&nbsp;have&nbsp;it&nbsp;working&nbsp;with&nbsp;WPF,&nbsp;you&nbsp;can&nbsp;use&nbsp;the&nbsp;code&nbsp;below.&nbsp;You&nbsp;can&nbsp;see&nbsp;that&nbsp;there&nbsp;is&nbsp;not&nbsp;a&nbsp;big&nbsp;difference:

&nbsp;

`private void Window_Loaded(object sender, RoutedEventArgs e){    wpfMap1.MapUnit = GeographyUnit.DecimalDegree;    wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);    //Adds countries and capitals shapefiles.    ShapeFileFeatureLayer Layer1 = new ShapeFileFeatureLayer(@"..\..\Data\countries02.shp");    Layer1.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.LightGreen, GeoColor.StandardColors.Black);    Layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;    ShapeFileFeatureLayer Layer2 = new ShapeFileFeatureLayer(@"..\..\Data\worldcapitals.shp");    Layer2.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1;    Layer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;    LayerOverlay layerOverlay = new LayerOverlay();    layerOverlay.Layers.Add("Layer1", Layer1);    layerOverlay.Layers.Add("Layer2", Layer2);    wpfMap1.Overlays.Add("Layers", layerOverlay);    wpfMap1.CurrentExtent = GetFullExtent(layerOverlay.Layers);    wpfMap1.Refresh();}//Function for getting the extent based on a collection of layers.//It gets the overall extent of all the layers.private RectangleShape GetFullExtent(GeoCollection<Layer> Layers){    Collection<BaseShape> rectangleShapes = new Collection<BaseShape>();    foreach (Layer layer in Layers)    {        layer.Open();        if (layer.HasBoundingBox == true) rectangleShapes.Add(layer.GetBoundingBox());    }    return ExtentHelper.GetBoundingBoxOfItems(rectangleShapes);}`

---

<div class="post-metadata">

**Author:** ![G11](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/ba9def/32.png) [@G11](https://community.thinkgeo.com/u/G11)\
**Post date:** [August 19, 2010, 2:27pm UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/6 "2010-08-19T14:27:34Z")

</div>

Thanks&nbsp;everyone&nbsp;for&nbsp;the&nbsp;replies.&nbsp;My&nbsp;requirement&nbsp;is&nbsp;that&nbsp;when&nbsp;u&nbsp;load&nbsp;a&nbsp;layer&nbsp;it&nbsp;has&nbsp;to&nbsp;strecth&nbsp;to&nbsp;the&nbsp;full&nbsp;extent&nbsp;of&nbsp;the&nbsp;map&nbsp;control&nbsp;as&nbsp;shown&nbsp;in&nbsp;the&nbsp;below&nbsp;image.&nbsp;Please&nbsp;verify&nbsp;the&nbsp;Map&nbsp;Suite&nbsp;Explorer&nbsp;which&nbsp;comes&nbsp;along&nbsp;with&nbsp;the&nbsp;installer.&nbsp;  
&nbsp;Regards&nbsp;

---

<div class="post-metadata">

**Author:** ![Val](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e56c9b/32.png) [@Val](https://community.thinkgeo.com/u/Val)\
**Post date:** [August 19, 2010, 10:51pm UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/7 "2010-08-19T22:51:46Z")

</div>

We&nbsp;did&nbsp;not&nbsp;get&nbsp;the&nbsp;image.&nbsp;Can&nbsp;you&nbsp;send&nbsp;it&nbsp;again&nbsp;as&nbsp;it&nbsp;will&nbsp;help&nbsp;us&nbsp;understand&nbsp;more&nbsp;easily&nbsp;what&nbsp;you&nbsp;are&nbsp;trying&nbsp;to&nbsp;achieve?&nbsp;Thank&nbsp;you.

---

<div class="post-metadata">

**Author:** ![G11](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/ba9def/32.png) [@G11](https://community.thinkgeo.com/u/G11)\
**Post date:** [August 20, 2010, 2:18am UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/8 "2010-08-20T02:18:50Z")

</div>

Hi&nbsp;Val,&nbsp;  
&nbsp;&nbsp;&nbsp;I&nbsp;had&nbsp;set&nbsp;my&nbsp;WPFControl’s&nbsp;height&nbsp;and&nbsp;width&nbsp;as&nbsp;600&nbsp;and&nbsp;1000&nbsp;respectively.&nbsp;Loaded&nbsp;8&nbsp;different&nbsp;shape&nbsp;files&nbsp;on&nbsp;the&nbsp;control&nbsp;and&nbsp;set&nbsp;the&nbsp;current&nbsp;extent&nbsp;as&nbsp;suggested&nbsp;in&nbsp;your&nbsp;previous&nbsp;post.&nbsp;when&nbsp;i&nbsp;debug&nbsp;i&nbsp;got&nbsp;current&nbsp;extent&nbsp;as&nbsp;{-4077.26966075121,3354.28020964718,3745.40009563083,-1339.32164418204}.&nbsp;Still&nbsp;the&nbsp;features&nbsp;in&nbsp;the&nbsp;shape&nbsp;files&nbsp;are&nbsp;not&nbsp;stretching&nbsp;to&nbsp;the&nbsp;my&nbsp;WPFControl’s&nbsp;height&nbsp;and&nbsp;width.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;  
&nbsp;Ranjith

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [August 20, 2010, 3:40am UTC](https://community.thinkgeo.com/t/full-extent-of-map/2773/9 "2010-08-20T03:40:22Z")

</div>

Hi&nbsp;Ranjith,&nbsp;  
&nbsp;&nbsp;  
&nbsp;It&nbsp;seems&nbsp;like&nbsp;that&nbsp;your&nbsp;shapefiles&nbsp;have&nbsp;different&nbsp;projections.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Here&nbsp;is&nbsp;what&nbsp;I’m&nbsp;think&nbsp;about;&nbsp;you&nbsp;have&nbsp;two&nbsp;layers&nbsp;in&nbsp;the&nbsp;map,&nbsp;one&nbsp;has&nbsp;a&nbsp;bounding&nbsp;box&nbsp;of&nbsp;[-180&nbsp;90&nbsp;180&nbsp;-90]&nbsp;while&nbsp;the&nbsp;other&nbsp;one&nbsp;has&nbsp;a&nbsp;bounding&nbsp;box&nbsp;of&nbsp;[-4000&nbsp;3000&nbsp;3000,-1000].&nbsp;The&nbsp;first&nbsp;layer&nbsp;is&nbsp;using&nbsp;decimal&nbsp;degree&nbsp;as&nbsp;its&nbsp;map&nbsp;unit&nbsp;and&nbsp;the&nbsp;second&nbsp;one&nbsp;is&nbsp;using&nbsp;feet.&nbsp;You&nbsp;get&nbsp;an&nbsp;envelop&nbsp;of&nbsp;the&nbsp;two&nbsp;layers&nbsp;When&nbsp;using&nbsp;ExtentHelper.GetBoundingBoxOfItems.&nbsp;If&nbsp;this&nbsp;extent&nbsp;is&nbsp;set&nbsp;to&nbsp;WpfMap.CurrentExtent,&nbsp;the&nbsp;first&nbsp;layer&nbsp;will&nbsp;be&nbsp;almost&nbsp;invisible.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Please&nbsp;consult&nbsp;your&nbsp;data&nbsp;vendor&nbsp;to&nbsp;confirm&nbsp;that&nbsp;all&nbsp;your&nbsp;data&nbsp;have&nbsp;the&nbsp;same&nbsp;projection&nbsp;or&nbsp;you&nbsp;can&nbsp;send&nbsp;[support@thinkgeo.com](mailto:support@thinkgeo.com)&nbsp;your&nbsp;data&nbsp;if&nbsp;it&nbsp;is&nbsp;fine.&nbsp;  
&nbsp;&nbsp;  
&nbsp;And&nbsp;by&nbsp;the&nbsp;way,&nbsp;please&nbsp;make&nbsp;sure&nbsp;to&nbsp;call&nbsp;WpfMap.Refresh&nbsp;every&nbsp;time&nbsp;the&nbsp;WpfMap.CurrentExtent&nbsp;is&nbsp;changed.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks
