# Select Part of Map

**URL:** <https://community.thinkgeo.com/t/select-part-of-map/2761>\
**Category:** WPF\
**Created:** [August 2, 2010, 11:31am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761 "2010-08-02T11:31:10Z")\
**Posts on this page:** 14\
**Page:** 1

<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 2, 2010, 11:31am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/1 "2010-08-02T11:31:10Z")

</div>

Hi,

I&nbsp;want&nbsp;to&nbsp;use&nbsp;mouse&nbsp;to&nbsp;select&nbsp;part&nbsp;of&nbsp;the&nbsp;map,&nbsp;and&nbsp;then&nbsp;highlight&nbsp;it.&nbsp;(similar&nbsp;to&nbsp;shift+Left&nbsp;click).&nbsp;So&nbsp;I&nbsp;want&nbsp;to:

  
&nbsp;&nbsp;&nbsp;&nbsp;1. Click&nbsp;on&nbsp;the&nbsp;map&nbsp;(&nbsp;it&nbsp;can&nbsp;be&nbsp;combination&nbsp;of&nbsp;Left-Click&nbsp;&nbsp;+&nbsp;Ctrl&nbsp;or&nbsp;Alt&nbsp;or&nbsp;...)
  
&nbsp;&nbsp;&nbsp;&nbsp;2. Hold&nbsp;the&nbsp;Left-Click
  
&nbsp;&nbsp;&nbsp;&nbsp;3. Move&nbsp;the&nbsp;mouse&nbsp;over&nbsp;the&nbsp;map&nbsp;(&nbsp;create&nbsp;something&nbsp;similar&nbsp;to&nbsp;the&nbsp;attached&nbsp;image).
  
&nbsp;&nbsp;&nbsp;&nbsp;4. Recieve&nbsp;the&nbsp;corners&nbsp;of&nbsp;the&nbsp;selected&nbsp;rectangle
  
&nbsp;&nbsp;&nbsp;&nbsp;5. Create&nbsp;a&nbsp;feature&nbsp;layer&nbsp;and&nbsp;Highlight&nbsp;the&nbsp;features
  

  

But&nbsp;the&nbsp;problem&nbsp;is&nbsp;that&nbsp;when&nbsp;I&nbsp;hold&nbsp;the&nbsp;Left&nbsp;Buttom&nbsp;of&nbsp;the&nbsp;mouse&nbsp;.&nbsp;the&nbsp;control&nbsp;starts&nbsp;to&nbsp;pan&nbsp;the&nbsp;map.

Many&nbsp;thanks

&nbsp;

[Select.png](https://community.thinkgeo.com/uploads/default/original/1X/b182797719dc15d2439ff7b0ed1f75c6aee9b876.png) (54 KB)

---

<div class="post-metadata">

**Author:** ![Raquibur](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/a9adbd/32.png) [@Raquibur](https://community.thinkgeo.com/u/Raquibur)\
**Post date:** [August 2, 2010, 12:12pm UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/2 "2010-08-02T12:12:32Z")

</div>

Dear&nbsp;Ben,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Please&nbsp;see&nbsp;the&nbsp;solution&nbsp;given&nbsp;by&nbsp;Howard&nbsp;in&nbsp;the&nbsp;thread&nbsp;  
&nbsp;[gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/39/aft/7827/afv/topic/Default.aspx](http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/39/aft/7827/afv/topic/Default.aspx)&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;  
&nbsp;Raquib&nbsp;

---

<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 2, 2010, 8:54pm UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/3 "2010-08-02T20:54:48Z")

</div>

Really&nbsp;thanks&nbsp;for&nbsp;your&nbsp;reply,&nbsp;Raquibur.  
  
  
  
To&nbsp;be&nbsp;more&nbsp;detail&nbsp;Ben,&nbsp;my&nbsp;suggestion&nbsp;is&nbsp;almost&nbsp;like&nbsp;Raquibur&nbsp;recommends.&nbsp;There&nbsp;is&nbsp;a&nbsp;little&nbsp;difference&nbsp;that&nbsp;is&nbsp;we&nbsp;need&nbsp;to&nbsp;keep&nbsp;the&nbsp;rectangle&nbsp;drawing&nbsp;with&nbsp;shift&nbsp;key&nbsp;and&nbsp;select&nbsp;features&nbsp;from&nbsp;one&nbsp;FeatureLayer.  
  
  
  
Here&nbsp;is&nbsp;a&nbsp;sample&nbsp;for&nbsp;you&nbsp;and&nbsp;let&nbsp;me&nbsp;know&nbsp;how&nbsp;it&nbsp;works.  
  
  
  
Thanks,  
  
Howard

[Post7932.zip](https://community.thinkgeo.com/uploads/default/original/2X/f/fa210dd849bfa4b0509a918bf54f472d142a7970.zip) (9.2 KB)

---

<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 3, 2010, 2:29am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/4 "2010-08-03T02:29:37Z")

</div>

thanks,&nbsp;  
&nbsp;I’ll&nbsp;give&nbsp;it&nbsp;a&nbsp;try&nbsp;and&nbsp;then&nbsp;write&nbsp;result&nbsp;here.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Many&nbsp;Thanks

---

<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 3, 2010, 2:43am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/5 "2010-08-03T02:43:39Z")

</div>

Hi&nbsp;Ben,&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Sure,&nbsp;take&nbsp;your&nbsp;time;&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;queries.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Howard

---

<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 3, 2010, 9:51am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/6 "2010-08-03T09:51:47Z")

</div>

It's&nbsp;great,&nbsp;thanks  
  
Just&nbsp;to&nbsp;small&nbsp;Question:

  
&nbsp;&nbsp;&nbsp;&nbsp;1. can&nbsp;we&nbsp;use&nbsp;key&nbsp;other&nbsp;than&nbsp;shift&nbsp;for&nbsp;the&nbsp;selection
  

  

Regards,  
  
Ben

---

<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 4, 2010, 1:13am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/7 "2010-08-04T01:13:55Z")

</div>

Hi&nbsp;Ben,  
  
  
  
Yes,&nbsp;Just&nbsp;one&nbsp;line&nbsp;of&nbsp;code:&nbsp;for&nbsp;example,&nbsp;press&nbsp;"S"&nbsp;which&nbsp;means&nbsp;"Select"&nbsp;instead&nbsp;of&nbsp;shift&nbsp;key.&nbsp;  
  
`selectExtentInteractiveOverlay.LeftClickDragKey = Keys.S;`  
  
  
One&nbsp;thing&nbsp;I&nbsp;want&nbsp;to&nbsp;point&nbsp;out&nbsp;is&nbsp;that&nbsp;you&nbsp;need&nbsp;reference&nbsp;System.Windows.Forms&nbsp;first&nbsp;because&nbsp;of&nbsp;the&nbsp;enum&nbsp;Keys.  
  
  
  
Thanks,  
  
Howard

---

<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 4, 2010, 4:23am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/8 "2010-08-04T04:23:03Z")

</div>

Thanks&nbsp;for&nbsp;your&nbsp;quick&nbsp;answer,&nbsp;  
&nbsp;the&nbsp;thing&nbsp;I&nbsp;need&nbsp;is&nbsp;zooming&nbsp;and&nbsp;selecting&nbsp;at&nbsp;the&nbsp;same&nbsp;time,&nbsp;if&nbsp;it&nbsp;is&nbsp;possible:&nbsp;  
&nbsp;&nbsp;  
&nbsp;shift+&nbsp;mouse&nbsp;--\>&nbsp;zoom&nbsp;  
&nbsp;ctrl+&nbsp;mouse&nbsp;--\>select&nbsp;  
&nbsp;&nbsp;  
&nbsp;thanks,&nbsp;  
&nbsp;Ben

---

<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 5, 2010, 12:44am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/9 "2010-08-05T00:44:40Z")

</div>

Ben,  
  
  
  
Sure,&nbsp;I&nbsp;changed&nbsp;the&nbsp;interactive&nbsp;overlay&nbsp;a&nbsp;little;&nbsp;please&nbsp;have&nbsp;a&nbsp;try,&nbsp;also&nbsp;you&nbsp;can&nbsp;change&nbsp;control&nbsp;key&nbsp;to&nbsp;any&nbsp;other&nbsp;key&nbsp;by&nbsp;setting&nbsp;the&nbsp;SelectDragKey&nbsp;property.  
  
  
  
Thanks,  
  
Howard

[SelectExtentInteractiveOverlay.cs](https://community.thinkgeo.com/uploads/default/original/2X/9/9f3be6f4ad5e4b11e5fa1b79f55a836c184f55a7.cs) (3.1 KB)

---

<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 5, 2010, 4:06am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/10 "2010-08-05T04:06:17Z")

</div>

Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Unfortunately&nbsp;I&nbsp;can&nbsp;not&nbsp;download&nbsp;your&nbsp;code!

---

<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 5, 2010, 4:21am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/11 "2010-08-05T04:21:06Z")

</div>

Hi&nbsp;Ben,  
  
  
  
Sorry&nbsp;for&nbsp;the&nbsp;inconvenience.&nbsp;I&nbsp;didn't&nbsp;notice&nbsp;that&nbsp;file&nbsp;suffix&nbsp;affects&nbsp;my&nbsp;uploading.&nbsp;Please&nbsp;download&nbsp;this&nbsp;one.  
  
  
  
Thanks,  
  
Howard

[001\_SelectExtentInteractiveOverlay.txt](https://community.thinkgeo.com/uploads/default/original/2X/7/778f9264d748f121c46f589c734251a5297c8122.txt) (3.1 KB)

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [August 5, 2010, 4:25am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/12 "2010-08-05T04:25:08Z")

</div>

&nbsp;Guys,

&nbsp;  
&nbsp;&nbsp;I&nbsp;also&nbsp;posted&nbsp;it&nbsp;as&nbsp;code&nbsp;as&nbsp;well.&nbsp;&nbsp;This&nbsp;is&nbsp;much&nbsp;nicer&nbsp;as&nbsp;people&nbsp;can&nbsp;see&nbsp;it&nbsp;before&nbsp;they&nbsp;download&nbsp;it.  
&nbsp;  
  
`using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Windows.Forms;using ThinkGeo.MapSuite.Core;using ThinkGeo.MapSuite.WpfDesktopEdition;namespace Post{    public class SelectExtentInteractiveOverlay : ExtentInteractiveOverlay    {        private Keys tempDragKey;        private bool isSelectDragKeyPressed;        public SelectExtentInteractiveOverlay(FeatureLayer sourceFeatureLayer)        {            SourceFeatureLayer = sourceFeatureLayer;            SelectDragKey = Keys.ControlKey;        }        public FeatureLayer SourceFeatureLayer { get; set; }        public Keys SelectDragKey { get; set; }         public event EventHandler<SelectedSelectExtentInteractiveOverlayEventArgs> Selected;        protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)        {            if (UnsafeHelper.IsKeyPressed(SelectDragKey))            {                tempDragKey = LeftClickDragKey;                LeftClickDragKey = SelectDragKey;                isSelectDragKeyPressed = true;            }            InteractiveResult result = base.MouseDownCore(interactionArguments);            return result;        }        protected override InteractiveResult MouseUpCore(InteractionArguments interactionArguments)        {            InteractiveResult result = base.MouseUpCore(interactionArguments);            if ((ExtentChangedType == ExtentChangedType.TrackZoomIn || ExtentChangedType == ExtentChangedType.TrackZoomOut) && SourceFeatureLayer != null && isSelectDragKeyPressed)            {                RectangleShape targetExtent = result.NewCurrentExtent;                result.NewCurrentExtent = null;                if (!SourceFeatureLayer.IsOpen) SourceFeatureLayer.Open();                Collection<Feature> queriedFeatures = SourceFeatureLayer.QueryTools.GetFeaturesInsideBoundingBox(targetExtent, ReturningColumnsType.AllColumns);                LeftClickDragKey = tempDragKey;                isSelectDragKeyPressed = false;                OnSelected(new SelectedSelectExtentInteractiveOverlayEventArgs(queriedFeatures));            }            return result;        }        protected virtual void OnSelected(SelectedSelectExtentInteractiveOverlayEventArgs e)        {            EventHandler<SelectedSelectExtentInteractiveOverlayEventArgs> handler = Selected;            if (handler != null)            {                handler(this, e);            }        }    }    public class SelectedSelectExtentInteractiveOverlayEventArgs : EventArgs    {        private Collection<Feature> selectedFeatures;        public SelectedSelectExtentInteractiveOverlayEventArgs(IEnumerable<Feature> selectedFeatures)        {            this.selectedFeatures = new Collection<Feature>();            foreach (Feature feature in selectedFeatures)            {                this.selectedFeatures.Add(feature);            }        }        public Collection<Feature> SelectedFeatures { get { return selectedFeatures; } }    }}`  
  
&nbsp;  
David

---

<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 6, 2010, 9:51am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/13 "2010-08-06T09:51:31Z")

</div>

It&nbsp;works&nbsp;perfectly,&nbsp;  
&nbsp;Many&nbsp;thanks

---

<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 7, 2010, 12:32am UTC](https://community.thinkgeo.com/t/select-part-of-map/2761/14 "2010-08-07T00:32:25Z")

</div>

Hi&nbsp;Ben,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;are&nbsp;welcome,&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;queries.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Howard
