Ejemplo n.º 1
0
        /// TODO: note if no features are selected the selection rectangle maintains visible after mouse up
        /// ISSUE 2373
        private void HandleMultiSelectMouseUp(ICoordinate worldPosition)
        {
            StopMultiSelect();
            List <IFeature> selectedFeatures = null;

            if (!KeyExtendSelection)
            {
                selectedFeatures = new List <IFeature>(FeatureEditors.Select(fe => fe.SourceFeature).ToArray());
                Clear(false);
            }
            IPolygon selectionPolygon = CreateSelectionPolygon(worldPosition);

            if (null != selectionPolygon)
            {
                foreach (ILayer layer in Map.GetAllLayers(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;
                        IList multiFeatures = vectorLayer.DataSource.GetFeatures(selectionPolygon);
                        for (int i = 0; i < multiFeatures.Count; i++)
                        {
                            var feature = (IFeature)multiFeatures[i];
                            if ((null != selectedFeatures) && (selectedFeatures.Contains(feature)))
                            {
                                continue;
                            }
                            AddSelection(vectorLayer, feature, -1, 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;
                float    limit   = (float)MapHelper.ImageToWorld(Map, 4);
                IFeature nearest = FindNearestFeature(worldPosition, limit, out selectedLayer, ol => ol.Visible);
                if (null != nearest) //&& (selectedLayer.IsVisible))
                {
                    AddSelection(selectedLayer, nearest, -1, false);
                }
            }

            selectPoints.Clear();
            // synchronize with map selection, possible check if selection is already set; do not remove
            UpdateMapControlSelection(true);
        }
Ejemplo n.º 2
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (IsMultiSelect)
            {
                StopMultiSelect();
                List <IFeature> selectedFeatures = null;
                if (!KeyExtendSelection)
                {
                    selectedFeatures = new List <IFeature>(FeatureEditors.Select(fe => fe.SourceFeature).ToArray());
                    Clear();
                }
                IPolygon selectionPolygon = CreateSelectionPolygon(worldPosition);
                if (null != selectionPolygon)
                {
                    foreach (ILayer layer in MapHelper.GetAllMapLayers(Map.Layers, false))
                    {
                        if ((!layer.ReadOnly) && (layer is VectorLayer))
                        {
                            // do not use the maptool provider but the datasource of each layer.
                            VectorLayer vectorLayer = (VectorLayer)layer;
                            if (vectorLayer.IsVisible)
                            {
                                IList multiFeatures = vectorLayer.DataSource.GetFeatures(selectionPolygon);
                                for (int i = 0; i < multiFeatures.Count; i++)
                                {
                                    IFeature feature = (IFeature)multiFeatures[i];
                                    if ((null != selectedFeatures) && (selectedFeatures.Contains(feature)))
                                    {
                                        continue;
                                    }
                                    AddSelection(vectorLayer, feature, -1, 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;
                    float    limit   = (float)MapControlHelper.ImageToWorld(Map, 4);
                    IFeature nearest = FindNearestFeature(worldPosition, limit, out selectedLayer, ol => ol.IsVisible);
                    if (null != nearest) //&& (selectedLayer.IsVisible))
                    {
                        AddSelection(selectedLayer, nearest, -1, false);
                    }
                }
                // synchronize with map selection, possible check if selection is already set; do not remove
                UpdateMapControlSelection();
                //MapControl.Refresh();
                //IsMultiSelect = false;
            }
            else
            {
                if ((null != orgMouseDownLocation) && (orgMouseDownLocation.X == worldPosition.X) &&
                    (orgMouseDownLocation.Y == worldPosition.Y) && (e.Button == MouseButtons.Left))
                {
                    // check if mouse was pressed at a selected object without moving the mouse. The default behaviour
                    // should be to select 'the next' object
                    TimeSpan timeSpan = DateTime.Now - orgClickTime;
                    int      dc       = SystemInformation.DoubleClickTime;
                    if (dc < timeSpan.TotalMilliseconds)
                    {
                        if (1 == FeatureEditors.Count)
                        {
                            // check if selection exists; could be toggled
                            Layer    outLayer;
                            IFeature nextFeature = GetNextFeatureAtPosition(worldPosition,
                                                                            // set limit from 4 to 10: TOOLS-1499
                                                                            (float)MapControlHelper.ImageToWorld(Map, 10),
                                                                            out outLayer,
                                                                            FeatureEditors[0].SourceFeature,
                                                                            ol => ol.IsVisible);
                            if (null != nextFeature)
                            {
                                Clear();
                                SetSelection(nextFeature, outLayer, 0); //-1 for ILineString
                                //MapControl.Refresh();
                            }
                        }
                    }
                }
                UpdateMapControlSelection();
            }
            IsBusy       = false;
            orgClickTime = DateTime.Now;

            //for (int i=0; i<FeatureEditors.Count; i++)
            //{
            //    IFeatureEditor featureEditor = FeatureEditors[i];

            //    if (featureEditor.Layer.CustomRenderers.Count > 0)
            //    {
            //        // todo move to IFeatureEditor
            //        featureEditor.Layer.CustomRenderers[0].
            //            UpdateRenderedFeatureGeometry(FeatureEditors[i].SourceFeature, FeatureEditors[i].Layer);
            //        IGeometry g = featureEditor.Layer.CustomRenderers[0].
            //            GetRenderedFeatureGeometry(FeatureEditors[i].SourceFeature, FeatureEditors[i].Layer);
            //        FeatureEditors[i].UpdateTracker(g);
            //    }
            //    //featureEditor.Stop();
            //}
        }