Behnam
August 2, 2010, 11:31am
1
Hi,
I want to use mouse to select part of the map, and then highlight it. (similar to shift+Left click). So I want to:
Click on the map ( it can be combination of Left-Click + Ctrl or Alt or ...) Hold the Left-Click Move the mouse over the map ( create something similar to the attached image). Recieve the corners of the selected rectangle Create a feature layer and Highlight the features But the problem is that when I hold the Left Buttom of the mouse . the control starts to pan the map.
Many thanks
Select.png (54 KB)
Howard
August 2, 2010, 8:54pm
3
Really thanks for your reply, Raquibur. To be more detail Ben, my suggestion is almost like Raquibur recommends. There is a little difference that is we need to keep the rectangle drawing with shift key and select features from one FeatureLayer. Here is a sample for you and let me know how it works. Thanks, Howard
Post7932.zip (9.2 KB)
Behnam
August 3, 2010, 2:29am
4
thanks, I’ll give it a try and then write result here. Many Thanks
Howard
August 3, 2010, 2:43am
5
Hi Ben, Sure, take your time; just feel free to let me know if you have more queries. Thanks, Howard
Behnam
August 3, 2010, 9:51am
6
It's great, thanks Just to small Question:
can we use key other than shift for the selection
Regards, Ben
Howard
August 4, 2010, 1:13am
7
Hi Ben, Yes, Just one line of code: for example, press "S" which means "Select" instead of shift key. selectExtentInteractiveOverlay.LeftClickDragKey = Keys.S; One thing I want to point out is that you need reference System.Windows.Forms first because of the enum Keys. Thanks, Howard
Behnam
August 4, 2010, 4:23am
8
Thanks for your quick answer, the thing I need is zooming and selecting at the same time, if it is possible: shift+ mouse --> zoom ctrl+ mouse -->select thanks, Ben
Howard
August 5, 2010, 12:44am
9
Ben, Sure, I changed the interactive overlay a little; please have a try, also you can change control key to any other key by setting the SelectDragKey property. Thanks, Howard
SelectExtentInteractiveOverlay.cs (3.1 KB)
Behnam
August 5, 2010, 4:06am
10
Thanks, Unfortunately I can not download your code!
Howard
August 5, 2010, 4:21am
11
Hi Ben, Sorry for the inconvenience. I didn't notice that file suffix affects my uploading. Please download this one. Thanks, Howard
001_SelectExtentInteractiveOverlay.txt (3.1 KB)
David
August 5, 2010, 4:25am
12
Guys,
I also posted it as code as well. This is much nicer as people can see it before they download it. 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<SelectedSelectExtentInteractiveOverlayEventArgs> 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<Feature> queriedFeatures = SourceFeatureLayer.QueryTools.GetFeaturesInsideBoundingBox(targetExtent, ReturningColumnsType.AllColumns); LeftClickDragKey = tempDragKey; isSelectDragKeyPressed = false; OnSelected(new SelectedSelectExtentInteractiveOverlayEventArgs(queriedFeatures)); } return result; } protected virtual void OnSelected(SelectedSelectExtentInteractiveOverlayEventArgs e) { EventHandler<SelectedSelectExtentInteractiveOverlayEventArgs> handler = Selected; if (handler != null) { handler(this, e); } } } public class SelectedSelectExtentInteractiveOverlayEventArgs : EventArgs { private Collection<Feature> selectedFeatures; public SelectedSelectExtentInteractiveOverlayEventArgs(IEnumerable<Feature> selectedFeatures) { this.selectedFeatures = new Collection<Feature>(); foreach (Feature feature in selectedFeatures) { this.selectedFeatures.Add(feature); } } public Collection<Feature> SelectedFeatures { get { return selectedFeatures; } } } } David
Behnam
August 6, 2010, 9:51am
13
It works perfectly, Many thanks
Howard
August 7, 2010, 12:32am
14
Hi Ben, You are welcome, just feel free to let us know if you have more queries. Thanks, Howard