# Problem deleting active drawed polygons

**URL:** <https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444>\
**Category:** Android\
**Created:** [March 14, 2017, 9:08am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444 "2017-03-14T09:08:24Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [March 14, 2017, 9:08am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/1 "2017-03-14T09:08:25Z")

</div>

Hi!  
Today I come to you with two questions.

1 - I have a problem related to drawing polygons on the map. Seen in the first picture is a drawn polygon, however I want to clear it, and draw a new one. Whenever I do this, it gets deleted from the map. When I press the polygon button, and start drawing again all the points from the originally drawn polygon seems to be stored in cache somewhere, so they re-appear onto the map when I start drawing again.

```
                mapView.EditOverlay.ClearAllControlPoints();
                mapView.EditOverlay.EditShapesLayer.Open();
                mapView.EditOverlay.EditShapesLayer.Clear();
                mapView.TrackOverlay.TrackShapeLayer.Open();
                mapView.TrackOverlay.TrackShapeLayer.Clear();                                   
                mapView.EditOverlay.Refresh();
                mapView.TrackOverlay.Refresh();

```

2 - Seen in picture 3 is a line drawn on top of the polygon, and is an “unwanted” situation in my app. I want to make it unable to draw crossing lines. Is this possible?

 ![](https://community.thinkgeo.com/uploads/default/original/3X/4/b/4b34915e76f799782227052cd608ba98990afbd4.png)

---

<div class="post-metadata">

**Author:** ![Peter](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/peter/32/19042_2.png) [@Peter](https://community.thinkgeo.com/u/Peter)\
**Post date:** [March 15, 2017, 8:58am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/2 "2017-03-15T08:58:30Z")

</div>

Hi Jehans,

Welcome! Please check the replies below:

1, I was unable to recreate issue with our sample [Drawing & Edition](http://wiki.thinkgeo.com/wiki/map_suite_android_drawing_editing) , following is my steps:  
a. Click the “Draw” and then click the “Polygon” button to draw a polygon.  
b. Click the “Cursor” button and then click “Clear” button, the polygon drawn before will be disappeared.  
c. Click “Draw” button again and click “Polygon” button to draw polygon again.

While doing these operations, I don’t see the polygon which removed in step b re-appear, any misunderstood here please let us know and I hope you can tell us which version is referenced in your application.

2, No, it doesn’t support. An option is to check if the lines are crossing after drawing completely. If it’s valid, then add to the specific layer, otherwise abandon it.

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [March 20, 2017, 1:53pm UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/3 "2017-03-20T13:53:34Z")

</div>

Hi Peter, and thank you for your answer.  
I am using the 9.0.615.0 version for Xamarin Forms.

I looked at your example, and it seems to be somewhat similar to my code. I debugged the code, and all internal features get removed, however the points of the polygon seems to be cached somewhere.

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [April 1, 2017, 2:47am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/4 "2017-04-01T02:47:21Z")

</div>

Hi Jehans,

I have reviewed your code, and guess that the problem about deleting shape is caused by tracking not. Before you draw other shape or delete shape, you need to call  
TrackOverlay.LongPress to end tracking.

You can refer to the TrackButtonClick function of the Drawing & Edition sample. (PS: When you call the TrackOverlay.LongPress function, you need to set world location that you draw the last time. )

You can refer to the following code:

// The endVertex is the end point that you draw the last time.  
mapView.EditOverlay.ClearAllControlPoints();  
mapView.EditOverlay.EditShapesLayer.Open();  
mapView.EditOverlay.EditShapesLayer.Clear();  
mapView.TrackOverlay.LongPress(new InteractionArguments() { WorldX = endVertex.X, WorldY = endVertex.Y });  
mapView.TrackOverlay.TrackShapeLayer.Open();  
mapView.TrackOverlay.TrackShapeLayer.Clear();  
mapView.EditOverlay.Refresh();  
mapView.TrackOverlay.Refresh();

If this can’t solve your problem, please give us more detail information about your requirement.

Thanks,

---

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [April 1, 2017, 9:59am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/5 "2017-04-01T09:59:53Z")

</div>

Great service as always Don! Will try this out.

---

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [April 5, 2017, 7:09am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/6 "2017-04-05T07:09:24Z")

</div>

Hello again,  
the mapView.TrackOverlay.Longpress function does not exist within Xamarin Forms ThinkGeo.

The problem is that the control points for the polygon seems to persist, even after deleting them through direct copy-paste code from other examples.  
What would be the best way to solve this?

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [April 10, 2017, 8:39am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/7 "2017-04-10T08:39:25Z")

</div>

Hi Jehans,

We have added IsInTracking property in TrackOverlay class, and you can set IsInTracking property to end tracking. The change will apply to the 9.0.658.0 version for MapSuiteFormsEdition.

You can refer to the following code to delete tracking shape:

```
   mapView.EditOverlay.ClearAllControlPoints();
   mapView.EditOverlay.EditShapesLayer.Open();
   mapView.EditOverlay.EditShapesLayer.Clear();
   mapView.TrackOverlay.IsInTracking = false;
   mapView.TrackOverlay.TrackShapeLayer.Open();
   mapView.TrackOverlay.TrackShapeLayer.Clear();
   mapView.EditOverlay.Refresh();
   mapView.TrackOverlay.Refresh();

```

Thanks,

---

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [April 10, 2017, 11:19am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/8 "2017-04-10T11:19:31Z")

</div>

Thank you so much!

I also sent you a PM Don. Have a good easter.

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [April 11, 2017, 2:17am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/9 "2017-04-11T02:17:07Z")

</div>

Hi Jehans,

Thanks for your PM, because not only me will work on your question, so please don’t use PM to sent us your information.

If you have some private information you can choose create a ticket and put your question there.

Wish that’s helpful.

Regards,

Don

---

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [April 18, 2017, 1:36pm UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/10 "2017-04-18T13:36:28Z")

</div>

Hello again, and hope you had a good easter.

I have now added version 9.0.664 to test if I am able to delete the polygons or not, but still a bug occurs. However a new one at this time.

1 - I draw a polygon.  
2 - I delete the drawn polygon.  
3 - When I click the map to draw a new polygon, it instantly crashes with the following errror on iOS:

```
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

```

Here is the full stacktrace for the android version:  
04-18 14:16:51.955 I/MonoDroid(10824): UNHANDLED EXCEPTION:  
04-18 14:16:52.015 I/MonoDroid(10824): System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.  
04-18 14:16:52.015 I/MonoDroid(10824): Parameter name: index  
04-18 14:16:52.015 I/MonoDroid(10824): at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00000] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/throwhelper.cs:93  
04-18 14:16:52.015 I/MonoDroid(10824): at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/throwhelper.cs:56  
04-18 14:16:52.015 I/MonoDroid(10824): at System.Collections.ObjectModel.Collection`1[T].set_Item (System.Int32 index, T value) [0x0002f] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/collections/objectmodel/collection.cs:54 04-18 14:16:52.015 I/MonoDroid(10824): at ThinkGeo.MapSuite.AndroidEdition.TrackInteractiveOverlay.KBc= (System.Int32 index, ThinkGeo.MapSuite.Core.Vertex trackVertex) [0x00001] in <f4975c76a2a34648b1dca05befdd564d>:0 04-18 14:16:52.015 I/MonoDroid(10824): at ThinkGeo.MapSuite.AndroidEdition.TrackInteractiveOverlay.TouchDownCore (ThinkGeo.MapSuite.AndroidEdition.InteractionArguments interactionArguments) [0x000f4] in <f4975c76a2a34648b1dca05befdd564d>:0 04-18 14:16:52.015 I/MonoDroid(10824): at ThinkGeo.MapSuite.AndroidEdition.InteractiveOverlay.TouchDown (ThinkGeo.MapSuite.AndroidEdition.InteractionArguments e) [0x00001] in <f4975c76a2a34648b1dca05befdd564d>:0 04-18 14:16:52.015 I/MonoDroid(10824): at ThinkGeo.MapSuite.AndroidEdition.MapView.<InitializeEvent>b__3 (ThinkGeo.MapSuite.AndroidEdition.InteractiveOverlay o, ThinkGeo.MapSuite.AndroidEdition.InteractionArguments args) [0x00000] in <f4975c76a2a34648b1dca05befdd564d>:0 04-18 14:16:52.015 I/MonoDroid(10824): at ThinkGeo.MapSuite.AndroidEdition.MapView.HRY= (Android.Views.MotionEvent e, System.Func`3[T1,T2,TResult] action, System.Single rotationAngle) [0x00054] in :0  
04-18 14:16:52.015 I/MonoDroid(10824): at ThinkGeo.MapSuite.AndroidEdition.MapView.b\_\_2 (Android.Views.MotionEvent e) [0x00008] in :0  
04-18 14:16:52.015 I/MonoDroid(10824): at ThinkGeo.MapSuite.AndroidEdition.MapSimpleOnGestureListener.OnDown (Android.Views.MotionEvent e) [0x0001b] in :0  
04-18 14:16:52.015 I/MonoDroid(10824): at Android.Views.GestureDetector+SimpleOnGestureListener.n\_OnDown\_Landroid\_view\_MotionEvent\_ (System.IntPtr jnienv, System.IntPtr native\_\_this, System.IntPtr native\_e) [0x00011] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Views.GestureDetector.cs:1087  
04-18 14:16:52.015 I/MonoDroid(10824): at (wrapper dynamic-method) System.Object:73120258-13f1-4fc6-8f67-aab9053afb15 (intptr,intptr,intptr)  
04-18 14:16:52.055 D/Mono (10824): Assembly Ref addref HockeySDK.AndroidBindings[0xaabd34e0] -\> System[0x961d1620]: 18  
04-18 14:16:52.115 W/art (10824): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable

---

<div class="post-metadata">

**Author:** ![Bill\_Xu](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@Bill\_Xu](https://community.thinkgeo.com/u/Bill_Xu)\
**Post date:** [April 19, 2017, 10:01am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/11 "2017-04-19T10:01:27Z")

</div>

Hi Jehans,

Thanks for your expatiation, it turns out to be a bug on Android edition.

Our development team has fixed the bug, please get the latest version(9.0.665) from our product center and have a try.

On your last step to recreate the issue, you mentioned that the error is on iOS. By following your steps, we cannot recreate it on iOS. If the issue still exists, could you please give us more detail steps from your application start. We are appreciate that if you can create a video, we suggest you to use [Jing](https://www.techsmith.com/jing.html) which is a light screen capture and sharing utility.

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [April 19, 2017, 1:34pm UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/12 "2017-04-19T13:34:07Z")

</div>

Hi Bill\_Xu, and thank you for the quick reply.

I will test this ASAP, will you be so kind as to make 9.0.665 available for download in product center?

I will also doublecheck the iOS version, and provide a video if needed.

---

<div class="post-metadata">

**Author:** ![Bill\_Xu](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@Bill\_Xu](https://community.thinkgeo.com/u/Bill_Xu)\
**Post date:** [April 20, 2017, 3:14am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/13 "2017-04-20T03:14:30Z")

</div>

Hi Jehans,

Thanks for your patience.

An issue occurs when 9.0.665.0 build, we have uploaded a new version 9.0.666.0 which is available for download in product center. Please get it and have a try.

Regards,  
Bill

---

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [April 20, 2017, 10:58am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/14 "2017-04-20T10:58:25Z")

</div>

Hi Bill! Version 9.0.666 worked perfectly, and fixed the bug for Android.

Here is the video for iOS + Screenshot below from Visual Studio. I also supplied my delete code.  
The MapView is the only page on the stack when this bug occurs.

> **[TechSmith Screencast](https://app.screencast.com/)**
>
> World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

 ![](https://community.thinkgeo.com/uploads/default/original/3X/2/e/2e4a1386dc678d84d50972b16d84c7ed93589298.jpg) 

```
case "delete.png":
                    mapView.TrackOverlay.TrackMode = TrackMode.None;
                    mapView.EditOverlay.ClearAllControlPoints();
                    mapView.EditOverlay.EditShapesLayer.Open();
                    mapView.EditOverlay.EditShapesLayer.Clear();
                    mapView.TrackOverlay.IsInTracking = false;
                    mapView.TrackOverlay.TrackShapeLayer.Open();
                    mapView.TrackOverlay.TrackShapeLayer.Clear();
                    mapView.EditOverlay.Refresh();
                    mapView.TrackOverlay.Refresh();

                    polygonButton.IsVisible = true;

                    break;

                case "polygon.png":
                     mapView.TrackOverlay.TrackMode = TrackMode.Polygon;
                    break;

```

---

<div class="post-metadata">

**Author:** ![Bill\_Xu](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@Bill\_Xu](https://community.thinkgeo.com/u/Bill_Xu)\
**Post date:** [April 21, 2017, 10:14am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/15 "2017-04-21T10:14:18Z")

</div>

Hi Jehans,

Thanks for your video and expatiation.

This issue has been fixed on 9.0.667.0 and higher version, please download that with product center and have a try.

If your meet any other problems in the future, please feel free to contact us. It is glad to help you.

Regards,  
Bill

---

<div class="post-metadata">

**Author:** ![Jehans\_Jr\_Storvik](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jehans\_Jr\_Storvik](https://community.thinkgeo.com/u/Jehans_Jr_Storvik)\
**Post date:** [April 21, 2017, 12:23pm UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/16 "2017-04-21T12:23:30Z")

</div>

Version 9.0.668 fixed it for iOS.  
Thank you, and have a good weekend!

---

<div class="post-metadata">

**Author:** ![Bill\_Xu](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@Bill\_Xu](https://community.thinkgeo.com/u/Bill_Xu)\
**Post date:** [April 24, 2017, 1:39am UTC](https://community.thinkgeo.com/t/problem-deleting-active-drawed-polygons/8444/17 "2017-04-24T01:39:39Z")

</div>

Hi Jehans,

It’s my pleasure and I’m very glad to hear it works for you.  
Any question please feel free to let us know.

Thanks,  
Bill
