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 Clear(bool fireSelectionChangedEvent) { SelectedFeatureInteractors.Clear(); if (trackingLayer.DataSource.GetFeatureCount() <= 0) { return; } trackers.Clear(); trackingLayer.RenderRequired = true; UpdateMapControlSelection(fireSelectionChangedEvent); }
private void RemoveSelection(IFeature feature) { for (int i = 0; i < SelectedFeatureInteractors.Count; i++) { if (ReferenceEquals(SelectedFeatureInteractors[i].SourceFeature, feature)) { SelectedFeatureInteractors.RemoveAt(i); break; } } UpdateMapControlSelection(); }
private void UpdateMapControlSelection(bool fireSelectionChangedEvent) { SynchronizeTrackers(); IList <IFeature> selectedFeatures = SelectedFeatureInteractors.Select(t => t.SourceFeature).ToList(); MapControl.SelectedFeatures = selectedFeatures; if (fireSelectionChangedEvent && SelectionChanged != null) { SelectionChanged(this, null); } }
/// TODO: note if no features are selected the selection rectangle maintains visible after mouse up /// ISSUE 2373 private void HandleMultiSelectMouseUp(Coordinate worldPosition) { StopMultiSelect(); List <IFeature> selectedFeatures = null; if (!KeyExtendSelection) { selectedFeatures = new List <IFeature>(SelectedFeatureInteractors.Select(fe => fe.SourceFeature).ToArray()); Clear(false); } var selectionPolygon = CreateSelectionPolygon(worldPosition); if (null != selectionPolygon) { foreach (ILayer layer in Map.GetAllVisibleLayers(false)) { //make sure parent layer is selectable or null var parentLayer = Map.GetGroupLayerContainingLayer(layer); 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 multiFeatures = vectorLayer.GetFeatures(selectionPolygon).Take(5000); foreach (IFeature feature in multiFeatures) { if ((null != selectedFeatures) && (selectedFeatures.Contains(feature))) { continue; } AddSelection(vectorLayer, feature, false); } } } } else { // 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 nearest = FindNearestFeature(worldPosition, limit, out selectedLayer, ol => ol.Visible); if (null != nearest) { AddSelection(selectedLayer, nearest, false); } } // synchronize with map selection, possible check if selection is already set; do not remove UpdateMapControlSelection(true); }
public void AddSelection(ILayer layer, IFeature feature, bool synchronizeUI = true) { if (!layer.Visible) { return; } var featureInteractor = GetFeatureInteractor(layer, feature); if (null == featureInteractor) { return; } SelectedFeatureInteractors.Add(featureInteractor); if (synchronizeUI) { UpdateMapControlSelection(); } }
private 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); }
private IFeatureInteractor GetActiveFeatureInteractor(IFeature feature) { return(SelectedFeatureInteractors.FirstOrDefault(t => ReferenceEquals(t.SourceFeature, feature))); }
/// <summary> /// Checks if selected features are actually need to be selected. /// </summary> public void RefreshSelection() { var layers = Map.GetAllVisibleLayers(true).ToArray(); SelectedFeatureInteractors.Where(i => !layers.Contains(i.Layer)).ToList().ForEach(i => RemoveSelection(i.SourceFeature)); }