Exemplo n.º 1
0
        //When the Draw Line button is clicked:
        //The skecth (a polyline graphic) will be created and will be added to the sketch layer
        //The sketch layer will be added to the map for display
        //2 map events will be registered for user's interaction
        private void AddGraphics_Click(object sender, RoutedEventArgs e)
        {
            //Take the first map widget from the view
            MapWidget mapWidget = OperationsDashboard.Instance.Widgets.First(w => w.GetType() == typeof(MapWidget)) as MapWidget;

            if (mapWidget == null || mapWidget.Map == null)
            {
                return;
            }

            MapWidget = mapWidget;
            client.Map map = MapWidget.Map;

            //First, remove any existing graphic layer on the map
            RemoveAllGraphicLayers();

            //Create the geometry (a polyline) for the sketch
            sketchGeometry = new client.Geometry.Polyline();
            sketchGeometry.SpatialReference = map.SpatialReference;
            sketchGeometry.Paths.Add(new client.Geometry.PointCollection());

            //Create the sketch with the geometry and a symbol
            client.Graphic sketch = new client.Graphic()
            {
                Symbol   = SimplePolylineSymbol.CreateLineSymbol(),
                Geometry = sketchGeometry,
            };

            //Add the sketch to the map sketch layer
            //mapSketchLyr.Graphics.Clear();
            mapSketchLyr.Graphics.Add(sketch);

            //Add the sketch layer back to the map
            map.Layers.Add(mapSketchLyr);

            //Register mouse click i.e. sketch begins
            //Register mouse double click i.e. sketch finishes
            map.MouseClick       += map_MouseClick;
            map.MouseDoubleClick += map_MouseDoubleClick;
            map.MouseMove        += map_MouseMove;
        }
Exemplo n.º 2
0
        //Add a map point (from mouse click) to the geometry of the sketch
        //Create a temporary graphic to trace user's mouse movement
        void map_MouseClick(object sender, client.Map.MouseEventArgs e)
        {
            sketchGeometry.Paths[0].Add(e.MapPoint);


            //feedback layer
            feedBackLyr.Graphics.Clear();

            client.Map map = MapWidget.Map;

            #region Create a temporary graphic to trace user's mouse movement
            //Create a point collection using the last clicked point and the latest mouse position
            PointCollection pc = new PointCollection();
            pc.Add(sketchGeometry.Paths[0].Last());
            pc.Add(new MapPoint());

            //Create the geometry of the feedback line using the point collection
            client.Geometry.Polyline feedbackGeomrtry = new client.Geometry.Polyline();
            feedbackGeomrtry.SpatialReference = map.SpatialReference;
            feedbackGeomrtry.Paths.Add(pc);

            //Create the feedback line with the geometry and a symbol
            client.Graphic feedback = new client.Graphic()
            {
                Symbol   = SimplePolylineSymbol.CreateLineSymbol(),
                Geometry = feedbackGeomrtry,
            };
            #endregion

            //Add the feedback line to the feedback layer
            feedBackLyr.Graphics.Add(feedback);

            //Add the layer to the map if we haevn't done so
            if (!map.Layers.Contains(feedBackLyr))
            {
                map.Layers.Add(feedBackLyr);
            }
        }