public void Redraw(Transform toScreen) { _controlLines.Clear(); _polyBezier.Points.Clear(); _toScreen = toScreen; for (int i = 0; i < _controlLocateables.Count; i++) { int index = (int)Math.Ceiling(i / 2.0); var controlLine1 = new PathFigure() { StartPoint = toScreen.Transform(_mainLocateables[index].Location) }; controlLine1.Segments.Add(new LineSegment() { Point = toScreen.Transform(_controlLocateables[i].Location) }); _controlLines.Add(controlLine1); } for (int i = 1; i < _mainLocateables.Count; i++) { int index = 2 * i - 2; _polyBezier.Points.Add(toScreen.Transform(_controlLocateables[index].Location)); _polyBezier.Points.Add(toScreen.Transform(_controlLocateables[index + 1].Location)); _polyBezier.Points.Add(toScreen.Transform(_mainLocateables[i].Location)); } PathFigure mainFigure = new PathFigure() { StartPoint = toScreen.Transform(_mainLocateables[0].Location) }; mainFigure.Segments.Add(_polyBezier); PathGeometry mainGeometry = new PathGeometry(new List <PathFigure>() { mainFigure }); this._mainPath = new Path() { Tag = "PolyBezier _mainPath temp Tag", Data = mainGeometry, Stroke = _stroke, StrokeThickness = 4, Opacity = .9, Cursor = Cursors.Hand }; _mainPath.Tag = new LayerTag(0) { Layer = this, IsTiled = false, LayerType = LayerType.EditableItem }; this._mainPath.MouseRightButtonDown += _mainPath_MouseRightButtonDown; _mainPath.MouseEnter += (sender, e) => { _mainPath.StrokeThickness = 6; }; _mainPath.MouseLeave += (sender, e) => { _mainPath.StrokeThickness = 4; }; PathFigureCollection controlFigureCollection = new PathFigureCollection(_controlLines); PathGeometry controlGeometry = new PathGeometry(controlFigureCollection); this._controlPath = new Path() { Data = controlGeometry, Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 1 }; _controlPath.Tag = new LayerTag(0) { Layer = this, IsTiled = false, LayerType = LayerType.EditableItem }; this._mainLayer = new SpecialPointLayer($"POLYBEZIER MAIN {LayerId}", _mainLocateables, .9, ScaleInterval.All, LayerType.EditableItem | LayerType.MoveableItem) { AlwaysTop = true }; this._controlLayer = new SpecialPointLayer($"POLYBEZIER CONTROL {LayerId}", _controlLocateables, .9, ScaleInterval.All, LayerType.EditableItem | LayerType.MoveableItem) { AlwaysTop = true }; this._mainPath.MouseLeftButtonDown += (sender, e) => { this.IsControlsShown = !this.IsControlsShown; var newVisibility = this.IsControlsShown ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; this.GetControlPath().Visibility = newVisibility; if (this.IsControlsShown) { AddLayer(this.GetControlPointLayer()); } else { RemoveLayer(this.GetControlPointLayer()); } }; //if (IsDecorated) //{ Decorate(); //} }
/// <summary> /// For Polygons do not repeat first point in the last point /// </summary> /// <param name="name"></param> /// <param name="mercatorPoints"></param> /// <param name="isClosed"></param> public EditableFeatureLayer(string name, Geometry mercatorGeometry, Transform toScreen, Func <double, double> screenToMap, Model.EditableFeatureLayerOptions options = null) { //this._isNewDrawingMode = isNewDrawing; this.Options = options ?? Model.EditableFeatureLayerOptions.CreateDefault(); this.Options.RequestHandleIsEdgeLabelVisibleChanged = () => { //what if editable feature layer was already removed from map? UpdateEdgeLables(); }; this.LayerName = name; this._webMercatorGeometry = mercatorGeometry; this.LayerId = Guid.NewGuid(); this._toScreen = toScreen; this._screenToMap = screenToMap; this.VisibleRange = ScaleInterval.All; //this.VisualParameters = new VisualParameters(_mercatorGeometry.IsRingBase() ? _fill : null, _stroke, 3, 1); this.VisualParameters = Options.Visual; this._feature = GetDefaultEditingPath(); this._pathGeometry = new PathGeometry(); MakePathGeometry(); this._feature.Data = this._pathGeometry; //if //{ // this._feature.MouseUp += (sender, e) => { this.RegisterMapOptionsForNewPath(e); }; //} if (!Options.IsNewDrawing) { this._feature.MouseRightButtonDown += (sender, e) => { this.RegisterMapOptionsForEditPath(e); }; } var layerType = Options.IsNewDrawing ? LayerType.EditableItem : LayerType.MoveableItem | LayerType.EditableItem; this._primaryVerticesLayer = new SpecialPointLayer("vert", new List <Locateable>(), 1, ScaleInterval.All, layerType) { AlwaysTop = true }; this._primaryVerticesLayer.RequestSelectedLocatableChanged = (l) => this.RequestSelectedLocatableChanged?.Invoke(l); this._midVerticesLayer = new SpecialPointLayer("int. vert", new List <Locateable>(), .7, ScaleInterval.All, layerType) { AlwaysTop = true }; this._edgeLabelLayer = new SpecialPointLayer("edge length", new List <Locateable>(), .9, ScaleInterval.All, layerType) { AlwaysTop = false }; this._primaryVerticesLabelLayer = new SpecialPointLayer("vert length", new List <Locateable>(), .9, ScaleInterval.All, layerType) { AlwaysTop = false }; ReconstructLocateables(); if (Options.IsNewDrawing) { //add virtual vertex which show last point this.AddSemiVertex((Point)(mercatorGeometry.Points == null ? mercatorGeometry.Geometries.Last().Points.Last() : mercatorGeometry.Points.Last())); } }
public void Initialize() { _mainLocateables.Clear(); _controlLocateables.Clear(); _controlLines.Clear(); _polyBezier.Points.Clear(); this._mainLocateables = mercatorPolyline.Select(i => AsLocateable(i, Colors.Green)).ToList(); for (int i = 0; i < _mainLocateables.Count; i++) { _mainLocateables[i].OnPositionChanged += mainLocateable_OnPositionChanged; var locateable = _mainLocateables[i]; _mainLocateables[i].Element.MouseRightButtonDown += (sender, e) => { mainElement_MouseRightButtonDown(locateable, e); }; var point = mercatorPolyline[i]; var control1 = AsLocateable(point, Colors.Gray); var controlLine1 = new PathFigure() { StartPoint = _toScreen.Transform(_mainLocateables[i].Location) }; controlLine1.Segments.Add(new LineSegment() { Point = _toScreen.Transform(control1.Location) }); control1.OnPositionChanged += controlLocateable_OnPositionChanged; this._controlLocateables.Add(control1); _controlLines.Add(controlLine1); if (i == 0 || i == _mainLocateables.Count - 1) { continue; } var control2 = AsLocateable(point, Colors.Gray); var controlLine2 = new PathFigure() { StartPoint = _toScreen.Transform(_mainLocateables[i].Location) }; controlLine2.Segments.Add(new LineSegment() { Point = _toScreen.Transform(control2.Location) }); control2.OnPositionChanged += controlLocateable_OnPositionChanged; this._controlLocateables.Add(control2); _controlLines.Add(controlLine2); } for (int i = 1; i < _mainLocateables.Count; i++) { int index = 2 * i - 2; _polyBezier.Points.Add(_toScreen.Transform(_controlLocateables[index].Location)); _polyBezier.Points.Add(_toScreen.Transform(_controlLocateables[index + 1].Location)); _polyBezier.Points.Add(_toScreen.Transform(_mainLocateables[i].Location)); } PathFigure mainFigure = new PathFigure() { StartPoint = _toScreen.Transform(_mainLocateables[0].Location) }; mainFigure.Segments.Add(_polyBezier); PathGeometry mainGeometry = new PathGeometry(new List <PathFigure>() { mainFigure }); this._mainPath = new Path() { Data = mainGeometry, Stroke = _stroke, StrokeThickness = 3, Opacity = .9 }; PathFigureCollection controlFigureCollection = new PathFigureCollection(_controlLines); PathGeometry controlGeometry = new PathGeometry(controlFigureCollection); this._controlPath = new Path() { Data = controlGeometry, Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 1 }; this._mainLayer = new SpecialPointLayer("1", _mainLocateables, .9, ScaleInterval.All, LayerType.EditableItem | LayerType.MoveableItem) { AlwaysTop = true }; this._controlLayer = new SpecialPointLayer("2", _controlLocateables, .9, ScaleInterval.All, LayerType.EditableItem | LayerType.MoveableItem) { AlwaysTop = true }; }