<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="Geomentum.MediaReach.Modules.Map.View.MapView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:esri="http://schemas.esri.com/arcgis/client/2009" xmlns:local="clr-namespace:Geomentum.MediaReach.Modules.Map.View" xmlns:ViewModel="clr-namespace:Geomentum.MediaReach.Modules.Map.ViewModel"> <esri:Map x:Name="MyMap" WrapAround="True" IsLogoVisible="False" Layers="{Binding ViewModel.BaseMapLayerService}" /> </UserControl>
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Geomentum.MediaReach.Modules.Map.View; using Microsoft.Practices.Prism.Events; using System.ComponentModel; using System.Collections.Generic; using System.Collections.ObjectModel; using Geomentum.MediaReach.Infrastructure.Models; using Geomentum.MediaReach.Infrastructure.Events; using ESRI.ArcGIS.Client; namespace Geomentum.MediaReach.Modules.Map.ViewModel { public class MapViewModel : IMapViewModel, INotifyPropertyChanged { private readonly IEventAggregator eventAggregator; private ESRI.ArcGIS.Client.LayerCollection _baseMapLayerService; private MediaReachMap _map; public IMapView View { get; set; } public MapViewModel(IMapView view, IEventAggregator eventAggregator, MediaReachMap map) { View = view; View.Model = this; _map = map; BaseMapLayerService = CreateMapLayers(map); this.eventAggregator = eventAggregator; this.eventAggregator.GetEvent<MapLayersUpdated>().Subscribe(this.updateLayerList); } public ESRI.ArcGIS.Client.LayerCollection BaseMapLayerService { get { return this._baseMapLayerService; } set { this._baseMapLayerService = value; OnPropertyChanged("BaseMapLayerService"); } } public void updateLayerList(ObservableCollection<LayerModel> LayerList) { ESRI.ArcGIS.Client.LayerCollection layers = new ESRI.ArcGIS.Client.LayerCollection(); ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer baseLayer = _map.MapLayerService; List<int> visibleLayerIDList = new List<int>(); ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = baseLayer.Layers; for (int index = 0; index < layerInfoArray.Length; index++) { if (LayerList[index].DefaultVisibility) visibleLayerIDList.Add(index); } baseLayer.VisibleLayers = visibleLayerIDList.ToArray(); layers.Add(baseLayer); BaseMapLayerService = layers; } private ESRI.ArcGIS.Client.LayerCollection CreateMapLayers(MediaReachMap map) { ESRI.ArcGIS.Client.LayerCollection layers = new ESRI.ArcGIS.Client.LayerCollection(); //create the base map layer ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer baseLayer = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer() { ID = "BaseLayer", Url = map.BaseMapURL }; layers.Add(baseLayer); return layers; } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } #endregion } }
Solved! Go to Solution.
public void updateLayerList(ObservableCollection<LayerModel> LayerList) { ESRI.ArcGIS.Client.LayerCollection layers = new ESRI.ArcGIS.Client.LayerCollection(); ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer baseLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)this._baseMapLayerService[0]; List<int> visibleLayerIDList = new List<int>(); ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = baseLayer.Layers; for ( int index = 0; index < layerInfoArray.Length; index++ ) { baseLayer.SetLayerVisibility(index, LayerList[index].DefaultVisibility); } //You should not not need these lines - I think :) this._baseMapLayerService[0] = baseLayer; OnPropertyChanged("BaseMapLayerService"); }
public void updateLayerList(ObservableCollection<LayerModel> LayerList) { ESRI.ArcGIS.Client.LayerCollection layers = new ESRI.ArcGIS.Client.LayerCollection(); ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer baseLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)this._baseMapLayerService[0]; List<int> visibleLayerIDList = new List<int>(); ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = baseLayer.Layers; for (int index = 0; index < layerInfoArray.Length; index++) { if (LayerList[index].DefaultVisibility) visibleLayerIDList.Add(index); } baseLayer.VisibleLayers = visibleLayerIDList.ToArray(); this._baseMapLayerService[0] = baseLayer; OnPropertyChanged("BaseMapLayerService"); }
public void updateLayerList(ObservableCollection<LayerModel> LayerList) { ESRI.ArcGIS.Client.LayerCollection layers = new ESRI.ArcGIS.Client.LayerCollection(); ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer baseLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)this._baseMapLayerService[0]; List<int> visibleLayerIDList = new List<int>(); ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = baseLayer.Layers; for ( int index = 0; index < layerInfoArray.Length; index++ ) { baseLayer.SetLayerVisibility(index, LayerList[index].DefaultVisibility); } //You should not not need these lines - I think :) this._baseMapLayerService[0] = baseLayer; OnPropertyChanged("BaseMapLayerService"); }