Create Points

Download Samples Repository

Description

Demonstrates how to create point geometries, attach them to graphics and display them on the map. MapPoint geometry objects are used to store geographic points.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.CreatePoints"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
		<esri:MapView x:Name="MyMapView" WrapAround="True">
			<esri:Map>
				<esri:ArcGISTiledMapServiceLayer
                    ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
			</esri:Map>
			<esri:MapView.GraphicsOverlays>
				<esri:GraphicsOverlay ID="graphicsOverlay" />
			</esri:MapView.GraphicsOverlays>
		</esri:MapView>
	</Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.Symbology;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace ArcGISRuntime.Samples.Desktop
{
	/// <summary>
	/// Demonstrates how to create point geometries, attach them to graphics and display them on the map. MapPoint geometry objects are used to store geographic points.
	/// </summary>
	/// <title>Create Points</title>
	/// <category>Geometry</category>
	public partial class CreatePoints : UserControl
	{
		private GraphicsOverlay _graphicsOverlay;

		/// <summary>Construct Create Points sample control</summary>
		public CreatePoints()
		{
			InitializeComponent();

			_graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
			MyMapView.NavigationCompleted += MyMapView_NavigationCompleted;
		}

		// Create four point graphics on the map in the center of four equal quadrants
		private void MyMapView_NavigationCompleted(object sender, EventArgs e)
		{
			MyMapView.NavigationCompleted -= MyMapView_NavigationCompleted;
			try
			{
                // Get current viewpoints extent from the MapView
                var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
                var viewpointExtent = currentViewpoint.TargetGeometry.Extent;

				var myViewpointExtent = viewpointExtent;
				var height = myViewpointExtent.Height / 4;
				var width = myViewpointExtent.Width / 4;
				var center = myViewpointExtent.GetCenter();

				var topLeft = new MapPoint(center.X - width, center.Y + height, MyMapView.SpatialReference);
				var topRight = new MapPoint(center.X + width, center.Y + height, MyMapView.SpatialReference);
				var bottomLeft = new MapPoint(center.X - width, center.Y - height, MyMapView.SpatialReference);
				var bottomRight = new MapPoint(center.X + width, center.Y - height, MyMapView.SpatialReference);

				var symbol = new SimpleMarkerSymbol() { Color = Colors.Red, Size = 15, Style = SimpleMarkerStyle.Diamond };

				_graphicsOverlay.Graphics.Add(new Graphic() { Geometry = topLeft, Symbol = symbol });
				_graphicsOverlay.Graphics.Add(new Graphic() { Geometry = topRight, Symbol = symbol });
				_graphicsOverlay.Graphics.Add(new Graphic() { Geometry = bottomLeft, Symbol = symbol });
				_graphicsOverlay.Graphics.Add(new Graphic() { Geometry = bottomRight, Symbol = symbol });

				_graphicsOverlay.Graphics.Add(new Graphic()
				{
					Geometry = new MapPoint(0, 0),
					Symbol = new SimpleMarkerSymbol() { Size = 15, Color = Colors.Blue }
				});
			}
			catch (Exception ex)
			{
				MessageBox.Show("Error occured : " + ex.Message, "Create Points Sample");
			}
		}
	}
}
Feedback on this topic?