Adding The Resource

AutoCAD Map 3D Geospatial Platform API

 
Adding The Resource
 
 
 

To use the XML files to create the layer and the feature source, use MgResourceService.SetResource(). For example:

// Add the layer definition.
// It will be stored in the repository using the resource
// identifier.
MgResourceIdentifier rID_layer = new MgResourceIdentifier(
    @"Library://Data/Zoning.LayerDefinition");
 
// Note: Modify this directory to point to the location of 
// the XML files.
 
String xmlDirectory = @"C:\Map 3D SDK\"
  + @"Map Samples\Platform\BuildMap\bin\Debug\";
 
// Read the XML file, then save its contents in the resource
// repository.
 
MgByteSource layer_byteSource = 
  new MgByteSource(xmlDirectory + "Zoning.layer");
layer_byteSource.SetMimeType("text/xml");
resourceService.SetResource(rID_layer, 
  layer_byteSource.GetReader(), null);
 
// Add the feature source
// Note: The layer definition XML refers to 
// 'Library://Data/SDF/Zoning.FeatureSource' so
// we must use that name here.
MgResourceIdentifier rID_feature_source = 
  new MgResourceIdentifier(
  @"Library://Data/SDF/Zoning.FeatureSource");
MgByteSource feature_byteSource = new 
  MgByteSource(xmlDirectory + "Zoning.FeatureSource");
feature_byteSource.SetMimeType("text/xml");
resourceService.SetResource(rID_feature_source, 
  feature_byteSource.GetReader(), null);

Then add the layer to the current map. For example:

MgLayerBase layer = AcMapLayer.Create(rID_layer, 
  resourceService);
layer.SetName("NewLayer");
AcMapMap currentMap = AcMapMap.GetCurrentMap();
currentMap.GetLayers().Add(layer);