I'm still fairly new to ArcGIS Pro, so forgive me for anything obvious I'm overlooking.
I'm attempting to add a network dataset to a map and then export it as a mobile map package. I've followed the instructions here (Create Mobile Map Package—Data Management toolbox | ArcGIS Desktop ) and my network dataset follows all of the conventions described on this page. When I build it I receive no errors. However, when I open it in my WPF application, the TransportationNetworks object is always null.
Is there a way to verify through ArcGIS Pro that the network dataset actually made it into the package? If that is the case then I can determine whether or not the problem is in my WPF application. If the network dataset isn't being included, then what am I failing to do?
I'm not sure what other information might be needed, so please tell me what else I should provide.
Solved! Go to Solution.
var mapPackage = await MobileMapPackage.OpenAsync("C:\\Program Files (x86)\\Common\\Maps\\NetworkPackage.mmpk");
//add this line and the TransportationNetworks[] should no longer be null.
await mapPackage.Maps[0].LoadAsync();
if (mapPackage.Maps[0].TransportationNetworks != null)
Alternatively .... you might want to display the map from the map package this will (auto) load the map [e.g. myMapView.Map = mapPackage .Maps[0];] Then you could monitor the status of the map (whether is loaded or not) by hooking up the the map's loaded event (e.g. myMapView.Map.Loaded += Map_Loaded;), and in the 'Map_Loaded' method you could now use the TransportationNetworks[].
So the general structure would be something like this (note: this is just one possible way):
MobileMapPackage mapPackage = await MobileMapPackage.OpenAsync(mmpkPath);
MyMapView.Map = mapPackage.Maps[0];
//connect up load event
MyMapView.Map.Loaded += Map_Loaded;
}
private void Map_Loaded(object sender, EventArgs e)
{
//Use dispatcher since dealing with different threads
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(CreateRouteTask));
}
private void CreateRouteTask()
{
// check if trans networks not null
if (MyMapView.Map.TransportationNetworks != null)
{
//if not do something with them
Console.WriteLine(MyMapView.Map.TransportationNetworks.Count);
}
}
You can open the .mmpk you created in Pro, the network you originally added should be in the mmpk's map. To open a .mmpk in Pro on the Insert tab select Import Map and point to .mmpk.
In your WPF app ... is the map loaded before you attempt to access the TransportationNetworks? Since the transportation networks are part of the map it needs to be loaded before accessing the TransportationNetworks array.
When I import the map package into Pro, the network exists just like it should. However, when I open it in WPF then the TransportationNetwork is null still. Am I loading the map wrong?
var mapPackage = await MobileMapPackage.OpenAsync("C:\\Program Files (x86)\\Common\\Maps\\NetworkPackage.mmpk");
if (mapPackage.Maps[0].TransportationNetworks != null)
{
this._routeTask = await RouteTask.CreateAsync(mapPackage.Maps[0].TransportationNetworks[0]);
}
else
{
// always null
}
var mapPackage = await MobileMapPackage.OpenAsync("C:\\Program Files (x86)\\Common\\Maps\\NetworkPackage.mmpk");
//add this line and the TransportationNetworks[] should no longer be null.
await mapPackage.Maps[0].LoadAsync();
if (mapPackage.Maps[0].TransportationNetworks != null)
Alternatively .... you might want to display the map from the map package this will (auto) load the map [e.g. myMapView.Map = mapPackage .Maps[0];] Then you could monitor the status of the map (whether is loaded or not) by hooking up the the map's loaded event (e.g. myMapView.Map.Loaded += Map_Loaded;), and in the 'Map_Loaded' method you could now use the TransportationNetworks[].
So the general structure would be something like this (note: this is just one possible way):
MobileMapPackage mapPackage = await MobileMapPackage.OpenAsync(mmpkPath);
MyMapView.Map = mapPackage.Maps[0];
//connect up load event
MyMapView.Map.Loaded += Map_Loaded;
}
private void Map_Loaded(object sender, EventArgs e)
{
//Use dispatcher since dealing with different threads
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(CreateRouteTask));
}
private void CreateRouteTask()
{
// check if trans networks not null
if (MyMapView.Map.TransportationNetworks != null)
{
//if not do something with them
Console.WriteLine(MyMapView.Map.TransportationNetworks.Count);
}
}