internal static void Transform(WriteableBitmap context, Geometry original, sb.Point location, int border, int fill)
        {
            var geometry = original.GetFlattenedPathGeometry();

            foreach (var figure in geometry.Figures)
            {
                Point firstLocalPoint = ((PolyLineSegment)figure.Segments[0]).Points[0];

                var firstPoint = new Point(firstLocalPoint.X + location.X, firstLocalPoint.Y + location.Y);

                foreach (var segment in figure.Segments)
                {
                    if (segment is PolyLineSegment)
                    {
                        var points = ((PolyLineSegment)segment).Points.Select(i => new Point(i.X + location.X, i.Y + location.Y)).ToList();

                        points.Insert(0, firstPoint);

                        AddLineString(context, points, border, fill);
                    }
                    else if (segment is LineSegment)
                    {
                        var x2 = ((LineSegment)segment).Point.X + location.X;

                        var y2 = ((LineSegment)segment).Point.Y + location.Y;

                        context.DrawLine((int)(firstPoint.X), (int)(firstPoint.Y), (int)(x2), (int)(y2), border);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
        }
Example #2
0
        private Locateable ToSecondaryLocateable(IPoint first, IPoint second)
        {
            var webMercatorPoint = new Point((first.X + second.X) / 2.0, (first.Y + second.Y) / 2.0);

            //var element = new View.MapMarkers.Circle(.6);
            var element = Options.MakeSecondaryVertex();

            var locateable = new Locateable(Model.AncherFunctionHandlers.CenterCenter)
            {
                Element = element, X = webMercatorPoint.X, Y = webMercatorPoint.Y
            };

            element.MouseLeftButtonDown += (sender, e) =>
            {
                webMercatorPoint.X = locateable.X;

                webMercatorPoint.Y = locateable.Y;

                if (!TryInsertPoint(webMercatorPoint, first, second, this._webMercatorGeometry))
                {
                    throw new NotImplementedException();
                }

                RequestRefresh?.Invoke(this);
            };

            return(locateable);
        }
Example #3
0
        private bool TryInsertPoint(Point webMercatorPoint, IPoint startLineSegment, IPoint endLineSegment, Geometry geometry)
        {
            var point = this.ToScreen(webMercatorPoint.AsWpfPoint());

            if (geometry.Points != null)
            {
                for (int i = 0; i < geometry.Points.Count; i++)
                {
                    if (geometry.Points[i] == startLineSegment)
                    {
                        geometry.InsertPoint(webMercatorPoint, i + 1);

                        ReconstructLocateables();

                        return(true);
                    }
                }
            }
            else
            {
                for (int g = 0; g < geometry.Geometries.Count; g++)
                {
                    if (TryInsertPoint(webMercatorPoint, startLineSegment, endLineSegment, geometry.Geometries[g]))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        internal static void Transform(drawing.Graphics graphics, Geometry original, sb.Point location, drawing.Pen pen, drawing.Brush brush)
        {
            var geometry = original.GetFlattenedPathGeometry();

            foreach (var figure in geometry.Figures)
            {
                Point firstLocalPoint = ((PolyLineSegment)figure.Segments[0]).Points[0];

                var firstPoint = new System.Drawing.PointF((float)(firstLocalPoint.X + location.X), (float)(firstLocalPoint.Y + location.Y));

                foreach (var segment in figure.Segments)
                {
                    if (segment is PolyLineSegment)
                    {
                        var points = ((PolyLineSegment)segment).Points.Select(i => new System.Drawing.PointF((float)(i.X + location.X), (float)(i.Y + location.Y))).ToList();

                        points.Add(firstPoint);

                        graphics.DrawLines(pen, points.ToArray());
                    }
                    else if (segment is LineSegment)
                    {
                        var x2 = (float)(((LineSegment)segment).Point.X + location.X);

                        var y2 = (float)(((LineSegment)segment).Point.Y + location.Y);

                        graphics.DrawLine(pen, firstPoint.X, firstPoint.Y, x2, y2);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
        }
Example #5
0
        private bool UpdateLineSegment(Point point, Point newPoint, Geometry geometry, RecursiveCollection <Locateable> midCollection)
        {
            if (geometry.Points != null)
            {
                for (int i = 0; i < geometry.Points.Count; i++)
                {
                    if (geometry.Points[i] == point)
                    {
                        UpdateMidPoints(point, newPoint, i, midCollection);

                        return(true);
                    }
                }
            }
            else
            {
                for (int g = 0; g < geometry.Geometries.Count; g++)
                {
                    var matched = UpdateLineSegment(point, newPoint, geometry.Geometries[g], midCollection.Collections[g]);

                    if (matched)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #6
0
        private void UpdateMidPoints(Point point, Point newPoint, int pointIndex, RecursiveCollection <Locateable> midCollection)
        {
            try
            {
                var displacement = new Point((newPoint.X - point.X) / 2.0, (newPoint.Y - point.Y) / 2.0);

                var length = midCollection.Values.Count;

                var leftIndex = GetLeftMidPointIndex(pointIndex, length);

                var rightIndex = GetRightMidPointIndex(pointIndex, length);

                Locateable left = leftIndex == int.MinValue ? null : midCollection.Values[leftIndex];

                if (left != null)
                {
                    left.X = left.X + displacement.X;
                    left.Y = left.Y + displacement.Y;
                }

                Locateable right = rightIndex == int.MinValue ? null : midCollection.Values[rightIndex];

                if (right != null)
                {
                    right.X = right.X + displacement.X;
                    right.Y = right.Y + displacement.Y;
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #7
0
        //probably this method can be better
        private void AddVertex(Point webMercatorPoint, Geometry geometry, RecursiveCollection <Locateable> primaryCollection)
        {
            if (geometry.Points != null)
            {
                var point = this.ToScreen(webMercatorPoint.AsWpfPoint());

                var locateable = ToPrimaryLocateable(webMercatorPoint);

                //geometry.Points.Count > 0, is to see if it is not going to add first point of a new part
                if (geometry.Points.Count > 0 && geometry.Points.Last().AreExactlyTheSame(webMercatorPoint) == true)
                {
                    return;
                }

                geometry.InsertLastPoint(webMercatorPoint);

                primaryCollection.Values.Add(locateable);

                //if (!MassEdit)
                //{
                this._primaryVerticesLayer.Items.Add(locateable);
                //}

                if (geometry.Points.Count > 1 && Options.IsEdgeLabelVisible)
                {
                    this._edgeLabelLayer.Items.Add(ToEdgeLengthLocatable(geometry.Points[geometry.Points.Count - 2], webMercatorPoint));
                }
            }
            else
            {
                AddVertex(webMercatorPoint, geometry.Geometries.Last(), primaryCollection.Collections.Last());
            }
        }
Example #8
0
        internal void StartNewPart(Point webMercatorPoint)
        {
            this._webMercatorGeometry.Geometries.Last().InsertLastPoint(webMercatorPoint);
            //this.AddVertex(webMercatorPoint);
            MakePathGeometry();

            ReconstructLocateables();
        }
Example #9
0
        public void FindNearestPoint(Point point)
        {
            var nearestPoint = _webMercatorGeometry.GetNearestPoint(point);

            this._primaryVerticesLabelLayer.Items.Clear();

            this._primaryVerticesLabelLayer.Items.Add(ToPrimaryLocateable(nearestPoint));
        }
Example #10
0
        private void UpdateLineSegment(Point point, Point newValue)
        {
            var oldPoint = ToScreen(point.AsWpfPoint());

            var screenPoint = ToScreen(newValue.AsWpfPoint());

            for (int f = this._pathGeometry.Figures.Count - 1; f >= 0; f--)
            {
                var dif = this._pathGeometry.Figures[f].StartPoint - oldPoint;

                if (this._pathGeometry.Figures[f].StartPoint.AsPoint().AreExactlyTheSame(oldPoint.AsPoint()))
                {
                    this._pathGeometry.Figures[f].StartPoint = screenPoint;

                    break;
                }
                else
                {
                    bool updated = false;

                    for (int s = 0; s < this._pathGeometry.Figures[f].Segments.Count; s++)
                    {
                        var lineSegment = (this._pathGeometry.Figures[f].Segments[s] as LineSegment);

                        dif = lineSegment.Point - oldPoint;

                        if (lineSegment.Point.AsPoint().AreExactlyTheSame(oldPoint.AsPoint()))
                        {
                            lineSegment.Point = screenPoint;

                            updated = true;

                            break;
                        }
                    }

                    if (updated)
                    {
                        break;
                    }
                }
            }

            var matched = UpdateLineSegment(point, newValue, this._webMercatorGeometry, this._midVertices);

            if (!matched)
            {
                throw new NotImplementedException();
            }
        }
Example #11
0
        private Locateable ToEdgeLengthLocatable(Point first, Point second)
        {
            Func <Point, Point> toGeodeticWgs84 = p => MapProjects.WebMercatorToGeodeticWgs84(p);

            var edge = new LineSegment <Point>(first, second);

            var element = new View.MapMarkers.RectangleLabelMarker(edge.GetLengthLabel(toGeodeticWgs84));

            //var offset = _screenToMap(15);

            return(new Locateable(Model.AncherFunctionHandlers.BottomCenter)
            {
                Element = element, X = edge.Middle.X, Y = edge.Middle.Y
            });
        }
Example #12
0
        internal void ChangeCurrentEditingPoint(Point point)
        {
            //find selected locatable

            var currentEditingPoint = this._primaryVerticesLayer.FindSelectedLocatable();

            if (currentEditingPoint == null)
            {
                return;
            }

            currentEditingPoint.X = point.X;

            currentEditingPoint.Y = point.Y;
        }
Example #13
0
        public void UpdateLastSemiVertexLocation(Point newMercatorPoint)
        {
            if (_pathGeometry.Figures?.Last()?.Segments?.Count() < 1)
            {
                AddSemiVertex(newMercatorPoint);
            }

            if (_pathGeometry.Figures.Last().Segments.Count < this._webMercatorGeometry.GetLastPart().Count)
            {
                AddSemiVertex(newMercatorPoint);
            }

            var newPoint = this.ToScreen(newMercatorPoint.AsWpfPoint());

            var lastSegment = ((LineSegment)_pathGeometry.Figures.Last().Segments.Last()).Point = new WpfPoint(newPoint.X, newPoint.Y);
        }
Example #14
0
        private spatial.Point GetStartPoint(sfc.Move[] moves)
        {
            spatial.Point point = new spatial.Point(0, 0);

            double deltaX = 0, deltaY = 0;

            for (int i = 0; i < moves.Length - 1; i++)
            {
                point = moves[i](point, 1);

                deltaX = Math.Min(point.X, deltaX);

                deltaY = Math.Min(point.Y, deltaY);
            }

            return(new spatial.Point(-deltaX, -deltaY));
        }
Example #15
0
        private List <spatial.Point> GetPoints()
        {
            sfc.Move[] movements = GetMoves(this.moves);

            spatial.Point startPoint = GetStartPoint(movements);

            List <spatial.Point> result = new List <spatial.Point>();

            result.Add(startPoint);

            for (int i = 0; i < movements.Length; i++)
            {
                startPoint = movements[i](startPoint, 1);

                result.Add(startPoint);
            }

            return(result);
        }
        public IRI.Msh.Common.Primitives.Point GetWgs84Point()
        {
            var point = new IRI.Msh.Common.Primitives.Point(X, Y);

            switch (this.SelectedItem?.MenuType)
            {
            case SpatialReferenceType.Geodetic:
                return(point);   //.Project( ,new IRI.Msh.CoordinateSystem.MapProjection.NoProjection());

            case SpatialReferenceType.UTM:
                return(point.Project(UTM.CreateForZone(UtmZone), new NoProjection()));

            case SpatialReferenceType.Mercator:
            case SpatialReferenceType.TransverseMercator:
            case SpatialReferenceType.CylindricalEqualArea:
            case SpatialReferenceType.LambertConformalConic:
            case SpatialReferenceType.WebMercator:
            case SpatialReferenceType.AlbersEqualAreaConic:
            default:
                throw new NotImplementedException();
            }
        }
Example #17
0
 public void StartNewPart(sb.Point webMercatorPoint)
 {
     this._editableFeatureLayer.StartNewPart(webMercatorPoint);
 }
Example #18
0
        public DrawingLayer(DrawMode mode, Transform toScreen, Func <double, double> screenToMap, sb.Point startMercatorPoint, EditableFeatureLayerOptions options)
        {
            this._mode = mode;

            sb.GeometryType type;

            switch (mode)
            {
            case DrawMode.Point:
                type = sb.GeometryType.Point;
                break;

            case DrawMode.Polyline:
                type = sb.GeometryType.LineString;
                break;

            case DrawMode.Polygon:
                type = sb.GeometryType.Polygon;
                break;

            case DrawMode.Rectange:
            case DrawMode.Freehand:
            default:
                throw new NotImplementedException();
            }

            //var options = new EditableFeatureLayerOptions() { IsVerticesLabelVisible = isEdgeLengthVisible };

            this._editableFeatureLayer = new EditableFeatureLayer("edit", new List <sb.Point>()
            {
                startMercatorPoint
            }, toScreen, screenToMap, type, options)
            {
                ZIndex = int.MaxValue
            };

            this._editableFeatureLayer.OnRequestFinishDrawing += (sender, e) => { this.OnRequestFinishDrawing.SafeInvoke(this); };

            this._editableFeatureLayer.RequestFinishEditing = g =>
            {
                this.RequestFinishEditing?.Invoke(g);
            };

            this._editableFeatureLayer.RequestCancelDrawing = () => { this.RequestCancelDrawing?.Invoke(); };

            this.VisibleRange = ScaleInterval.All;

            this.VisualParameters = new VisualParameters(mode == DrawMode.Polygon ? new SolidColorBrush(Colors.YellowGreen) : null, new SolidColorBrush(Colors.Blue), 3, 1);
        }
        public BezierItem(sb.Point startPoint, sb.Point endPoint, Transform toScreen)
        {
            this._toScreen = toScreen;

            var start = toScreen.Transform(startPoint.AsWpfPoint());

            var end = toScreen.Transform(endPoint.AsWpfPoint());

            var startControlPoint = toScreen.Transform(startPoint.AsWpfPoint());

            var endControlPoint = toScreen.Transform(endPoint.AsWpfPoint());


            var bezierSegment = new BezierSegment(startControlPoint, endControlPoint, end, true);

            _bezierFigure = new PathFigure()
            {
                StartPoint = start
            };

            _bezierFigure.Segments.Add(bezierSegment);

            PathGeometry bezierPathGeometry = new PathGeometry(new List <PathFigure>()
            {
                _bezierFigure
            });

            //pathGeometry.Transform = this.panTransformForPoints;


            _startControlLineFigure = new PathFigure()
            {
                StartPoint = start
            };

            _startControlLineFigure.Segments.Add(new LineSegment(startControlPoint, true));


            _endControlLineFigure = new PathFigure()
            {
                StartPoint = end
            };

            _endControlLineFigure.Segments.Add(new LineSegment(endControlPoint, true));

            StartLocateable = new Locateable(MapProjects.WebMercatorToGeodeticWgs84(startPoint))
            {
                Element = new View.MapMarkers.Circle(1, new SolidColorBrush(Colors.Green))
            };

            StartLocateable.OnPositionChanged += (sender, e) =>
            {
                var locateable = (Locateable)sender;

                var newPoint = toScreen.Transform(new System.Windows.Point(locateable.X, locateable.Y));

                _bezierFigure.StartPoint = newPoint;

                _startControlLineFigure.StartPoint = newPoint;

                //update();
            };


            EndLocateable = new Locateable(MapProjects.WebMercatorToGeodeticWgs84(endPoint))
            {
                Element = new View.MapMarkers.Circle(1, new SolidColorBrush(Colors.Green))
            };

            EndLocateable.OnPositionChanged += (sender, e) =>
            {
                var locateable = (Locateable)sender;

                var newPoint = toScreen.Transform(new System.Windows.Point(locateable.X, locateable.Y));

                bezierSegment.Point3 = newPoint;

                _endControlLineFigure.StartPoint = newPoint;

                //update();
            };


            StartControlLocateable = new Locateable(MapProjects.WebMercatorToGeodeticWgs84(startControlPoint.AsPoint()))
            {
                Element = new View.MapMarkers.Circle(1, new SolidColorBrush(Colors.Green))
            };

            StartControlLocateable.OnPositionChanged += (sender, e) =>
            {
                var locateable = (Locateable)sender;

                var newPoint = toScreen.Transform(new System.Windows.Point(locateable.X, locateable.Y));

                bezierSegment.Point1 = newPoint;

                (_startControlLineFigure.Segments.First() as LineSegment).Point = newPoint;

                //update();
            };


            EndControlLocateable = new Locateable(MapProjects.WebMercatorToGeodeticWgs84(endControlPoint.AsPoint()))
            {
                Element = new View.MapMarkers.Circle(1, new SolidColorBrush(Colors.Green))
            };

            EndControlLocateable.OnPositionChanged += (sender, e) =>
            {
                var locateable = (Locateable)sender;

                var newPoint = toScreen.Transform(new System.Windows.Point(locateable.X, locateable.Y));

                bezierSegment.Point2 = newPoint;

                (_endControlLineFigure.Segments.First() as LineSegment).Point = newPoint;

                //update();
            };



            Path temp = new Path();

            temp.Data            = bezierPathGeometry;
            temp.Stroke          = new SolidColorBrush(Colors.Black);
            temp.StrokeThickness = 2;
            //temp.RenderTransform = this.panTransformForPoints;
            //temp.Tag = new LayerTag(0) { IsTiled = false, LayerType = LayerType.Drawing };

            //this.mapView.Children.Add(temp);

            //Path axLine2 = new Path() { Stroke = new SolidColorBrush(Colors.Gray), StrokeThickness = 1, RenderTransform = panTransformForPoints };
            Path axLine2 = new Path()
            {
                Stroke = new SolidColorBrush(Colors.Gray), StrokeThickness = 1
            };

            axLine2.Data = new PathGeometry(new List <PathFigure>()
            {
                _startControlLineFigure
            });
            //axLine2.Tag = new LayerTag(-1) { IsTiled = false, LayerType = LayerType.Drawing };
            //this.mapView.Children.Add(axLine2);

            //Path axLine3 = new Path() { Stroke = new SolidColorBrush(Colors.Gray), StrokeThickness = 1, RenderTransform = panTransformForPoints };
            Path axLine3 = new Path()
            {
                Stroke = new SolidColorBrush(Colors.Gray), StrokeThickness = 1
            };

            axLine3.Data = new PathGeometry(new List <PathFigure>()
            {
                _endControlLineFigure
            });
            //axLine3.Tag = new LayerTag(-1) { IsTiled = false, LayerType = LayerType.Drawing };
            //this.mapView.Children.Add(axLine3);
        }
        internal static void Transform(drawing.Graphics graphics, sb.Geometry <sb.Point> original, sb.Point location, drawing.Pen pen, drawing.Brush brush)
        {
            if (original.Geometries != null)
            {
                foreach (var geometry in original.Geometries)
                {
                    Transform(graphics, geometry, location, pen, brush);
                }
            }
            else
            {
                if (original.NumberOfPoints < 1)
                {
                    return;
                }

                var firstPoint = original.Points[0];

                if (original.Type == sb.GeometryType.Point)
                {
                    graphics.DrawEllipse(pen, (float)(firstPoint.X + location.X), (float)(firstPoint.Y + location.Y), pointSize, pointSize);
                }
                else if (original.Type == IRI.Msh.Common.Primitives.GeometryType.LineString)
                {
                    AddLineString(graphics, original, location, pen, brush);
                }
            }
        }
        private static void AddLineString(drawing.Graphics graphics, sb.Geometry <sb.Point> original, sb.Point location, drawing.Pen pen, drawing.Brush brush)
        {
            if (original.NumberOfPoints < 1)
            {
                return;
            }

            for (int i = 1; i < original.NumberOfPoints; i++)
            {
                graphics.DrawLine(pen,
                                  (float)(original.Points[i - 1].X + location.X),
                                  (float)(original.Points[i - 1].Y + location.Y),
                                  (float)(original.Points[i].X + location.X),
                                  (float)(original.Points[i].Y + location.Y));
            }
        }
        internal static void Transform(WriteableBitmap context, sb.Geometry <sb.Point> original, sb.Point location, int border, int fill)
        {
            if (original.Geometries != null)
            {
                foreach (var geometry in original.Geometries)
                {
                    Transform(context, geometry, location, border, fill);
                }
            }
            else
            {
                if (original.NumberOfPoints < 1)
                {
                    return;
                }

                var firstPoint = original.Points[0];

                if (original.Type == sb.GeometryType.Point)
                {
                    context.DrawEllipseCentered(border, (int)(firstPoint.X + location.X), (int)(firstPoint.Y + location.Y), pointSize, pointSize);
                }
                else if (original.Type == IRI.Msh.Common.Primitives.GeometryType.LineString)
                {
                    AddLineString(context, original, location, border, fill);
                }
            }
        }
Example #23
0
        public void AddSemiVertex(Point webMercatorPoint)
        {
            var point = this.ToScreen(webMercatorPoint.AsWpfPoint());

            this._pathGeometry.Figures.Last().Segments.Add(new LineSegment(new WpfPoint(point.X, point.Y), true));
        }
Example #24
0
 public void AddSemiVertex(sb.Point webMercatorPoint)
 {
     this._editableFeatureLayer.AddSemiVertex(webMercatorPoint);
 }
        private static void AddLineString(WriteableBitmap context, sb.Geometry <sb.Point> original, sb.Point location, int border, int fill)
        {
            if (original.NumberOfPoints < 1)
            {
                return;
            }

            for (int i = 1; i < original.NumberOfPoints; i++)
            {
                context.DrawLine(
                    (int)(original.Points[i - 1].X + location.X),
                    (int)(original.Points[i - 1].Y + location.Y),
                    (int)(original.Points[i].X + location.X),
                    (int)(original.Points[i].Y + location.Y),
                    border);
            }
        }
Example #26
0
 public void AddVertex(Point webMercatorPoint)
 {
     AddVertex(webMercatorPoint, this._webMercatorGeometry, this._vertices);
 }
Example #27
0
 public void UpdateLastVertexLocation(sb.Point point)
 {
     this._editableFeatureLayer.UpdateLastSemiVertexLocation(point);
 }