Index: src/Common/SharpMap.UI/Tools/SelectTool.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/SharpMap.UI/Tools/SelectTool.cs (.../SelectTool.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/SharpMap.UI/Tools/SelectTool.cs (.../SelectTool.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -7,12 +7,13 @@ using System.Windows.Forms; using DelftTools.Utils; using DelftTools.Utils.Collections; +using GeoAPI.CoordinateSystems.Transformations; using GeoAPI.Extensions.Feature; using GeoAPI.Geometries; +using GisSharpBlog.NetTopologySuite.Geometries; using log4net; using SharpMap.Api.Editors; using SharpMap.Api.Layers; -using SharpMap.Converters.Geometries; using SharpMap.Data.Providers; using SharpMap.Layers; using SharpMap.Rendering; @@ -21,6 +22,7 @@ using SharpMap.UI.Forms; using SharpMap.UI.Helpers; using SharpMap.UI.Properties; +using GeometryFactory = SharpMap.Converters.Geometries.GeometryFactory; namespace SharpMap.UI.Tools { @@ -64,22 +66,23 @@ /// public class SelectTool : MapTool { + public event EventHandler SelectionChanged; + public static int MaxSelectedFeatures = 5000; private static readonly ILog log = LogManager.GetLogger(typeof(SelectTool)); private static readonly IDictionary stylesCache = new Dictionary(); private readonly Collection trackers = new Collection(); + private readonly List selectPoints = new List(); + private readonly VectorLayer trackingLayer; + private DateTime orgClickTime; - private readonly List selectPoints = new List(); - + private ICoordinate mouseDownLocation; // TODO: remove me private ICoordinate orgMouseDownLocation; private ICoordinate WORLDPOSITION; - private readonly VectorLayer trackingLayer; - private bool isMultiSelect; - public static int MaxSelectedFeatures = 5000; public SelectTool() { @@ -89,10 +92,13 @@ SelectedFeatureInteractors = new List(); trackingLayer = new VectorLayer("Trackers") + { + DataSource = new FeatureCollection { - DataSource = new FeatureCollection {Features = trackers}, - Theme = new CustomTheme(GetTrackerStyle) - }; + Features = trackers + }, + Theme = new CustomTheme(GetTrackerStyle) + }; } public override Cursor Cursor @@ -111,31 +117,12 @@ } } - public MultiSelectionMode MultiSelectionMode { get; set; } - - /// - /// Interactors created for selected features. - /// - public IList SelectedFeatureInteractors { get; private set; } - - public bool KeyToggleSelection - { - get { return ((Control.ModifierKeys & Keys.Control) == Keys.Control); } - } - - public bool KeyExtendSelection - { - get { return ((Control.ModifierKeys & Keys.Shift) == Keys.Shift); } - } - - public IEnumerable Selection - { - get { return SelectedFeatureInteractors.Select(interactor => interactor.SourceFeature); } - } - public override IMapControl MapControl { - get { return base.MapControl; } + get + { + return base.MapControl; + } set { base.MapControl = value; @@ -145,7 +132,10 @@ public override bool IsActive { - get { return base.IsActive; } + get + { + return base.IsActive; + } set { base.IsActive = value; @@ -162,27 +152,35 @@ } } - public override void OnPaint(PaintEventArgs e) + public MultiSelectionMode MultiSelectionMode { get; set; } + + /// + /// Interactors created for selected features. + /// + public IList SelectedFeatureInteractors { get; private set; } + + public bool KeyToggleSelection { - base.OnPaint(e); - Render(e.Graphics, MapControl.Map); + get + { + return ((Control.ModifierKeys & Keys.Control) == Keys.Control); + } } - public override void Render(Graphics graphics, Map map) + public bool KeyExtendSelection { - // Render the selectionLayer and trackingLayer - // Bypass ILayer.Render and call OnRender directly; this is more efficient - foreach (var tracker in trackers.Where(tracker => tracker.FeatureInteractor.SourceFeature != null)) + get { - // todo optimize this; only necessary when map extent has changed. - var interactor = tracker.FeatureInteractor; - var feature = interactor.TargetFeature ?? interactor.SourceFeature; - - interactor.UpdateTracker(feature.Geometry); + return ((Control.ModifierKeys & Keys.Shift) == Keys.Shift); } + } - SynchronizeTrackers(); - trackingLayer.OnRender(graphics, map); + public IEnumerable Selection + { + get + { + return SelectedFeatureInteractors.Select(interactor => interactor.SourceFeature); + } } public TrackerFeature GetTrackerAtCoordinate(ICoordinate worldPos) @@ -195,11 +193,14 @@ if (featureInteractor.Layer != null && featureInteractor.Layer.CoordinateTransformation != null) { var mathTransform = featureInteractor.Layer.CoordinateTransformation.MathTransform.Inverse(); - coordinate = TransformCoordinate(worldPos,mathTransform); + coordinate = TransformCoordinate(worldPos, mathTransform); } trackerFeature = featureInteractor.GetTrackerAtCoordinate(coordinate); - if (trackerFeature != null) break; + if (trackerFeature != null) + { + break; + } } return trackerFeature; } @@ -239,13 +240,19 @@ UpdateMapControlSelection(); } - public void AddSelection(ILayer layer, IFeature feature, bool synchronizeUI = true, bool checkIfAlreadySelected=true) + public void AddSelection(ILayer layer, IFeature feature, bool synchronizeUI = true, bool checkIfAlreadySelected = true) { // If already selected, do nothing. - if (!layer.Visible || (checkIfAlreadySelected && Selection.Contains(feature))) return; + if (!layer.Visible || (checkIfAlreadySelected && Selection.Contains(feature))) + { + return; + } var featureInteractor = GetFeatureInteractor(layer, feature); - if (featureInteractor == null) return; + if (featureInteractor == null) + { + return; + } SelectedFeatureInteractors.Add(featureInteractor); @@ -255,16 +262,162 @@ } } + /// + /// Selects the given features on the map. Will search all layers for the features when no vector layer is provided + /// + /// The feature to select on the map. + /// The layer on which the features reside. + public bool Select(IEnumerable featuresToSelect, ILayer vectorLayer = null, bool checkIfAlreadySelected = true) + { + if (featuresToSelect == null) + { + Clear(true); + return false; + } + + var features = featuresToSelect as IList ?? featuresToSelect.ToList(); + if (features.Count > MaxSelectedFeatures) + { + log.Warn(string.Format("Can't select {0} features at once, selecting only first {1} features.", features.Count, MaxSelectedFeatures)); + features = features.Take(MaxSelectedFeatures).ToList(); + } + + Clear(false); + VectorLayer foundLayer = null; + //var selectionFailsBecauseFeatureCannotBeFoundInLayer = new List(); + var warningMessages = new List(); + var inLayer = false; + foreach (var feature in features) + { + if (vectorLayer != null) + { + foundLayer = vectorLayer as VectorLayer; + inLayer = foundLayer != null && foundLayer.DataSource.Features.Contains(feature); + } + else if (foundLayer == null || foundLayer.DataSource == null || foundLayer.DataSource.Features == null) + { + foundLayer = Map.GetLayerByFeature(feature) as VectorLayer; + inLayer = foundLayer != null; + } + else + { + inLayer = foundLayer.DataSource.Features.Contains(feature); + if (!inLayer) + { + foundLayer = Map.GetLayerByFeature(feature) as VectorLayer; + inLayer = foundLayer != null; + } + } + + if (foundLayer != null) + { + if (inLayer) + { + AddSelection(foundLayer, feature, ReferenceEquals(feature, features.Last()), checkIfAlreadySelected); + } + else + { + var message = string.Format("The feature '{1}' you want to select is NOT in the layer '{0}'", + foundLayer.Name, + feature is INameable ? ((INameable) feature).Name : feature.ToString()); + warningMessages.Add(message); + } + } + } + if (warningMessages.Count > 0) + { + log.Warn(string.Join(Environment.NewLine, warningMessages)); + } + return true; + } + + /// + /// Selects the given feature on the map. Will search all layers for the feature. + /// + /// The feature to select on the map. + public bool Select(IFeature featureToSelect) + { + if (null == featureToSelect) + { + Clear(true); + return false; + } + // Find the layer that this feature is on + ILayer foundLayer = MapControl.Map.GetLayerByFeature(featureToSelect); + if (foundLayer != null && foundLayer is VectorLayer) + { + // Select the feature + Select(foundLayer, featureToSelect); + return true; + } + + return false; + } + + public void Select(ILayer vectorLayer, IFeature feature) + { + if (IsBusy) + { + return; + } + + Clear(false); + SetSelection(feature, vectorLayer); + UpdateMapControlSelection(true); + } + + /// + /// Checks if selected features are actually need to be selected. + /// + public void RefreshSelection() + { + var visibleLayers = Map.GetAllVisibleLayers(true).ToList(); + + // check if selected features still exist in the providers + + SelectedFeatureInteractors.Where(featureInteractor => featureInteractor.Layer.DataSource == null || !featureInteractor.Layer.DataSource.Features.Contains(featureInteractor.SourceFeature)).ToArray() + .ForEach(fi => SelectedFeatureInteractors.Remove(fi)); + + SelectedFeatureInteractors.RemoveAllWhere(i => !visibleLayers.Contains(i.Layer)); + UpdateMapControlSelection(); + } + + public override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + Render(e.Graphics, MapControl.Map); + } + + public override void Render(Graphics graphics, Map map) + { + // Render the selectionLayer and trackingLayer + // Bypass ILayer.Render and call OnRender directly; this is more efficient + foreach (var tracker in trackers.Where(tracker => tracker.FeatureInteractor.SourceFeature != null)) + { + // todo optimize this; only necessary when map extent has changed. + var interactor = tracker.FeatureInteractor; + var feature = interactor.TargetFeature ?? interactor.SourceFeature; + + interactor.UpdateTracker(feature.Geometry); + } + + SynchronizeTrackers(); + trackingLayer.OnRender(graphics, map); + } + public override IEnumerable GetContextMenuItems(ICoordinate worldPosition) { var selectFeatureMenu = CreateContextMenuItemForFeaturesAtLocation(worldPosition, "Select", Select, false); - if (selectFeatureMenu == null || selectFeatureMenu.DropDownItems.Count == 0) yield break; + if (selectFeatureMenu == null || selectFeatureMenu.DropDownItems.Count == 0) + { + yield break; + } yield return new MapToolContextMenuItem - { - Priority = 1, - MenuItem = selectFeatureMenu - }; + { + Priority = 1, + MenuItem = selectFeatureMenu + }; } public override void OnDraw(Graphics graphics) @@ -294,12 +447,12 @@ { var point1 = Map.WorldToImage(GeometryFactory.CreateCoordinate(mouseDownLocation.X, mouseDownLocation.Y)); var point2 = Map.WorldToImage(GeometryFactory.CreateCoordinate(WORLDPOSITION.X, WORLDPOSITION.Y)); - - var rectangle = new Rectangle((int)Math.Min(point1.X, point2.X), - (int)Math.Min(point1.Y, point2.Y), - (int)Math.Abs(point1.X - point2.X), - (int)Math.Abs(point1.Y - point2.Y)); + var rectangle = new Rectangle((int) Math.Min(point1.X, point2.X), + (int) Math.Min(point1.Y, point2.Y), + (int) Math.Abs(point1.X - point2.X), + (int) Math.Abs(point1.Y - point2.Y)); + using (var pen = new Pen(color)) { graphics.DrawRectangle(pen, rectangle); @@ -314,20 +467,26 @@ public override void OnMouseDown(ICoordinate worldPosition, MouseEventArgs e) { - if (e.Button != MouseButtons.Left) return; + if (e.Button != MouseButtons.Left) + { + return; + } mouseDownLocation = worldPosition; orgMouseDownLocation = null; IsBusy = true; - + var trackerFeature = SelectedFeatureInteractors.Count <= 1 - ? GetTrackerAtCoordinate(worldPosition) - : null; // hack: if multiple selection toggle/select complete feature + ? GetTrackerAtCoordinate(worldPosition) + : null; // hack: if multiple selection toggle/select complete feature if (trackerFeature != null) { - if (SelectedFeatureInteractors.Count != 1) return; + if (SelectedFeatureInteractors.Count != 1) + { + return; + } orgMouseDownLocation = (ICoordinate) worldPosition.Clone(); FocusTracker(trackerFeature); @@ -336,10 +495,10 @@ } ILayer selectedLayer; - - var limit = (float)MapHelper.ImageToWorld(Map, 4); + + var limit = (float) MapHelper.ImageToWorld(Map, 4); var nearest = FindNearestFeature(worldPosition, limit, out selectedLayer, ol => ol.Visible); - + if (nearest != null) { SelectFeature(worldPosition, nearest, selectedLayer); @@ -359,7 +518,10 @@ public override void OnMouseMove(ICoordinate worldPosition, MouseEventArgs e) { - if (!isMultiSelect) return; + if (!isMultiSelect) + { + return; + } UpdateMultiSelection(worldPosition); DoDrawing(false); @@ -372,7 +534,10 @@ public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e) { - if (e.Button != MouseButtons.Left) return; + if (e.Button != MouseButtons.Left) + { + return; + } if (isMultiSelect) { @@ -391,10 +556,10 @@ { //make sure parent layer is selectable or null var parentLayer = Map.GetGroupLayerContainingLayer(layer); - if ( (parentLayer == null || parentLayer.IsSelectable) && layer.IsSelectable && layer is VectorLayer) + if ((parentLayer == null || parentLayer.IsSelectable) && layer.IsSelectable && layer is VectorLayer) { // do not use the maptool provider but the datasource of each layer. - var vectorLayer = (VectorLayer)layer; + var vectorLayer = (VectorLayer) layer; var multiFeatures = vectorLayer.GetFeatures(selectionPolygon).Take(MaxSelectedFeatures); foreach (var feature in multiFeatures) { @@ -413,7 +578,7 @@ // if mouse hasn't moved handle as single select. A normal multi select uses the envelope // of the geometry and this has as result that unwanted features will be selected. ILayer selectedLayer; - var limit = (float)MapHelper.ImageToWorld(Map, 4); + var limit = (float) MapHelper.ImageToWorld(Map, 4); var nearest = FindNearestFeature(worldPosition, limit, out selectedLayer, ol => ol.Visible); if (nearest != null) { @@ -439,11 +604,11 @@ // check if selection exists; could be toggled ILayer outLayer; IFeature nextFeature = GetNextFeatureAtPosition(worldPosition, - // set limit from 4 to 10: TOOLS-1499 - (float)MapHelper.ImageToWorld(Map, 10), - out outLayer, - SelectedFeatureInteractors[0].SourceFeature, - ol => ol.Visible); + // set limit from 4 to 10: TOOLS-1499 + (float) MapHelper.ImageToWorld(Map, 10), + out outLayer, + SelectedFeatureInteractors[0].SourceFeature, + ol => ol.Visible); if (null != nextFeature) { Clear(false); @@ -460,139 +625,40 @@ orgClickTime = DateTime.Now; } - /// - /// Selects the given features on the map. Will search all layers for the features when no vector layer is provided - /// - /// The feature to select on the map. - /// The layer on which the features reside. - public bool Select(IEnumerable featuresToSelect, ILayer vectorLayer = null, bool checkIfAlreadySelected = true) + public override void OnMapCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { - if (featuresToSelect == null) + switch (e.Action) { - Clear(true); - return false; - } - - var features = featuresToSelect as IList ?? featuresToSelect.ToList(); - if (features.Count > MaxSelectedFeatures) - { - log.Warn(string.Format("Can't select {0} features at once, selecting only first {1} features.",features.Count,MaxSelectedFeatures)); - features = features.Take(MaxSelectedFeatures).ToList(); - } - - Clear(false); - VectorLayer foundLayer = null; - //var selectionFailsBecauseFeatureCannotBeFoundInLayer = new List(); - var warningMessages = new List(); - var inLayer = false; - foreach (var feature in features) - { - if (vectorLayer != null) + case NotifyCollectionChangeAction.Remove: { - foundLayer = vectorLayer as VectorLayer; - inLayer = foundLayer != null && foundLayer.DataSource.Features.Contains(feature); - } - else if (foundLayer == null || foundLayer.DataSource == null || foundLayer.DataSource.Features == null) - { - foundLayer = Map.GetLayerByFeature(feature) as VectorLayer; - inLayer = foundLayer != null; - } - else - { - inLayer = foundLayer.DataSource.Features.Contains(feature); - if (!inLayer) + if (e.Item is ILayer) { - foundLayer = Map.GetLayerByFeature(feature) as VectorLayer; - inLayer = foundLayer != null; + RefreshSelection(); } - } - if (foundLayer != null ) - { - if (inLayer) - AddSelection(foundLayer, feature, ReferenceEquals(feature, features.Last()), checkIfAlreadySelected); - else + if (sender is Map) { - var message = string.Format("The feature '{1}' you want to select is NOT in the layer '{0}'", - foundLayer.Name, - feature is INameable ? ((INameable) feature).Name : feature.ToString()); - warningMessages.Add(message); - } - } - } - if (warningMessages.Count > 0) - log.Warn(string.Join(Environment.NewLine, warningMessages)); - return true; - } - - /// - /// Selects the given feature on the map. Will search all layers for the feature. - /// - /// The feature to select on the map. - public bool Select(IFeature featureToSelect) - { - if (null == featureToSelect) - { - Clear(true); - return false; - } - // Find the layer that this feature is on - ILayer foundLayer = MapControl.Map.GetLayerByFeature(featureToSelect); - if (foundLayer != null && foundLayer is VectorLayer) - { - // Select the feature - Select(foundLayer, featureToSelect); - return true; - } - - return false; - } - - public void Select(ILayer vectorLayer, IFeature feature) - { - if (IsBusy) - { - return; - } - - Clear(false); - SetSelection(feature, vectorLayer); - UpdateMapControlSelection(true); - } - - public override void OnMapCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) - { - switch (e.Action) - { - case NotifyCollectionChangeAction.Remove: - { - if(e.Item is ILayer) + var layer = (ILayer) e.Item; + if (layer is GroupLayer) { - RefreshSelection(); - } - - if (sender is Map) - { - var layer = (ILayer)e.Item; - if (layer is GroupLayer) + var layerGroup = (GroupLayer) layer; + foreach (ILayer layerGroupLayer in layerGroup.Layers) { - var layerGroup = (GroupLayer)layer; - foreach (ILayer layerGroupLayer in layerGroup.Layers) - { - HandleLayerStatusChanged(layerGroupLayer); - } + HandleLayerStatusChanged(layerGroupLayer); } - else - { - HandleLayerStatusChanged(layer); - } } - break; + else + { + HandleLayerStatusChanged(layer); + } } + break; + } case NotifyCollectionChangeAction.Replace: throw new NotImplementedException(); } } + /// /// todo add cancel method to IMapTool /// todo mousedown clears selection -> complex selection -> start multi select -> cancel -> original selection lost @@ -632,7 +698,7 @@ // from the selection, but this simple and effective. if (layer is GroupLayer) { - var layerGroup = (GroupLayer)layer; + var layerGroup = (GroupLayer) layer; foreach (ILayer layerGroupLayer in layerGroup.Layers) { HandleLayerStatusChanged(layerGroupLayer); @@ -646,24 +712,6 @@ } } - /// - /// Checks if selected features are actually need to be selected. - /// - public void RefreshSelection() - { - var visibleLayers = Map.GetAllVisibleLayers(true).ToList(); - - // check if selected features still exist in the providers - - SelectedFeatureInteractors.Where(featureInteractor => featureInteractor.Layer.DataSource == null || !featureInteractor.Layer.DataSource.Features.Contains(featureInteractor.SourceFeature)).ToArray() - .ForEach(fi => SelectedFeatureInteractors.Remove(fi)); - - SelectedFeatureInteractors.RemoveAllWhere(i => !visibleLayers.Contains(i.Layer)); - UpdateMapControlSelection(); - } - - public event EventHandler SelectionChanged; - protected virtual void SelectFeature(ICoordinate worldPosition, IFeature nearestFeature, ILayer selectedLayer) { // Create or add a new FeatureInteractor @@ -692,7 +740,7 @@ { // no special key processing; handle as a single select. Clear(false); - + if (!StartSelection(selectedLayer, nearestFeature)) { StartMultiSelect(); @@ -731,6 +779,36 @@ StartDrawing(); } + protected bool StartSelection(ILayer layer, IFeature feature) + { + var featureInteractor = GetFeatureInteractor(layer, feature); + if (null == featureInteractor) + { + return false; + } + + if (featureInteractor.AllowSingleClickAndMove()) + { + // do not yet select, but allow MltiSelect + SelectedFeatureInteractors.Add(featureInteractor); + SynchronizeTrackers(); + UpdateMapControlSelection(); + return true; + } + return false; + } + + internal void RefreshFeatureInteractors() + { + var selectedFeaturesWithLayer = SelectedFeatureInteractors.Select(fe => new + { + Feature = fe.SourceFeature, fe.Layer + }).ToList(); + SelectedFeatureInteractors.Clear(); + selectedFeaturesWithLayer.ForEach(fl => SelectedFeatureInteractors.Add(GetFeatureInteractor(fl.Layer, fl.Feature))); + SynchronizeTrackers(); + } + private void StopMultiSelect() { isMultiSelect = false; @@ -744,7 +822,7 @@ /// private static VectorStyle GetTrackerStyle(IFeature feature) { - var trackerFeature = (TrackerFeature)feature; + var trackerFeature = (TrackerFeature) feature; VectorStyle style; @@ -753,7 +831,10 @@ { if (!stylesCache.ContainsKey(trackerFeature.Bitmap)) { - style = new VectorStyle { Symbol = trackerFeature.Bitmap }; + style = new VectorStyle + { + Symbol = trackerFeature.Bitmap + }; stylesCache[trackerFeature.Bitmap] = style; } else @@ -769,11 +850,13 @@ { SelectedFeatureInteractors.Clear(); if (trackingLayer.DataSource.GetFeatureCount() <= 0) + { return; + } trackers.Clear(); trackingLayer.RenderRequired = true; - + UpdateMapControlSelection(fireSelectionChangedEvent); } @@ -789,22 +872,6 @@ trackingLayer.RenderRequired = true; } - protected bool StartSelection(ILayer layer, IFeature feature) - { - var featureInteractor = GetFeatureInteractor(layer, feature); - if (null == featureInteractor) return false; - - if (featureInteractor.AllowSingleClickAndMove()) - { - // do not yet select, but allow MltiSelect - SelectedFeatureInteractors.Add(featureInteractor); - SynchronizeTrackers(); - UpdateMapControlSelection(); - return true; - } - return false; - } - /// /// Sets the selected object in the selectTool. SetSelection supports also the toggling/extending the /// selected Trackers. @@ -823,7 +890,7 @@ IList featureTrackers = new List(); for (int i = 0; i < trackingLayer.DataSource.Features.Count; i++) { - var trackerFeature = (TrackerFeature)trackingLayer.DataSource.Features[i]; + var trackerFeature = (TrackerFeature) trackingLayer.DataSource.Features[i]; if (ReferenceEquals(trackerFeature, feature)) { featureTrackers.Add(i); @@ -833,11 +900,13 @@ AddSelection(featureLayer, feature); } } - + private void FocusTracker(TrackerFeature trackFeature) { if (null == trackFeature) + { return; + } if (!((KeyToggleSelection) || (KeyExtendSelection))) { @@ -883,16 +952,15 @@ private static IPolygon CreatePolygon(double left, double top, double right, double bottom) { var vertices = new List - { - GeometryFactory.CreateCoordinate(left, bottom), - GeometryFactory.CreateCoordinate(right, bottom), - GeometryFactory.CreateCoordinate(right, top), - GeometryFactory.CreateCoordinate(left, top) - }; - vertices.Add((ICoordinate)vertices[0].Clone()); + { + GeometryFactory.CreateCoordinate(left, bottom), + GeometryFactory.CreateCoordinate(right, bottom), + GeometryFactory.CreateCoordinate(right, top), + GeometryFactory.CreateCoordinate(left, top) + }; + vertices.Add((ICoordinate) vertices[0].Clone()); ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray()); return GeometryFactory.CreatePolygon(newLinearRing, null); - } private IPolygon CreateSelectionPolygon(ICoordinate worldPosition) @@ -908,9 +976,9 @@ return null; } return CreatePolygon(Math.Min(mouseDownLocation.X, worldPosition.X), - Math.Max(mouseDownLocation.Y, worldPosition.Y), - Math.Max(mouseDownLocation.X, worldPosition.X), - Math.Min(mouseDownLocation.Y, worldPosition.Y)); + Math.Max(mouseDownLocation.Y, worldPosition.Y), + Math.Max(mouseDownLocation.X, worldPosition.X), + Math.Min(mouseDownLocation.Y, worldPosition.Y)); } var vertices = selectPoints.Select(point => Map.ImageToWorld(point)).ToList(); @@ -919,8 +987,8 @@ // too few points to create a polygon return null; } - vertices.Add((ICoordinate)worldPosition.Clone()); - vertices.Add((ICoordinate)vertices[0].Clone()); + vertices.Add((ICoordinate) worldPosition.Clone()); + vertices.Add((ICoordinate) vertices[0].Clone()); ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray()); return GeometryFactory.CreatePolygon(newLinearRing, null); } @@ -930,12 +998,16 @@ UpdateMapControlSelection(true); } - private static ICoordinate TransformCoordinate(ICoordinate coordinate, GeoAPI.CoordinateSystems.Transformations. IMathTransform mathTransform) + private static ICoordinate TransformCoordinate(ICoordinate coordinate, IMathTransform mathTransform) { - var transformCoordinate = mathTransform.Transform(new[] { coordinate.X, coordinate.Y }); - return new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(transformCoordinate[0], transformCoordinate[1]); + var transformCoordinate = mathTransform.Transform(new[] + { + coordinate.X, + coordinate.Y + }); + return new Coordinate(transformCoordinate[0], transformCoordinate[1]); } - + private void UpdateMapControlSelection(bool fireSelectionChangedEvent) { SynchronizeTrackers(); @@ -957,13 +1029,5 @@ Clear(); } } - - internal void RefreshFeatureInteractors() - { - var selectedFeaturesWithLayer = SelectedFeatureInteractors.Select(fe => new {Feature = fe.SourceFeature, fe.Layer}).ToList(); - SelectedFeatureInteractors.Clear(); - selectedFeaturesWithLayer.ForEach(fl => SelectedFeatureInteractors.Add(GetFeatureInteractor(fl.Layer, fl.Feature))); - SynchronizeTrackers(); - } } } \ No newline at end of file