using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; namespace Post { public class SelectExtentInteractiveOverlay : ExtentInteractiveOverlay { private Keys tempDragKey; private bool isSelectDragKeyPressed; public SelectExtentInteractiveOverlay(FeatureLayer sourceFeatureLayer) { SourceFeatureLayer = sourceFeatureLayer; SelectDragKey = Keys.ControlKey; } public FeatureLayer SourceFeatureLayer { get; set; } public Keys SelectDragKey { get; set; } public event EventHandler Selected; protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments) { if (UnsafeHelper.IsKeyPressed(SelectDragKey)) { tempDragKey = LeftClickDragKey; LeftClickDragKey = SelectDragKey; isSelectDragKeyPressed = true; } InteractiveResult result = base.MouseDownCore(interactionArguments); return result; } protected override InteractiveResult MouseUpCore(InteractionArguments interactionArguments) { InteractiveResult result = base.MouseUpCore(interactionArguments); if ((ExtentChangedType == ExtentChangedType.TrackZoomIn || ExtentChangedType == ExtentChangedType.TrackZoomOut) && SourceFeatureLayer != null && isSelectDragKeyPressed) { RectangleShape targetExtent = result.NewCurrentExtent; result.NewCurrentExtent = null; if (!SourceFeatureLayer.IsOpen) SourceFeatureLayer.Open(); Collection queriedFeatures = SourceFeatureLayer.QueryTools.GetFeaturesInsideBoundingBox(targetExtent, ReturningColumnsType.AllColumns); LeftClickDragKey = tempDragKey; isSelectDragKeyPressed = false; OnSelected(new SelectedSelectExtentInteractiveOverlayEventArgs(queriedFeatures)); } return result; } protected virtual void OnSelected(SelectedSelectExtentInteractiveOverlayEventArgs e) { EventHandler handler = Selected; if (handler != null) { handler(this, e); } } } public class SelectedSelectExtentInteractiveOverlayEventArgs : EventArgs { private Collection selectedFeatures; public SelectedSelectExtentInteractiveOverlayEventArgs(IEnumerable selectedFeatures) { this.selectedFeatures = new Collection(); foreach (Feature feature in selectedFeatures) { this.selectedFeatures.Add(feature); } } public Collection SelectedFeatures { get { return selectedFeatures; } } } }