# Only allow one feature to be created

**URL:** <https://community.thinkgeo.com/t/only-allow-one-feature-to-be-created/1665>\
**Category:** WinForms\
**Created:** [April 11, 2011, 4:56pm UTC](https://community.thinkgeo.com/t/only-allow-one-feature-to-be-created/1665 "2011-04-11T16:56:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [April 11, 2011, 4:56pm UTC](https://community.thinkgeo.com/t/only-allow-one-feature-to-be-created/1665/1 "2011-04-11T16:56:05Z")

</div>

I'm&nbsp;using&nbsp;the&nbsp;TrackOverlay&nbsp;to&nbsp;allow&nbsp;users&nbsp;to&nbsp;draw&nbsp;features&nbsp;on&nbsp;the&nbsp;map.

The&nbsp;user&nbsp;should&nbsp;only&nbsp;be&nbsp;able&nbsp;to&nbsp;draw&nbsp;one&nbsp;feature.

If&nbsp;the&nbsp;user&nbsp;clicks&nbsp;the&nbsp;draw&nbsp;point&nbsp;button&nbsp;and&nbsp;I&nbsp;change&nbsp;to&nbsp;TrackMode.Point&nbsp;how&nbsp;do&nbsp;I&nbsp;stop&nbsp;the&nbsp;user&nbsp;creating&nbsp;more&nbsp;than&nbsp;one&nbsp;point?

I&nbsp;guess&nbsp;this&nbsp;will&nbsp;involve&nbsp;creating&nbsp;a&nbsp;custom&nbsp;version&nbsp;of&nbsp;TrackOverlay&nbsp;and&nbsp;overriding&nbsp;the&nbsp;MouseUp&nbsp;andMouseDown&nbsp;events&nbsp;but&nbsp;this&nbsp;will&nbsp;be&nbsp;difficult&nbsp;because&nbsp;the&nbsp;user&nbsp;could&nbsp;be&nbsp;in&nbsp;TrackMode.Polygon&nbsp;and&nbsp;I&nbsp;wont&nbsp;know&nbsp;if&nbsp;the&nbsp;user&nbsp;is&nbsp;continuing&nbsp;with&nbsp;the&nbsp;first&nbsp;polygon&nbsp;or&nbsp;creating&nbsp;a&nbsp;second.

Any&nbsp;ideas?

Cheers

Steve

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [April 11, 2011, 9:22pm UTC](https://community.thinkgeo.com/t/only-allow-one-feature-to-be-created/1665/2 "2011-04-11T21:22:31Z")

</div>

&nbsp;Figured&nbsp;it&nbsp;out:

`using ThinkGeo.MapSuite.DesktopEdition;namespace MapUserControl{    public class CustomTrackInteractiveOverlay : TrackInteractiveOverlay    {        protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)        {            if (TrackShapeLayer.InternalFeatures.Count > 0)            {                TrackShapeLayer.InternalFeatures.Clear();            }            return base.MouseDownCore(interactionArguments);        }    }}`

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [April 12, 2011, 3:41am UTC](https://community.thinkgeo.com/t/only-allow-one-feature-to-be-created/1665/3 "2011-04-12T03:41:56Z")

</div>

&nbsp;Steve,

There&nbsp;is&nbsp;a&nbsp;easier&nbsp;way&nbsp;to&nbsp;implement&nbsp;your&nbsp;requirement,&nbsp;please&nbsp;refer&nbsp;the&nbsp;following&nbsp;code:

&nbsp;

`winformsMap1.TrackOverlay.TrackEnded += new EventHandler<TrackEndedTrackInteractiveOverlayEventArgs>(TrackOverlay_TrackEnded); void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e) {    winformsMap1.TrackOverlay.TrackMode = TrackMode.None; }`&nbsp;&nbsp;So&nbsp;when&nbsp;the&nbsp;user&nbsp;draws&nbsp;one&nbsp;point&nbsp;or&nbsp;any&nbsp;other&nbsp;graphs,&nbsp;the&nbsp;track&nbsp;mode&nbsp;would&nbsp;be&nbsp;set&nbsp;to&nbsp;none&nbsp;mode&nbsp;automatically.&nbsp;&nbsp;&nbsp;Please&nbsp;add&nbsp;the&nbsp;code&nbsp;above&nbsp;to&nbsp;your&nbsp;application,&nbsp;if&nbsp;you&nbsp;encounter&nbsp;any&nbsp;more&nbsp;questions&nbsp;please&nbsp;let&nbsp;me&nbsp;know&nbsp;again,

Thanks,

Scott,

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [April 12, 2011, 4:05pm UTC](https://community.thinkgeo.com/t/only-allow-one-feature-to-be-created/1665/4 "2011-04-12T16:05:03Z")

</div>

Hi&nbsp;Scott&nbsp;  
&nbsp;&nbsp;  
&nbsp;Very&nbsp;interesting&nbsp;and&nbsp;solves&nbsp;one&nbsp;problem&nbsp;but&nbsp;the&nbsp;user&nbsp;can&nbsp;still&nbsp;click&nbsp;the&nbsp;draw&nbsp;point&nbsp;button&nbsp;and&nbsp;draw&nbsp;another&nbsp;feature.&nbsp;I&nbsp;need&nbsp;to&nbsp;stop&nbsp;the&nbsp;user&nbsp;drawing&nbsp;more&nbsp;than&nbsp;one&nbsp;feature&nbsp;no&nbsp;matter&nbsp;how&nbsp;he&nbsp;attempts&nbsp;to&nbsp;do&nbsp;it.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;method&nbsp;I&nbsp;presented&nbsp;should&nbsp;prevent&nbsp;more&nbsp;than&nbsp;one&nbsp;feature&nbsp;being&nbsp;created&nbsp;under&nbsp;any&nbsp;circumstances&nbsp;unless&nbsp;you&nbsp;can&nbsp;see&nbsp;any&nbsp;flaws?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [April 13, 2011, 2:29am UTC](https://community.thinkgeo.com/t/only-allow-one-feature-to-be-created/1665/5 "2011-04-13T02:29:15Z")

</div>

&nbsp;Steve,

I'm&nbsp;sorry&nbsp;I&nbsp;misunderstood&nbsp;what&nbsp;you&nbsp;meant,&nbsp;now&nbsp;I&nbsp;understand&nbsp;it&nbsp;fully&nbsp;what&nbsp;you&nbsp;want,&nbsp;I&nbsp;think&nbsp;there&nbsp;is&nbsp;a&nbsp;easier&nbsp;way&nbsp;than&nbsp;your&nbsp;method&nbsp;below:

&nbsp;

`            winformsMap1.TrackOverlay.TrackStarting += new EventHandler<TrackStartingTrackInteractiveOverlayEventArgs>(TrackOverlay_TrackStarting); void TrackOverlay_TrackStarting(object sender, TrackStartingTrackInteractiveOverlayEventArgs e)        {            if (winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count > 0)            {                winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();            }        }`So&nbsp;it&nbsp;will&nbsp;prevent&nbsp;more&nbsp;than&nbsp;one&nbsp;graphs&nbsp;to&nbsp;be&nbsp;drawn&nbsp;on&nbsp;the&nbsp;map,&nbsp;it&nbsp;always&nbsp;one&nbsp;graphs&nbsp;to&nbsp;be&nbsp;tracked&nbsp;on&nbsp;the&nbsp;map.&nbsp;This&nbsp;is&nbsp;a&nbsp;optional&nbsp;for&nbsp;you,&nbsp;your&nbsp;method&nbsp;is&nbsp;also&nbsp;good,&nbsp;just&nbsp;more&nbsp;choices&nbsp;for&nbsp;you,

Thanks,

Scott,
