DrawStatusChanged not firing

867
2
03-29-2017 07:46 AM
MarkCederholm
Regular Contributor II

When I only have an ArcGISTiledLayer loaded, the MapView.DrawStatusChanged event fires exactly as expected.  However, when I add layers from a MobileMapPackage, it doesn't want to fire properly at all.  Is this a known (WPF) issue? [NavigationCompleted fires OK.]

Tags (1)
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor

However, when I add layers from a MobileMapPackage, it doesn't want to fire properly at all.

Are you removing the layer from the MobileMapPackage.Map before adding to your MapView.Map? It might be that you are getting "Object already owned" error and the layer from mobile map package is never added to the map?

If you would like to know the state for each layer added, you can use LayerViewStateChanged, it also has Error property that you can check.

You can try the following code which reports status from both events. Load button will add layers from mobile map package. I assume, this is what you're trying to do?

        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView"
                      DrawStatusChanged="MyMapView_DrawStatusChanged"
                      LayerViewStateChanged="MyMapView_LayerViewStateChanged">
            <esri:Map>
                <esri:ArcGISMapImageLayer Source="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" />
            </esri:Map>
        </esri:MapView>
        <StackPanel VerticalAlignment="Top"
                    HorizontalAlignment="Right">
            <Button Content="Load"
                    Click="Button_Click" />
            <ListView x:Name="Status" />
        </StackPanel>
    </Grid>
        public MainWindow()
        {
            InitializeComponent();
            Status.ItemsSource = _status;
        }
        private ObservableCollection<string> _status = new ObservableCollection<string>();
        private void MyMapView_DrawStatusChanged(object sender, Esri.ArcGISRuntime.UI.DrawStatusChangedEventArgs e)
        {
            _status.Add($"MyMapView_DrawStatusChanged:\t{e.Status}");
        }

        private void MyMapView_LayerViewStateChanged(object sender, LayerViewStateChangedEventArgs e)
        {
            _status.Add($"MyMapView_LayerViewStateChanged:\t{e.Layer.Name}:\t{e.LayerViewState.Status}");
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var mmpk = await MobileMapPackage.OpenAsync(@"C:\Temp\sanfrancisco.mmpk");
            foreach (var layer in mmpk.Maps[0].Basemap.BaseLayers.ToList())
            {
                mmpk.Maps[0].Basemap.BaseLayers.Remove(layer);
                MyMapView.Map.Basemap.BaseLayers.Add(layer);
            }
            foreach (var layer in mmpk.Maps[0].OperationalLayers.ToList())
            {
                mmpk.Maps[0].OperationalLayers.Remove(layer);
                MyMapView.Map.OperationalLayers.Add(layer);
            }
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
MarkCederholm
Regular Contributor II

The "Object not owned" error actually crashes the app.  I ran into that long ago.  However, if a draw error on a layer is not raising an unhandled exception, but is causing DrawStatusChanged not to fire, that could be the problem.  I'll look into that, and thanks for the example.

I do know that some of the MMPKs I've created cause problems in Runtime, especially if they were imported into Pro from an ArcMap MXD.  For example, one layer causes the app to crash when visibility is turned off!  I'm working on recreating some of my maps from scratch in Pro to see if that makes a difference.

0 Kudos