Hello,
I want to be able to register a mouse click event and then plot a point graphic at that location. Right now I get the mouse click, get the location of that mouse click and then use those coordinates to create a graphic. After doing all this the point still does not display onto the map..
//MainWindow.xaml.cs
private void MainMapView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
MapViewModel mvm = new MapViewModel();
Point p = e.GetPosition(MainMapView);
MapPoint mp = MainMapView.ScreenToLocation(e.GetPosition(MainMapView));
mvm.createPoint(mp);
}
//MapViewModel.cs
public void createPoint(MapPoint point)
{
// Create a new graphics overlay to contain a variety of graphics.
var graphicsOverlay = new GraphicsOverlay();
// Add the overlay to a graphics overlay collection.
GraphicsOverlayCollection overlays = new GraphicsOverlayCollection
{
graphicsOverlay
};
// Set the view model's "GraphicsOverlays" property (will be consumed by the map view).
this.GraphicsOverlays = overlays;
var mapPoint = new MapPoint(point.X, point.Y, SpatialReferences.Wgs84);
// Create a symbol to define how the point is displayed.
var pointSymbol = new SimpleMarkerSymbol
{
Style = SimpleMarkerSymbolStyle.X,
Color = System.Drawing.Color.Red,
Size = 10.0
};
// Add an outline to the symbol.
pointSymbol.Outline = new SimpleLineSymbol
{
Style = SimpleLineSymbolStyle.Solid,
Color = System.Drawing.Color.Red,
Width = 2.0
};
// Create a point graphic with the geometry and symbol.
var pointGraphic = new Graphic(mapPoint, pointSymbol);
// Add the point graphic to graphics overlay.
graphicsOverlay.Graphics.Add(pointGraphic);
}