AnsweredAssumed Answered

How to Update MapView with Graphics via ViewModel?

Question asked by khurram.ali on Oct 31, 2018
Latest reply on Nov 2, 2018 by minerjoe

I am developing an application with ArcGIS Runtime SDK for .Net and following the MVVM Pattern, in my ViewModel I have an ObservableCollection of GraphicsOverlay that I have binded to the MapView in my View, now when I add a new GraphicsOverlay to the ObservableCollection and add Graphics in it, graphics are not reflection in the View, 

 

I have implemented INotifyPropertyChanged and all other things are working fine with the ViewModel

        

public class MapViewModel : BaseViewModel
{
private Map map;

public Map Map
{
get { return this.map; }
set { this.map = value; }
}
public ObservableCollection<GraphicsOverlay> GraphicsOverlays { get; set; }

 

public MapViewModel()
{
GraphicsOverlays = new ObservableCollection<GraphicsOverlay>();
}

 

And in my Method that is called by any event

 

public void UpdateMarker(MapPoint point)
{
GraphicsOverlays[0].Graphics.Clear();

// Create a symbol to symbolize the point
SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.X, System.Drawing.Color.Yellow, 20);

// Create the graphic
Graphic symbolGraphic = new Graphic(point, symbol);

// Add the graphic to the graphics overlay
var newGraphicsOverlay=new GraphicsOverlay();
GraphicsOverlays[0].Graphics.Add(symbolGraphic);

}

 

 

And in my View I have

<esri:MapView x:Name="MyMapView" Grid.Column="0" DataContext="{StaticResource MapVM}" GraphicsOverlays="{Binding GraphicsOverlays}" Map="{Binding Map}" Cursor="{Binding MapViewCursor}">

 

I am unable to find any sample that does exactly this, so how to do this, I am new to arcGIS, Thanks in advance.

Outcomes