1

I am trying to add an MPK to ArcGIS Runtim 10.27 using MVVM pattern and WPF I am able to see the MPK running on the localhost after running the application but the MPKMap = localMapService.UrlMapService; is not adding the MPK to the map. (And Yes! I already have base map so map is running well but no MPK!)

In my Model.cs I have

public class Model
{
    private string mapPackage = "E:\\App\\Data\\Parcels.mpk";
    public Model()  { }

    public string MapPackage
    {
        get { return this.mapPackage; }
        set
        {
            if (value != this.mapPackage)
            {
                this.mapPackage = value;
            }
        }
    }
}

and in the ViewModel.cs I have

public class ViewModel : INotifyPropertyChanged
{
    public Model myModel { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;

    public ViewModel()
    {
        myModel = new Model();
        this.CreateLocalServiceAndDynamicLayer();
    }

    public async void CreateLocalServiceAndDynamicLayer()
    {

            LocalMapService localMapService = new LocalMapService(this.MPKMap);
            await localMapService.StartAsync();

            MPKMap = localMapService.UrlMapService;
    }

    public string MPKMap
    {
        get { return myModel.MapPackage; }
        set
        {
            this.myModel.MapPackage = value;
            OnPropertyChanged("MPKUri");
        }
    }

    protected void OnPropertyChanged([CallerMemberName] string member = "")
    {
        var eventHandler = PropertyChanged;
        if (eventHandler != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(member));
        }
    }
}

in the MainWindow.xaml I have

<Window.Resources>
    <local:ViewModel x:Key="VM"/>
</Window.Resources>

<Grid>        
    <esri:MapView x:Name="MyMapView" Grid.Row="0" LayerLoaded="MyMapView_LayerLoaded" >
        <esri:Map>
            <esri:ArcGISDynamicMapServiceLayer ID="MPK" ServiceUri="{Binding Source={StaticResource VM}, Path=MPKUri}"/>
        </esri:Map>
    </esri:MapView>
</Grid>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.