arcgis runtime for .net 100.6怎么加载本地SHP文件

我用Arcgis runtime for .net 100.6想加载SHP文件,我按照官网的案例源码(用MPK加载SHP)跑了一遍,怎么也加载不了SHP文件,发现如果不添加子层,也就是注释掉
 imageryLayer.Sublayers.Add(_shapefileSublayer);
就能加载MPK文件,如果不注释掉,运行打开文件之后什么也没加载进来
下面是官网上的案例源码
  private async void StartLocalMapService(string filename, string path)
{
// Start a service from the blank MPK
string mapServiceUrl = GetMpkPath();

// Create the local map service
_localMapService = new LocalMapService(mapServiceUrl);

// Create the shapefile workspace
ShapefileWorkspace shapefileWorkspace = new ShapefileWorkspace("shp_wkspc", path);

// Create the layer source that represents the shapefile on disk
TableSublayerSource source = new TableSublayerSource(shapefileWorkspace.Id, filename);

// Create a sublayer instance from the table source
_shapefileSublayer = new ArcGISMapImageSublayer(0, source);

// Add the dynamic workspace to the map service
_localMapService.SetDynamicWorkspaces(new List<DynamicWorkspace>() { shapefileWorkspace });

// Subscribe to notifications about service status changes
_localMapService.StatusChanged += _localMapService_StatusChanged;

try
{
// Start the map service
await _localMapService.StartAsync();
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error");
}
}

private async void _localMapService_StatusChanged(object sender, StatusChangedEventArgs e)
{
// Add the shapefile layer to the map once the service finishes starting
if (e.Status == LocalServerStatus.Started)
{
// Create the imagery layer
ArcGISMapImageLayer imageryLayer = new ArcGISMapImageLayer(_localMapService.Url);

// Subscribe to image layer load status change events
// Only set up the sublayer renderer for the shapefile after the parent layer has finished loading
imageryLayer.LoadStatusChanged += (q, ex) =>
{
// Add the layer to the map once loaded
if (ex.Status == Esri.ArcGISRuntime.LoadStatus.Loaded)
{
// Create a default symbol style
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Red, 3);

// Apply the symbol style with a renderer
_shapefileSublayer.Renderer = new SimpleRenderer(lineSymbol);

// Add the shapefile sublayer to the imagery layer
imageryLayer.Sublayers.Add(_shapefileSublayer)
//按官网案例源码来,运行后加载SHP后没反应,注释掉能加载MPK。
}
};

try
{
// Load the layer
await imageryLayer.LoadAsync();

// Clear any existing layers
MyMapView.Map.OperationalLayers.Clear();

// Add the image layer to the map
MyMapView.Map.OperationalLayers.Add(imageryLayer);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error");
}
}
}
 
请问下怎么解决
已邀请:
Runtime是什么版本啊?100.2之后的版本是可以直接加载shapefile的,不需要通过mpk这种方式,参考代码:
// Open the shapefile
            ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath);
            // Create a feature layer to display the shapefile
            FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile);
            // Add the feature layer to the map
            MyMapView.Map.OperationalLayers.Add(newFeatureLayer);
           
 

要回复问题请先登录注册