/// <summary> Handles the click on the map. </summary> /// <param name="sender"> The sender of the MouseDown event. </param> /// <param name="e"> The event parameters. </param> private void map_MouseDown(object sender, MouseButtonEventArgs e) { if (!(e.ChangedButton == MouseButton.Left && e.ButtonState == MouseButtonState.Pressed)) { return; } // get clicked coordinate and transform to PTV Mercator var canvasPoint = e.GetPosition(this); var mercatorPoint = CanvasToPtvMercator(canvasPoint); // ctrl-key adds the selected polygon if (!(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))) { geometries.Clear(); } // query the items for a point (which is a rectangle of size 0) foreach (var geoItem in provider.QueryBBox(mercatorPoint.X, mercatorPoint.Y, mercatorPoint.X, mercatorPoint.Y, null)) { // parse the geometry from the wkb to a WPF path // transform to canvas coordinates var geometry = WkbToWpf.Parse(geoItem.Wkb, PtvMercatorToCanvas); // The result set conains all geometries whose *envelope* contains the point. // Check for exact containment if (geometry.FillContains(canvasPoint)) { geometries.Add(geometry); } } }
/// <summary> Event handler for MouseDown event. </summary> /// <param name="sender"> The sender of the MouseDown event. </param> /// <param name="e"> The event parameters. </param> #region doc:map_MouseDown handler private void map_MouseDown(object sender, MouseButtonEventArgs e) { if (!(e.ChangedButton == MouseButton.Left && e.ButtonState == MouseButtonState.Pressed)) { return; } var canvasPoint = e.GetPosition(this); System.Windows.Point wgsPoint = CanvasToGeo(canvasPoint); var ds = new FeatureDataSet(); geometries.Clear(); using (var shpFile = new SharpMap.Data.Providers.ShapeFile(shapeFilePath)) { shpFile.Open(); shpFile.ExecuteIntersectionQuery(new BoundingBox(wgsPoint.X, wgsPoint.Y, wgsPoint.X, wgsPoint.Y), ds); //if selected any object if (ds.Tables[0].Rows.Count <= 0) { return; } using (var geomProvider = new GeometryProvider(ds.Tables[0])) { geomProvider.Open(); foreach (var geoItem in geomProvider.Geometries) { var geometry = WkbToWpf.Parse(geoItem.AsBinary(), GeoToCanvas); if (geometry.FillContains(canvasPoint)) { geometries.Add(geometry); } } } } }