Map 3D deletes layers and data sources through programs

Source: Internet
Author: User

In Map 3D, you can use APIs to connect to various data sources such as SHP and Oracle. If you are not familiar with this process, refer to the BuildMap example in Map 3D ObjectARX SDK, however, BuildMap does not demonstrate how to disconnect from these data sources. If you have read the BuildMap implementation code, you will find that connecting to the data source is actually the process of creating the FeatureSource resource. adding layers to the map is the process of creating LayerDefinition. In this case, disconnecting is the process of deleting the corresponding resource.

 

The following code deletes a layer from the Map and disconnects it (tested in Map 3D 2013 ):

 

    [CommandMethod("RemoveLayer")]    public void RemoveLayer()    {      Document doc = Application.DocumentManager.MdiActiveDocument;      Editor ed = doc.Editor;      Database db = doc.Database;      AcMapMap map = AcMapMap.GetCurrentMap();      string layerName = "layer1";      // remove the layer      var layers = map.GetLayers();      if (!layers.Contains(layerName))      {        ed.WriteMessage("\nLayer does not exist: " + layerName);        return;      }      MgLayerBase layer = layers.GetItem(layerName);      layers.Remove(layer);      // remove the layer resource      MgResourceIdentifier identifier = layer.LayerDefinition;      MgResourceService resourceService        = AcMapServiceFactory.GetService(MgServiceType.ResourceService)        as MgResourceService;      if (resourceService.ResourceExists(identifier))        resourceService.DeleteResource(identifier);      // remove the feature source      identifier = new MgResourceIdentifier(layer.FeatureSourceId);      if (resourceService.ResourceExists(identifier))        resourceService.DeleteResource(identifier);    }

 

In addition, this method also has other advantages. It is no longer available today and will be detailed later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.