Skip To Content

WebFeatureLayer.AddAsync (.NET)

This method adds a new web feature layer with an optional filtering query. Resulting features within the project area will be drawn. If the web layer being added is secure, the user will be prompted to enter credentials as required by the portal.

Declaration

public async Task<(bool Success, ICollection<string> WebFeatureLayerNames)> Esri.ArcGISForAutoCAD.WebFeatureLayer.AddAsync(Document doc, string url, string definitionExpression = "", string branchName = "")

Parameters

TypeNameDescriptionRequired

Document

doc

The AutoCAD document to act on.

required

string

url

URL of a valid web feature layer to add to the drawing.

required

string

definitionExpression

WHERE clause expression to limit features from the layer by attribute values. The syntax of the WHERE clause is determined by the source data.

optional

string

branchName

Name of a branch version available on the web feature layer.

optional

Returns

TypeDescription

(bool Success, ICollection<string> WebFeatureLayerNames)

A named tuple where the first value is the Success value and the second value is the WebFeatureLayerNames value. The Success value is a Boolean value of whether the web feature layer(s) were added successfully. The WebFeatureLayerNames value is a collection of added web feature layer name(s).

Remarks on error conditions

This method can throw an exception or may return null if a parameter is invalid.

Example 1

Print the success of adding all PoolPermits web feature layers without any filtering query.

// Initialize
var doc = Application.DocumentManager.MdiActiveDocument;
var url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/FeatureServer";

// Add the web feature layers
var success = await Esri.ArcGISForAutoCAD.WebFeatureLayer.AddAsync(doc, url);

// Print the web feature layer names
if (success.Success == true)
{
  foreach (var name in success.WebFeatureLayerNames)
  {
    doc.Editor.WriteMessage("\n" + name);
  }
}

/* Example output 
No_Permit
Has_Permit
*/

Example 2

Print the success of adding the USA_States_Generalized web feature layer and features where the STATE_NAME field value starts with the letter N.

// Initialize
var doc = Application.DocumentManager.MdiActiveDocument;
var url = "https://esri.maps.arcgis.com/home/item.html?id=8c2d6d7df8fa4142b0a1211c8dd66903";
var definitionExpression = "STATE_NAME LIKE \'N%\'";

// Add the web feature layer
var success = await Esri.ArcGISForAutoCAD.WebFeatureLayer.AddAsync(doc, url, definitionExpression);

// Print the web feature layer name
if (success.Success == true)
{
  doc.Editor.WriteMessage(success.WebFeatureLayerNames.First());
}

/* Example output 
USA_States_Generalized
*/

Example 3

Print the success of adding the editor01.triangle branch of the Damage_To_Commercial_Buildings web feature layer.

// Initialize
var doc = Application.DocumentManager.MdiActiveDocument;
var url = "https://sampleserver7.arcgisonline.com/server/rest/services/DamageAssessment/FeatureServer";
var branchName = "editor01.triangle";

// Add the web feature layer
var success = await Esri.ArcGISForAutoCAD.WebFeatureLayer.AddAsync(doc, url, "", branchName);

// Print the web feature layer name
if (success.Success == true)
{
  doc.Editor.WriteMessage(success.WebFeatureLayerNames.First());
}

/* Example output 
Damage_To_Commercial_Buildings
*/

See also

MapLayer.AddAsync - .NET method that adds a map or imagery layer to the current drawing using the specified service properties.

WebLayer.AddAsync - .NET method that adds a new map layer, imagery layer, or web feature layer to the drawing using the specified URL.

DocFeatureLayer.Add - NET method that adds a document feature layer definition to the AutoCAD drawing.

esri_webfeaturelayer_add - AutoLISP function that adds a new web feature layer with an optional filtering query.