ArcGISWindowsPhoneSDK.WebMapCharts.MyMap_MapGesture C# (CSharp) Method

MyMap_MapGesture() private method

private MyMap_MapGesture ( object sender, Map e ) : void
sender object
e Map
return void
        private void MyMap_MapGesture(object sender, Map.MapGestureEventArgs e)
        {
            if (e.Gesture == GestureType.Tap)
            {
                GraphicsLayer glayer = MyMap.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
                glayer.Graphics.Clear();

                MyInfoWindow.IsOpen = false;
                chartDetailsContent.Content = null;

                double mapScale = MyMap.Scale;

                ArcGISTiledMapServiceLayer alayer = null;
                DataTemplate dt = null;
                int layid = 0;

                foreach (Layer layer in MyMap.Layers)
                {
                    if (layer.GetValue(Document.PopupTemplatesProperty) != null)
                    {
                        alayer = layer as ArcGISTiledMapServiceLayer;
                        IDictionary<int, DataTemplate> idict = layer.GetValue(Document.PopupTemplatesProperty) as IDictionary<int, DataTemplate>;

                        foreach (LayerInfo linfo in alayer.Layers)
                        {
                            if (((mapScale > linfo.MaxScale // in scale range
                                && mapScale < linfo.MinScale) ||
                                (linfo.MaxScale == 0.0 // no scale dependency
                                && linfo.MinScale == 0.0) ||
                                (mapScale > linfo.MaxScale // minscale = 0.0 = infinity
                                && linfo.MinScale == 0.0)) &&
                                idict.ContainsKey(linfo.ID)) // id present in dictionary
                            {
                                layid = linfo.ID;
                                dt = idict[linfo.ID];
                                break;
                            }
                        }
                        if (dt != null)
                        {
                            QueryTask qt = new QueryTask(string.Format("{0}/{1}", alayer.Url, layid));
                            qt.ExecuteCompleted += (s, qe) =>
                            {
                                if (qe.FeatureSet.Features.Count > 0)
                                {
                                    Graphic g = qe.FeatureSet.Features[0];
                                    MyInfoWindow.Anchor = e.MapPoint;
                                    popupContent.ContentTemplate = dt;
                                    popupContent.Content = g.Attributes;
                                    MyInfoWindow.IsOpen = true;

                                    SolidColorBrush symbolColor = new SolidColorBrush(Colors.Cyan);

                                    if (g.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon || g.Geometry is Envelope)
                                    {
                                        g.Symbol = new SimpleFillSymbol()
                                        {
                                            BorderBrush = symbolColor,
                                            BorderThickness = 2
                                        };
                                    }
                                    else if (g.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
                                    {
                                        g.Symbol = new SimpleLineSymbol()
                                        {
                                            Color = symbolColor
                                        };
                                    }
                                    else // Point
                                    {
                                        g.Symbol = new SimpleMarkerSymbol()
                                        {
                                            Color = symbolColor,
                                            Size = 12
                                        };
                                    }
                                    glayer.Graphics.Add(g);
                                }
                            };

                            ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query()
                            {
                                Geometry = e.MapPoint,
                                OutSpatialReference = MyMap.SpatialReference,
                                ReturnGeometry = true
                            };
                            query.OutFields.Add("*");

                            qt.ExecuteAsync(query);
                        }
                    }
                }
            }
        }