コード例 #1
0
        //Show a point on the profile line when user clicks on a data point on the graph
        private void LineSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Remove any existing graphic from the data point layer
            selecteDataPointLyr.Graphics.Clear();

            //When ClearGraphics_Click occurs, all data points will be removed and no new data points will be added
            //In this case, skip the rest of the method
            if (e.RemovedItems.Count > 0 && e.AddedItems.Count == 0)
            {
                return;
            }

            PointCollection profilePointCol = Profile.Paths.FirstOrDefault();

            if (profilePointCol == null || profilePointCol.Count == 0)
            {
                return;
            }

            //From the profile line, we get the map point whose m value is the same
            //as user's selected data point on the graph
            double   m        = ((KeyValuePair <double, double>)e.AddedItems[0]).Key; //M value of the data point selected from the graph
            MapPoint mapPoint = profilePointCol.FirstOrDefault(mp => mp.M == m);      //Get the map point from the profile line with the same m value

            if (mapPoint == null)
            {
                return;
            }

            //Create a point graphic with the map point and a symbol
            client.Graphic dataPointGraphic = new client.Graphic()
            {
                Symbol   = SimplePointSymbol.CreatePointSymbol(),
                Geometry = mapPoint
            };
            //Add the graphic to the data point layer
            selecteDataPointLyr.Graphics.Add(dataPointGraphic);

            //If we can find the data point layer, we first remove it
            if (MapWidget.Map.Layers.Contains(selecteDataPointLyr))
            {
                MapWidget.Map.Layers.Remove(selecteDataPointLyr);
            }

            //Add the point layer back to make sure it always stay on top
            MapWidget.Map.Layers.Add(selecteDataPointLyr);
        }