Example #1
0
 public TrackerFeature(IFeatureInteractor featureMutator, IGeometry geometry, int index, Bitmap bitmap)
 {
     FeatureInteractor = featureMutator;
     Geometry          = geometry;
     Bitmap            = bitmap;
     Index             = index;
 }
        public override void OnMouseDown(Coordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            var oldSelectedTrackerIndicesCount = SelectedTrackersCount;
            var oldTrackerFeatureCount         = trackers.Count;

            IsBusy = true;
            ILayer selectedLayer;

            mouseDownLocation = worldPosition;

            // Check first if an object is already selected and if the mousedown has occured at this object.
            var trackerFeature = GetTrackerAtCoordinate(worldPosition);

            if (SelectedFeatureInteractors.Count > 1)
            {
                // hack: if multiple selection toggle/select complete feature
                trackerFeature = null;
            }

            SetClickOnExistingSelection(false, null);

            if (null != trackerFeature)
            {
                if (1 == SelectedFeatureInteractors.Count)
                {
                    SetClickOnExistingSelection(true, worldPosition);
                    FocusTracker(trackerFeature);
                    MapControl.Refresh();
                }
                return;
            }
            // single selection. Find the nearest geometry and give
            var limit   = (float)MapHelper.ImageToWorld(Map, 4);
            var nearest = FindNearestFeature(worldPosition, limit, out selectedLayer, ol => ol.Visible);

            if (null != nearest)
            {
                // Create or add a new FeatureInteractor
                if (SelectedFeatureInteractors.Count > 0)
                {
                    IFeatureInteractor currentFeatureInteractor = GetActiveFeatureInteractor(nearest);
                    if (KeyExtendSelection) // Shift key
                    {
                        if (null == currentFeatureInteractor)
                        {
                            var selectedBranch = nearest as IBranch;
                            if (selectedBranch != null)
                            {
                                SelectBranchesAlongShortestPath(worldPosition, selectedLayer, nearest, selectedBranch);
                            }
                            else
                            {
                                // not in selection; add
                                AddSelection(selectedLayer, nearest);
                                targetNode = null;
                            }
                        } // else possibly set default focus tracker
                    }
                    else if (KeyToggleSelection) // CTRL key
                    {
                        if (null == currentFeatureInteractor)
                        {
                            // not in selection; add
                            AddSelection(selectedLayer, nearest);
                            SetTargetNodeIfBranch(worldPosition, nearest);
                        }
                        else
                        {
                            // in selection; remove
                            RemoveSelection(nearest);
                            targetNode = null;
                        }
                    }
                    else
                    {
                        // no special key processing; handle as a single select.
                        Clear(false);
                        if (!StartSelection(selectedLayer, nearest))
                        {
                            StartMultiSelect();
                        }
                        SetTargetNodeIfBranch(worldPosition, nearest);
                    }
                }
                else
                {
                    if (!StartSelection(selectedLayer, nearest))
                    {
                        StartMultiSelect();
                    }
                    SetTargetNodeIfBranch(worldPosition, nearest);
                }
            }
            else
            {
                // We didn't find an object at the position of the mouse button -> start a multiple select
                if (!KeyExtendSelection)
                {
                    // we are not extending the current selection
                    Clear(false);
                }
                if (e.Button == MouseButtons.Left)
                {
                    StartMultiSelect();
                }
            }

            if ((oldSelectedTrackerIndicesCount != SelectedTrackersCount ||
                 oldTrackerFeatureCount != trackers.Count) && trackingLayer.DataSource.Features.Count != 0)
            {
                MapControl.Refresh();
            }
        }