ProConcepts Map Authoring

Uma Harano edited this page Jun 26, 2018 · 12 revisions

The Mapping functionality in ArcGIS Pro is delivered through the ArcGIS.Desktop.Mapping assembly. The ArcGIS.Desktop.Mapping namespace provides classes and members to author maps. This includes creating maps, opening web maps in ArcGIS Online, adding content—such as layers—to maps, creating and editing symbols, assigning renderers to layers, and supporting map annotation and dynamic labeling. The ArcGIS.Desktop.Mapping namespace also provides the ability to manage styles and style items in an ArcGIS Pro project.

  • ArcGIS.Desktop.Core.dll
  • ArcGIS.Desktop.Mapping.dll
Language:      C# and Visual Basic
Subject:       Map Authoring
Contributor:   ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization:  Esri, http://www.esri.com
Date:          6/7/2018
ArcGIS Pro:    2.2
Visual Studio: 2015, 2017

In this topic

Creating and displaying maps

The Map object is the primary object used for the organization of geographic data in ArcGIS Pro. It is a container of layers and stand-alone tables. Typical tasks with a map object include adding a new layer, changing the spatial reference, obtaining the currently selected features, and managing spatiotemporal bookmarks. To view and interact with maps or features, use the MapView object.

You can use the Map object to access the map and the data it contains. The Map object is a primary point for customization tasks because it not only manages layers of data, but it is also a view and has to manage the drawing of its data. Typical tasks with the Map object include adding a new layer, setting a basemap, changing the spatial reference, and obtaining the currently selected features and elements.

The Map object has properties that operate on all layers within the map, such as spatial reference, map scale, and so on, along with methods that manipulate the map's layers. Layers can, if required, handle drawing operations for their associated data, but it is more common for layers to have an associated renderer object. The properties of the renderer object control how the data is displayed in the map. Renderers use symbols for the actual drawing—the renderer matches a particular symbol with the properties of the entity that is to be drawn.

Because of the asynchronize nature of the application, a Map object cannot be created using its constructor; in fact, the Map class does not have a public constructor. To create a map object, you need to use methods from MapFactory.Instance. Methods such as MapFactory.Instance.CreateMap() add the newly created map into the current project. You do not need to write additional code for adding a map to a project.

// create a new map with an ArcGIS Online basemap
Map map = MapFactory.Instance.CreateMap("World Map", ArcGIS.Core.CIM.MapType.Map, ArcGIS.Core.CIM.MapViewingMode.Map, Basemap.Streets);
// open an existing map 
var mapProjectItems = Project.Current.GetItems<MapProjectItem>();
var mapProjectItem = mapProjectItems.FirstOrDefault(mpi => mpi.Name.Equals("World Map"));
Map map = mapProjectItem.GetMap();
ProApp.Panes.CreateMapPaneAsync(map);
// access the currently active map
Map map = MapView.Active.Map;
// set or change the basemap layer of the active map
Map map = MapView.Active.Map;
map.SetBasemapLayers(Basemap.Gray);

Working with web maps

ArcGIS Pro supports seamless integration with ArcGIS Online or your organization portal. You can add and open an existing web map in your project, add an existing portal layer item to a map, or publish a map from your project as a web map to share within your organization or with a wider audience.

Create basemaps

A basemap is a non-editable layer that provides background, or reference information, in your map. It is typically designed to provide a visual reference for other layers to help orient the user of the map. Aerial imagery, terrain, and streets from ArcGIS Online are examples of basemap layers you can add to your map. In addition, you can create custom basemap layers for your project by creating a map of basemap type and authoring it as if it were a regular map. The map appears in the basemap layer gallery on the ribbon as well as in the Content pane with a different icon.

// create custom basemap in your current project
Map basemap = MapFactory.Instance.CreateMap("My basemap", MapType.Basemap);
// create and add layer to the basemap using LayerFactory.Instance
string url = @"c:\temp\roads.shp"; 
Uri uri = new Uri(url);
Layer lyr = LayerFactory.Instance.CreateLayer(uri, basemap);

Working with MapMembers

MapMember is an abstract class and represents items contained within a map. It contains common methods and properties that are shared by layers and stand-alone tables. The Layer and StandaloneTable classes inherit from the MapMember class. To get a list of available layers and stand-alone tables in a map, use the Map.Layers and Map.StandaloneTables properties. The result from Map.Layers maintains the group layer structure. Should you need to get a list without group layers hierarchy, use Map.GetLayersAsFlattenedList() method.

//Generic MapMember class hierarchy

                                                            MapMember
                                          |--------------------|-----------------|
                                          |                                      |
                                        Layer                               StandaloneTable
                                          |
                |-------------------------|-----------------------------------------|
                |                         |                                         |
         BasicFeatureLayer          BasicRasterLayer                          CompositeLayer
                |                         |                                         |
      |---------|---------|          |----|----------|                 |------------|---------|
      |                   |          |               |                 |            |         |
AnnotationLayer    FeatureLayer  RasterLayer  ImageServiceLayer    GroupLayer  MosaicLayer  (etc.)

To find an existing MapMember such as a layer or a stand-alone table, use the FindLayer or FindStandaloneTable method respectively from a map. These methods allow you to search by unique layer or table URI. The FindLayer method is a member of the ILayerContainer interface, which is implemented by GroupLayer and CompositeLayer, so you can find a layer from a map or a composite layer. Use the 'FindLayers' or 'FindStandaloneTables' methods to find layers or standalone tables by name.

These functions do not support partial searches, but you can achieve that by using the .NET lambda expression.

//find all layers from the active map that contain 'world' in their name
Map map = MapView.Active.Map;
IEnumerable<Layer> layers = map.GetLayersAsFlattenedList().Where(l => l.Name.Contains("world"));

To get the selected layers or tables, you need to use MapView class, not Map.

MapView mapView = MapView.Active;
IReadOnlyList<Layer> selectedLayers = mapView.GetSelectedLayers();
IReadOnlyList<StandaloneTable> selectedTables = mapView.GetSelectedStandaloneTables();

Working with layers

Layers display geographic information on a map. A layer does not store the actual geographic data; rather, it references the data contained in shapefiles, geodatabases, images, and so on, then defines how to display this geographic data. Most often, a layer references to a single shapefile, table, or a view in the database. Sometimes the source of a layer is a joined table made of two or more tables. Some layers do not refer to geographic data. For example, a GroupLayer refers to other layers, and an AnnotationLayer stores text or graphic elements.

Each type of layer object represents different types of data. Examples of layer objects include the following:

  • FeatureLayer
  • RasterLayer
  • GroupLayer

All layers inherit from an abstract class called Layer, which inherits from MapMember. Layers do not have a public constructor; you cannot create them with a new keyword. Instead, you need to use one of the methods from LayerFactory.Instance to create one. The LayerFactory.Instance provides methods, such as CreateLayer(), to create any layer and returns an object of Layer type or a method such as CreateFeatureLayer() or CreateGroupLayer() to create specific layers such as FeatureLayer or GroupLayer respectively.

Layer create methods allow you to use the following:

  • Local or shared paths to shapefiles, FeatureClasses, and so on
  • URLs to map or feature services
  • Item objects

A layer must be part of a LayerContainer. Therefore you need to pass in a LayerContainer (for example, a map or a group layer that implements the ILayerContainer interface) to the create method.

//create a layer from a shapefile
string uriShp = @"\\Machine\SharedFolder\Census.shp";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(uriShp), map);

//create a layer from a feature class off an sde
string uriSde = @"c:\MyDataConnections\MySDE.sde\Census";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(uriSde), map);

//create a layer using a URL
string url = @"http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0";
Layer lyr = LayerFactory.Instance.CreateLayer(new Uri(url), map);

Working with feature layers

A FeatureLayer is a layer that is based on vector geographic data, which is typically a geodatabase, shapefile feature class, or sublayer off a map or feature service. It allows you to draw and/or edit the underlying features. DefinitionQuery can be used to draw a subset of all features.

//create a feature layer to ONLY cities in California
FeatureLayer flyr = LayerFactory.Instance.CreateFeatureLayer(new Uri(strUri), map);
flyr.SetDefinitionQuery("state_name = 'California'");

LayerFactory.Instance.CreateFeatureLayer() allows you to pass in RendererDefinition to create a feature layer with the desired symbology instead of with the default symbology.

//create a feature layer with a graduated color renderer on a numeric field
RendererDefinition rd = new GraduatedColorsRendererDefinition("POP10_SQMI");
FeatureLayer flyr = LayerFactory.Instance.CreateFeatureLayer(uri, myMap, layerName: "Population Density", rendererDefinition: rd);

Renderers

Renderers are objects that store symbolization for feature layers and draw this data based on the stored symbolization rules. To create a renderer in ArcGIS Pro, it is recommended that you create a RendererDefinition and delegate the task to a feature layer by calling the CreateRenderer method. You get a CIMRenderer object. If you need to, you can modify that and assign it to the feature layer by calling the SetRenderer method. You can get hold of the current renderer assigned to a feature layer—for example, if you want to modify a symbol used in the renderer—by calling the GetRenderer method.

//assign a graduated color renderer with 6 breaks and exclusion clause
GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
{
  ClassificationField = "CROP_ACR07",
  ClassificationMethod = ArcGIS.Core.CIM.ClassificationMethod.NaturalBreaks,
  BreakCount = 6,
  ExclusionClause = "CROP_ACR07 = -99",
  ExclusionSymbol = aExclusionSymbol,
  ColorRamp = aColorRamp,
  SymbolTemplate = aSymbolTemplate,
};

CIMRenderer gcRenderer = aFeatureLayer.CreateRenderer(gcDef);
aFeatureLayer.SetRenderer(gcRenderer);

Labeling

The labeling properties of a layer are stored in the LabelClasses collection available on FeatureLayer. To update or read properties on an existing LabelClass, get the LabelClass you want from the collection. The LabelClass provides access to commonly updated label class properties. Full label placement properties can be accessed for the label engine the map is currently using by calling GetMaplexLabelPlacementProperties() or GetStandardLabelPlacementProperties(), which return CIMMaplexLabelPlacementProperties and CIMStandardLabelPlacementProperties, respectively. To update these properties, call SetMaplexLabelPlacementProperties() or SetStandardLabelPlacementProperties() depending on the label engine being used. Call GetLabelEngine on the Map to determine which label engine is currently being used. Map level labeling properties can be accessed via the Map method GetGeneralPlacementProperties() and updated via SetGeneralPlacementProperties().

Working with raster layers

RasterLayer represents an image or pixel data on disk or in a geodatabase.

// Create a RasterLayer from an image on disk.
string url = @"C:\Images\Italy.tif";
RasterLayer rasterLayer = (RasterLayer)LayerFactory.Instance.CreateLayer(new Uri(url), map);

LayerFactory.Instance.CreateRasterLayer() allows you to pass in RasterColorizerDefinition to create a raster or image service layer with the desired colorizer instead of with the default colorizer.

// Create a new stretch colorizer definition using default constructor.
StretchColorizerDefinition stretchColorizerDef = new StretchColorizerDefinition();
await QueuedTask.Run(() =>
{
  // Create a raster layer using the colorizer definition created above.
  // Note: You can create a raster layer from a url, project item, or data connection.
  RasterLayer rasterLayerfromURL =
    LayerFactory.Instance.CreateRasterLayer(new Uri(url), aMap, 0, layerName, stretchColorizerDef) as RasterLayer;
});

Working with mosaic layers

MosaicLayer is a group layer that represents a mosaic dataset. A mosaic dataset is a collection of images that have been seamlessly mosaicked together so that they look like one image. The mosaic layer group layer can contain up to four different sublayers:

  • Boundary—Feature layer that represents the boundary of the mosaic.
  • Footprint—Feature layer that represents the footprints of the images comprising the mosaic.
  • Seamline—Feature layer that represents the seamlines between the images of the mosaic. This layer only shows if seamlines have been generated.
  • Image—Image service layer that represents the mosaic. Users can control the way images are displayed, mosaicked, and transmitted through this layer.

Feature layers that are part of a mosaic layer can be distinguished from other feature layers by using the FeatureMosaicSubLayer class. Similarly, an image service layer that is part of a mosaic layer can be distinguished from other image service layers by using the ImageMosaicSubLayer class.

// Get the Image sublayer of the mosaic layer.
ImageMosaicSubLayer mosaicImageSublayer = mosaiclayer.GetImageLayer();
// Get the Footprint sublayer of the mosaic layer.
FeatureMosaicSubLayer mosaicFootprintSubLayer = mosaiclayer.GetFootprintLayer();
// Get the Boundary sublayer of the mosaic layer.
FeatureMosaicSubLayer mosaicBoundarySubLayer = mosaiclayer.GetBoundaryLayer();
// Get the Seamline sublayer of the mosaic layer.
FeatureMosaicSubLayer mosaicSeamlineSubLayer = mosaiclayer.GetSeamlineLayer();

LayerFactory.Instance.CreateMosaicLayer() allows you to pass in RasterColorizerDefinition to create a mosaic layer with the desired colorizer instead of with the default colorizer.

// Create a new colorizer definition using default constructor.
StretchColorizerDefinition stretchColorizerDef = new StretchColorizerDefinition();
await QueuedTask.Run(() =>
{
  // Create a mosaic layer using the colorizer definition created above.
  // Note: You can create a mosaic layer from a url, project item, or data connection.
  MosaicLayer newMosaicLayer =
    LayerFactory.Instance.CreateMosaicLayer(new Uri(url), aMap, 0, layerName, stretchColorizerDef) as MosaicLayer;
});

Working with image service layers

ImageServiceLayer represents pixel data coming from an image service or a mosaic dataset. Image service layers allow users to change the order in which images are mosaicked together (called the mosaic method) and how the overlapping portions of the images are displayed (called the mosaic operator). The image service layer also allows users to control the compression of the image being transmitted.

// Get the mosaic rule of the image service.
CIMMosaicRule mosaicRule = isLayer.GetMosaicRule();
// Set the mosaic method to be Center.
mosaicRule.MosaicMethod = RasterMosaicMethod.Center;
// Update the image service with the changed mosaic rule.
isLayer.SetMosaicRule(mosaicRule);

LayerFactory.Instance.CreateRasterLayer() allows you to pass in RasterColorizerDefinition to create a raster or image service layer with the desired colorizer instead of with the default colorizer.

// Create a new colorizer definition using default constructor.
StretchColorizerDefinition stretchColorizerDef = new StretchColorizerDefinition();
await QueuedTask.Run(() =>
{
  // Create an image service layer using the colorizer definition created above.
  ImageServiceLayer imageServiceLayer =
    LayerFactory.Instance.CreateRasterLayer(new Uri(url), aMap, 0, layerName, stretchColorizerDef) as ImageServiceLayer;
});

Colorizers

Raster, mosaic, and image service layers are drawn based on properties stored in colorizers. Use the GetColorizer method on the raster and image service layers to get a CIMRasterColorizer object and make modifications accordingly. Use the SetColorizer method to apply the changes.

To create colorizers in ArcGIS Pro, it is recommended that you create a RasterColorizerDefinition first and then delegate the task of creating the colorizer to a raster, mosaic or image service layer by calling the CreateColorizer method.

// Get the colorizer from the raster layer.
CIMRasterColorizer rasterColorizer = rasterLayer.GetColorizer();
// Update raster colorizer properties.
rasterColorizer.Brightness = 10;
rasterColorizer.Contrast = -5;
rasterColorizer.ResamplingType = RasterResamplingType.NearestNeighbor;
// Update the raster layer with the changed colorizer.
rasterLayer.SetColorizer(rasterColorizer);

Querying features or rows using IDisplayTable

FeatureLayers and StandaloneTables are often entry points to accessing and selecting features and data. Both of these classes implement the IDisplayTable interface to support accessing, querying, and selecting features or rows. IDisplayTable also allows you to get the field list, set or get definition query, and so on. Note that (1) all IDisplayTable members are available directly from the FeatureLayer and StandaloneTable classes, you do not need to cast them to the IDiplayTable interface, and (2) these methods work properly when dealing with joined data.

To access the base table including joined tables, you need to use the GetTable method.

There is also a Search method for performing a search on a layer or a stand-alone table. This method returns a cursor of features or rows from the layer or the stand-alone table that meet a given search criteria. If there is a definition query set, Search will work on the subset that meets the definition criteria. Note that the Search method will not work on joined fields and returned values from joined fields; you do not need to anything special.

You can use the Select method to highlight features or rows on the map view or in the attribute table window.

//searching and returning number of features where value in 'Class' field in 'city'
QueryFilter qf = new QueryFilter()
  {
	WhereClause = "Class = 'city'"
  };

RowCursor rows = aFeatureLayer.Search(qf);

int i = 0;
while (rows.MoveNext()) i++;

Replacing data sources

There are numerous reasons why data sources need to be repaired or redirected to different locations. The idea of making these changes manually in every affected map document can be overwhelming. Methods are available with Map, Layer, and StandaloneTable classes to make these changes programmatically. You have control of updating data sources for individual map members, or you can update those that have a common workspace all at once.

FindAndReplaceWorkspacePath, available on Map, Layer, and StandaloneTable classes, allows you to substitute an entire or partial string for a layer or table's workspace path. It can't be used if the workspace type or dataset name has changed. It is ideal for scenarios where drive letters change, switch to UNC paths, update SDE connection file information, and so on.

ReplaceDatasource allows you to change the entire workspace path for all layers and tables that share the workspace path.

The Map class also provides the ChangeVersion method to switch and view data from a different SDE version.

Styles

StyleProjectItem represents a style in an ArcGIS Pro project. Styles are project items that contain reusable things such as symbols, colors, color schemes, and layout elements. The styles in a project can be retrieved as follows:

//Get all styles in the project
var styles = Project.Current.GetItems<StyleProjectItem>();

//Get a specific style in the project
StyleProjectItem style = styles.First(x => x.Name == "NameOfTheStyle");

ArcGIS Pro includes system styles that are installed and available to add to a project. These are read-only; you cannot modify their contents. In addition to the system styles, you can also create new custom styles and add these to your project as follows:

 //Full path for the new style file (.stylx) to be created
 string styleToCreate = @"C:\Temp\NewStyle.stylx";
 Project.Current.CreateStyle(styleToCreate);

When a new project is created, four system styles (ArcGIS 2D, ArcGIS 3D, ArcGIS Colors, and ColorBrewer Schemes RGB) are added to the project to ensure galleries of versatile symbols, colors, color schemes, and layout elements. You can also add other system styles or custom styles to a project. Galleries include items from all styles added to a project. Styles can be added to a project as follows:

//For ArcGIS Pro system styles, just pass in the name of the style to add to the project
Project.Current.AddStyle("3D Vehicles");

//For custom styles, pass in the full path to the style file on disk
string customStyleToAdd = @"C:\Temp\CustomStyle.stylx";
Project.Current.AddStyle(customStyleToAdd);

Removing a style from a project does not delete or otherwise change the style or its contents. Styles can be removed from a project as follows:

//For core ArcGIS Pro styles, just pass in the name of the style to remove from the project
roject.Current.RemoveStyle("3D Vehicles");

//For custom styles, pass in the full path to the style file on disk
string customStyleToRemove = @"C:\Temp\CustomStyle.stylx";
Project.Current.RemoveStyle(customStyleToRemove);

Upgrading styles

The underlying structure of symbols and styles may change with successive releases of ArcGIS Pro. That means that styles created in earlier versions may not be current. Styles that are not current can still be used in a project but will be read-only. You can check whether a style is current as follows:

//For custom styles, pass in the full path to the style file on disk
string customStyleToAdd = @"C:\Temp\CustomStyle.stylx";
Project.Current.AddStyle(customStyleToAdd);
StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(x => x.Path == customStyleToAdd);

//returns true if style matches the current Pro version
bool isCurrent = style.IsCurrent();  

If a style is not current, it can be upgraded. Upgrading will allow you to add, delete, and modify contents of the style.

//For custom styles, pass in the full path to the style file on disk
string customStyleToAdd = @"C:\Temp\CustomStyle.stylx";
Project.Current.AddStyle(customStyleToAdd);
StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(x => x.Path == customStyleToAdd);

//Upgrade style
if (style.CanBeUpgraded())
{
 StyleHelper.UpgradeStyle(style);
}

Style Item

StyleItem represents an item contained in a style. A style can contain the following types of style items:

  • SymbolStyleItem—Can be of the following types:

    • Point symbol—Symbol to draw point features.
    • Line symbol—Symbol to draw line features.
    • Polygon symbol—Symbol to draw polygon features.
    • Text symbol—Symbol to draw labels or annotation features.
  • ColorStyleItem—Single color defined by values in a supported color model.

  • ColorRampStyleItem—Array of colors in a specified pattern or scheme.

  • NorthArrowStyleItem—Directional layout element used to indicate north orientation.

  • ScaleBarStyleItem—Layout element that graphically indicates map scale.

  • LabelPlacementStyleItem—Can be of the following types:

    • Standard label placement—Set of rules based on the standard label engine determining how labels will be placed in relation to features.
    • Maplex label placement—Set of rules based on the Maplex label engine determining how labels will be placed in relation to features.

You can search for a specific type of style items in a style. For example, this is how to search for point symbols in a style:

//Get all point symbols in a style - pass in an empty string for the searchString parameter
IList<SymbolStyleItem> allPointSymbols = style.SearchSymbols(StyleItemType.PointSymbol, "");

//Get point symbols in a style that satisfy the search criteria
IList<SymbolStyleItem> pointSymbols = style.SearchSymbols(StyleItemType.PointSymbol, "red");

Similarly, you can also search for other types of style items. For example, here is how to search for colors in a style:

//Get colors in a style that satisfy the search criteria
IList<ColorStyleItem> colors = style.SearchColors("blue");

Each style item in a style has a unique key, and this key can be used to retrieve the specific style item from a style as follows:

//Get a specific style item from a style based on the KEY of the style item
//In this example, "Cone_Volume_3" is the KEY of the Cone symbol in the "ArcGIS 3D" system style
SymbolStyleItem redCone = await QueuedTask.Run<SymbolStyleItem>(() =>
    {
         return (SymbolStyleItem) style.LookupItem(StyleItemType.PointSymbol, "Cone_Volume_3");
    });

Style items can be added or removed from a style as follows:

//Add a style item to a style
await QueuedTask.Run(() =>
{
      style.AddItem(styleItemToAdd);
});

//Remove a style item from a style
await QueuedTask.Run(() =>
{
      style.RemoveItem(styleItemToRemove);
});

Symbol in a SymbolStyleItem can be retrieved as follows:

//Get symbol from SymbolStyleItem
CIMSymbol symbol = await QueuedTask.Run<CIMSymbol>(() =>
{
      return symbolStyleItem.Symbol;
});

Similarly, you can also retrieve color, color ramp, north arrow, and so on, from their respective style items. For example, this is how you can get a north arrow from NorthArrowStyleItem:

//Get north arrow from NorthArrowStyleItem
CIMNorthArrow northArrow = await QueuedTask.Run<CIMNorthArrow>(() =>
{
      return northArrowItem.NorthArrow;
});

The StyleItem class is designed to support data binding, which helps in creation of custom symbol galleries. Style items can be retrieved from a style based on search criteria, and the results can be displayed along with a preview image for each style item in a gallery. The CustomSymbolPicker SDK sample shows how this can be accomplished.

Creating and editing symbols

SymbolFactory.Instance provides many static methods and properties to create new symbols. For example, new symbols can be created as follows:

//Construct a point symbol of a specific color, size and shape
CIMPointSymbol pointSymbol = await QueuedTask.Run<CIMPointSymbol>(() =>
{
      return SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 10.0, SimpleMarkerStyle.Star);
});

//Construct a polygon symbol of specific color and fill style
CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid);

//Construct a line symbol of specific color, size and line style
CIMLineSymbol lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);

Methods are also provided for editing some properties of symbols. For example:

//Set rotation of point symbol
pointSymbol.SetAngle(30.0);

//Set width of line symbol
lineSymbol.SetSize(4.0);

In 3D scenes, point, line and polygon symbols can be displayed either in real-world units or in page units. If the symbol is displayed in real-world units, the symbol will scale with distance, which means that the symbol will display larger when you zoom in closer and smaller as you zoom away from the symbol. When creating new symbols, it is important to set the real-world unit setting of the symbol to be the same as that of the feature layer so that you do not see unexpected display results because of a mismatch. Here is how this can be done:

//Set real world setting of symbol to be the same as that of the feature layer
pointSymbol.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);

Using symbols with renderers

To update the symbol of a feature layer, you first get the feature layer's current renderer by calling the GetRenderer method, set the renderer's symbol reference to the symbol reference of the new symbol, and update the feature layer renderer by calling the SetRenderer method. For example, here is how the symbol can be updated for a feature layer symbolized with a simple renderer:

//Get simple renderer from the feature layer
CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;

//Set the symbol's real world setting to be the same as that of the feature layer
symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);

//Update the symbol reference of the current simple renderer
currentRenderer.Symbol = symbolToApply.MakeSymbolReference();

//Update the feature layer renderer
ftrLayer.SetRenderer(currentRenderer);

UI controls

Coordinate System Picker

The Coordinate System Picker is a UI component similar to the core Coordinate Picker on the ArcGIS Pro Map property sheet. Use this within an Add-in to allow users to pick a spatial reference. Configure the control using a CoordinateSystemControlProperties object

xmlns:mapping="clr-namespace:ArcGIS.Desktop.Mapping.Controls;assembly=ArcGIS.Desktop.Mapping"

<Border BorderBrush="{DynamicResource Esri_BorderBrush}" BorderThickness="2" Margin="2">
  <mapping:CoordinateSystemsControl  x:Name="CoordinateSystemsControl"
                          ConfigureControl="{Binding Path=ControlProperties}"/>
</Border>

coordinatesystempicker

A sample using the Coordinate System Picker can be found at Coordinate Systems Dialog.

Coordinate System Details

The Coordinate System Details control displays the properties of a specified spatial reference. It can be used in conjunction with a Coordinate System Picker which provides a UI for choosing a spatial reference or used alone.

xmlns:mapping="clr-namespace:ArcGIS.Desktop.Mapping.Controls;assembly=ArcGIS.Desktop.Mapping"

<mapping:CoordinateSystemsDetailsControl 
         SpatialReference="{Binding ElementName=CoordinateSystemsControl, Path=SelectedSpatialReference}"
         ShowVerticalCSDetails="true"/>

coordinatesystemdetails

A sample using the Coordinate System Picker and the Coordinate System Detail control can be found at Coordinate Systems Dialog.

Query Builder

The Query Builder control provides a UI for building a query expression against a layer or table. Configure the query builder with the layer or table and optional expression using a QueryBuilderControlProperties object.

xmlns:mapping="clr-namespace:ArcGIS.Desktop.Mapping.Controls;assembly=ArcGIS.Desktop.Mapping"

<mapping:QueryBuilderControl x:Name="QueryBuilderControl"  
                               ConfigureControl="{Binding Path=ControlProperties}"/>

querybuilder

A sample using the Query Builder control can be found at QueryBuilderControl.

Geocode control

The Geocode Locator control provides a UI for geocoding. It looks and acts the same as the Locate dockpane. It allows you to add, remove, reorder, enable and disable locators. It also provides functionality to search and display geocode results.

xmlns:mapping="clr-namespace:ArcGIS.Desktop.Mapping.Controls;assembly=ArcGIS.Desktop.Mapping"

<mappingControls:LocatorControl x:Name="locator" />

locatorControl

A sample using the Geocode Locator control can be found at GeocodingTools.

Home

Developing with ArcGIS Pro


Framework

    Add-ins

    Configurations

    Customization

    Styling


Content


CoreHost


DataReviewer


Editing


Geodatabase


Geometry

    Relational Operations


Geoprocessing


Layouts


Map Authoring


Map Exploration

    Map Tools


Raster


Sharing


Tasks


Utility Network


Workflow Manager


Reference

    2.0 Migration

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.