Get Selected GraphicsLayer from Map

2225
1
01-29-2016 03:26 AM
GerardLawless
New Contributor II

In my IOS app i've drawn a number of graphics onto the Map. In the TouchesBegin event that is fired when a user interacts with the map i cant figure out how to tell if the point interacts with one of the graphics.

I've binded the SDK to C#. The objects and the process should be the exact same as in a natively developed app

public override void TouchesBegan(NSSet touches, UIEvent evt)

        {

            if (!this.Loaded) return;

            try

            {

                base.TouchesBegan(touches, evt);

                var touch = touches.AnyObject as UITouch;

                if (touch == null) return;

                var p = new AGSIdentifyParameters()

                {

                    Tolerance = 20,

                    Dpi = 98,

                    LayerOption = AGSIdentifyParametersLayerOption.All

                };

           

                var identityPoint = ToMapPoint(touch.LocationInView(this));

                p.Geometry = identityPoint;

                p.SpatialReference = identityPoint.SpatialReference;

                p.MapEnvelope = this.MaxEnvelope;

                p.Size = new CGSize(UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width);

//AFTER HERE IS WHERE I AM GETTING LOST. IM NOT SURE HOW TO FIND THE GRAPHIC I WANT TO INTERACT WIT

                var gs = GraphicsLayer.SelectedGraphics;

               

                var result = GraphicsLayer.Graphics.FirstOrDefault(i => i.Geometry.Envelope.ContainsPoint(identityPoint));

                if (result != null)

                {

                    var r = result.Geometry;

                }

            }

            catch (Exception ex)

            {

                Analystics.Instance.LogError(ex,"Issue occured in the ontouch event on the Map");

            }

0 Kudos
1 Reply
GagandeepSingh
Occasional Contributor II

To get the graphics for a tap on the map view, you should use the mapView:didClickAtPoint:mapPoint:graphics:​ method on the AGSMapViewTouchDelegate? Simply register your view controller as the touchDelegate for the map view and define the above mentioned method in the same view controller. Now whenever you tap on the map view, the delegate method show be called.

0 Kudos