private void OnViewpointChanged(object sender, EventArgs e)
{
// Unhook the event
MyMapView.ViewpointChanged -= OnViewpointChanged;
// Get area that is shown in a MapView
Polygon visibleArea = MyMapView.VisibleArea;
// Get extent of that area
Envelope extent = visibleArea.Extent;
// Get central point of the extent
MapPoint centerPoint = extent.GetCenter();
// Create values inside the visible extent for creating graphic
var extentWidth = extent.Width / 5;
var extentHeight = extent.Height / 10;
// Create point collection
PointCollection points = new PointCollection(SpatialReferences.WebMercator)
{
new MapPoint(centerPoint.X - extentWidth * 2, centerPoint.Y - extentHeight * 2),
new MapPoint(centerPoint.X - extentWidth * 2, centerPoint.Y + extentHeight * 2),
new MapPoint(centerPoint.X + extentWidth * 2, centerPoint.Y + extentHeight * 2),
new MapPoint(centerPoint.X + extentWidth * 2, centerPoint.Y - extentHeight * 2)
};
// Create overlay to where graphics are shown
GraphicsOverlay overlay = new GraphicsOverlay();
// Add points to the graphics overlay
foreach (var point in points)
{
// Create new graphic and add it to the overlay
overlay.Graphics.Add(new Graphic(point));
}
// Create symbol for points
SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol()
{
Color = Colors.Yellow,
Size = 30,
Style = SimpleMarkerSymbolStyle.Square,
};
// Create simple renderer with symbol
SimpleRenderer renderer = new SimpleRenderer(pointSymbol);
// Set renderer to graphics overlay
overlay.Renderer = renderer;
// Add created overlay to the MapView
MyMapView.GraphicsOverlays.Add(overlay);
}
}