This project is read-only.

DrawControl in deepearth sl4

Apr 15, 2011 at 6:58 AM

Hello.

I work with deepearth sl4. To create drawControl in my project I copied it from deepearth sl3 solution and modified it. Control work fine, but I have problem.

For instance I need to draw a polygon. Everything works, but I found that polygon is drawn with delays. Code bellow:

  _DrawLayer = new GeometryLayer(_MapInstance){ UpdateMode = UpdateModes.TransformUpdate};

  void Events_MapMouseDown(object sender, MouseButtonEventArgs args)
        {var map = sender as Map;
            if (map.DragMode == DragBehavior.Draw)
            { _CurrentMousePoint = map.CoordHelper.PixelToGeo(args.GetPosition(map));
                switch (DrawMode)
                { case GeometryMode.Polygon:
                        if (!_IsDoubleClick)
                        {
                            if (!_IsDrawing)
                            {
                                    _Polygon = new DrawPolygon
                                    {
                                        Stroke = new SolidColorBrush(Colors.Black),
                                        Fill = new SolidColorBrush(Colors.Red),
                                    };
                                    _Polygon.Locations.Add(_CurrentMousePoint);
                                    _DrawLayer.Add(_Polygon);
                                    _DrawLayer.Add(new PointControl { Location = _CurrentMousePoint });
                                    _IsDrawing = true;   
                            }
                            else
                            {
                                    _Polygon.Locations.Add(_CurrentMousePoint);
                                    _DrawLayer.Add(new PointControl { Location = _CurrentMousePoint });
                            }
                        }
                        else
                        {
                            _IsDoubleClick = false;
                        }
                        break;

}

        }

and mousemove event:

 void Events_MapMouseMove(object sender, MouseEventArgs args)
        {
            var map = sender as Map;
            var _MousePoint = map.CoordHelper.PixelToGeo(args.GetPosition(map));

            if (map.DragMode == DragBehavior.Draw)
            {
                switch (DrawMode)
                {
                    case GeometryMode.Polygon:
                        if (_IsDrawing && _LeaderPolygon == null)
                        {
                                _LeaderPolygon = new DrawPolygon { Stroke = new SolidColorBrush(Colors.Brown)};
                                _LeaderPolygon.Locations.Add(_Polygon.Locations[0]);
                                _LeaderPolygon.Locations.Add(_Polygon.Locations[_Polygon.Locations.Count - 1]);
                                _LeaderPolygon.Locations.Add(_MousePoint);
                                _LeaderPoint = new PointControl { Location = _MousePoint };
                                _DrawLayer.Add(_LeaderPolygon);
                                _DrawLayer.Add(_LeaderPoint);
                        }
                        else
                        {
                            if (_LeaderPolygon != null)
                            {
                                    _LeaderPolygon.Locations[0] = _Polygon.Locations[0];
                                    _LeaderPolygon.Locations[1] = _Polygon.Locations[_Polygon.Locations.Count - 1];
                                    _LeaderPolygon.Locations[2] = _MousePoint;
                                    _LeaderPolygon.Locations.Add(_Polygon.Locations[0]);
                                    _LeaderPoint.Location = _MousePoint;
                            }
                        }
                        if (_LeaderPolygon != null && _LeaderPoint != null)
                        {
                                _DrawLayer.UpdateShape(_LeaderPolygon);
                                _DrawLayer.UpdateShape(_LeaderPoint);
                        }
                        break;

 

This code work but as I have said it works with delay. 

Somebody can help me?

Thanks,

Ilgiz.