private void graphicalselection_icon_Click(object sender, EventArgs e) { if (selectedOrder == -1) MessageBox.Show("First Select Appropriate Layer"); else { filename1 = themeview1.Items[selectedOrder].ShapeName; } graphicalselection_icon.Checked = !graphicalselection_icon.Checked; if (graphicalselection_icon.Checked == true) { //Using the rectangle from TrackOverlay to do the spatial query winformsMap1.TrackOverlay.TrackMode = TrackMode.Rectangle; //Event for getting the rectangle shape at the end of tracking the rectangle on the map. winformsMap1.TrackOverlay.TrackEnded += new EventHandler(winformsMap1_TrackEnded); //InMemoryfeatureLayer to show the selected features from the spatial query. InMemoryFeatureLayer spatialQueryResultLayer = new InMemoryFeatureLayer(); spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.FromArgb(200, GeoColor.SimpleColors.PastelRed))); spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Red; spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; LayerOverlay spatialQueryResultOverlay = new LayerOverlay(); spatialQueryResultOverlay.Layers.Add("SpatialQueryResultLayer", spatialQueryResultLayer); winformsMap1.Overlays.Add("SpatialQueryResultOverlay", spatialQueryResultOverlay); winformsMap1.Refresh(); } if (graphicalselection_icon.Checked == false) { winformsMap1.Refresh(); winformsMap1.TrackOverlay.TrackMode = TrackMode.None; } } void winformsMap1_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e) { RectangleShape rectangleShape = (RectangleShape)e.TrackShape; Collection featureFilenames = new Collection(); foreach (string filename in openFileDialog.FileNames) { featureFilenames.Add(filename); } ShapeFileFeatureLayer worldLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer(themeview1.Items[selectedOrder].ShapeName); InMemoryFeatureLayer spatialQueryResultLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("SpatialQueryResultLayer"); //Spatial query to find the features intersecting the rectangle from the track rectangle. Collection spatialQueryResults; worldLayer.Open(); spatialQueryResults = worldLayer.QueryTools.GetFeaturesIntersecting(rectangleShape, ReturningColumnsType.NoColumns); worldLayer.Close(); //Adds the selected features to the InMemoryfeatureLayer spatialQueryResultLayer.Open(); spatialQueryResultLayer.EditTools.BeginTransaction(); spatialQueryResultLayer.InternalFeatures.Clear(); foreach (Feature feature in spatialQueryResults) { spatialQueryResultLayer.EditTools.Add(feature); } spatialQueryResultLayer.EditTools.CommitTransaction(); spatialQueryResultLayer.Close(); //Refreshes the layers to show new result. winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear(); winformsMap1.Refresh(winformsMap1.TrackOverlay); winformsMap1.Refresh(winformsMap1.Overlays["SpatialQueryResultOverlay"]); } private void clearselection_Click(object sender, EventArgs e) { InMemoryFeatureLayer spatialQueryResultLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("spatialQueryResultLayer"); if (spatialQueryResultLayer.InternalFeatures.Count > 0) { spatialQueryResultLayer.InternalFeatures.Clear(); } }