ThinkGeo.com    |     Documentation    |     Premium Support

Problem deleting active drawed polygons

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?

Hi Jehans,

Welcome! Please check the replies below:

1, I was unable to recreate issue with our sample Drawing & Edition , 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

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.

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,

Great service as always Don! Will try this out.

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?

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,

Thank you so much!

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

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

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.Collection1[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.Func3[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

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 which is a light screen capture and sharing utility.

Thanks,
Bill

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.

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

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.

http://www.screencast.com/t/tzKzBjIsYmQ

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;

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

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

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