Esempio n. 1
0
        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();
        }
Esempio n. 2
0
 private void Clear(bool fireSelectionChangedEvent)
 {
     SelectedFeatureInteractors.Clear();
     if (trackingLayer.DataSource.GetFeatureCount() <= 0)
     {
         return;
     }
     trackers.Clear();
     trackingLayer.RenderRequired = true;
     UpdateMapControlSelection(fireSelectionChangedEvent);
 }
Esempio n. 3
0
 private void RemoveSelection(IFeature feature)
 {
     for (int i = 0; i < SelectedFeatureInteractors.Count; i++)
     {
         if (ReferenceEquals(SelectedFeatureInteractors[i].SourceFeature, feature))
         {
             SelectedFeatureInteractors.RemoveAt(i);
             break;
         }
     }
     UpdateMapControlSelection();
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        /// 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);
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 private IFeatureInteractor GetActiveFeatureInteractor(IFeature feature)
 {
     return(SelectedFeatureInteractors.FirstOrDefault(t => ReferenceEquals(t.SourceFeature, feature)));
 }
Esempio n. 9
0
        /// <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));
        }