I am trying to create a point graphic using a map point and a marker symbol.
A map point is defined with x and y coordinates and a spatial reference.
For latitude and longitude coordinates, the spatial reference is WGS84.
I am using following code to achieve this
using System;
using System.Collections.Generic;
using System.Text;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
namespace AddPointLineAndPolygon
{
class MapViewModel : INotifyPropertyChanged
{
public MapViewModel()
{
SetupMap();
CreateGraphics();
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private Map _map;
public Map Map
{
get { return _map; }
set
{
_map = value;
OnPropertyChanged();
}
}
private GraphicsOverlayCollection _graphicsOverlays;
public GraphicsOverlayCollection GraphicsOverlays
{
get { return _graphicsOverlays; }
set
{
_graphicsOverlays = value;
OnPropertyChanged();
}
}
private void SetupMap()
{
// Create a new map with a 'topographic vector' basemap.
this.Map = new Map(BasemapStyle.ArcGISTopographic);
}
private void CreateGraphics()
{
// Create a new graphics overlay to contain a variety of graphics.
var malibuGraphicsOverlay = new GraphicsOverlay();
// Add the overlay to a graphics overlay collection.
GraphicsOverlayCollection overlays = new GraphicsOverlayCollection
{
malibuGraphicsOverlay
};
// Set the view model's "GraphicsOverlays" property (will be consumed by the map view).
this.GraphicsOverlays = overlays;
// Create a point geometry.
var dumeBeachPoint = new MapPoint(-118.8066, 34.0006, SpatialReferences.Wgs84);
// Create a symbol to define how the point is displayed.
var pointSymbol = new SimpleMarkerSymbol
{
Style = SimpleMarkerSymbolStyle.Circle,
Color = System.Drawing.Color.Orange,
Size = 10.0
};
// Add an outline to the symbol.
pointSymbol.Outline = new SimpleLineSymbol
{
Style = SimpleLineSymbolStyle.Solid,
Color = System.Drawing.Color.Blue,
Width = 2.0
};
But when I run this code, it is not showing any graphics. What is missing in my code, please help.
CodePudding user response:
You can create a Graphic with the point and pointSymbol and display the Graphic by adding it to the graphicsOverlay's Graphics collection.
See the following code:
// Create a point graphic with the geometry and symbol.
var pointGraphic = new Graphic(dumeBeachPoint, pointSymbol);
// Add the point graphic to graphics overlay.
malibuGraphicsOverlay.Graphics.Add(pointGraphic);