31
ArcGIS Pro SDK for .NET Intro and Pro Add-in Programming Patterns Wolfgang Kaiser

ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

ArcGIS Pro SDK for .NET Intro and Pro Add-in

Programming PatternsWolfgang Kaiser

Page 2: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Session Overview

• Introduction to Pro Add-ins and the Module

• Introduction to Pro Configurations

• Asynchronous Programming: Introduction to QueuedTask

- Use of async and await

- Authoring custom asynchronous functions

• Overview of MVVM

- Dockpane example

• ‘Hooking’ (reusing) existing ArcGIS Pro commands

Page 3: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

What is an ArcGIS Pro add-in ?

• Extends ArcGIS Pro through:

- Buttons

- Tools

- Dockpanes

- Embeddable control

- ..

• Packaged within a single, compressed

file with an .esriaddinX file extension

Page 4: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

What is an ArcGIS Pro add-in? (Continued)

• Uses a declarative-based framework (config.daml)

• Authored using .NET

• .NET Add-ins are using:

- 64-bit platform

- WPF (Windows Presentation Foundation) with .NET 4.6.1 +

MVVM pattern (Model View ViewModel)

- Asynchronous Patterns: Multiple threads

- ArcGIS Pro API which comes with ArcGIS Pro out-of-box

Page 5: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

What is the ArcGIS Pro SDK for .NET?

• Easy to use project templates and wizards (in Visual

Studio 2015 and 2017)

• New installation experience

- Integrated with Visual Studio gallery

Page 6: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

The Module Class

• Hub and central access point for a subsystem

• Similar to the Extension object used in the ArcObjects 10.x

framework

• Singletons instantiated automatically by the Framework

internal class Module1 : Module {private static Module1 _this = null;/// <summary>/// Retrieve the singleton instance to this module here/// </summary>public static Module1 Current{

get{

return _this ?? (_this = (Module1)FrameworkApplication.FindModule("ProAppModule7_Module"));}

}

Page 7: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Config.daml

• Declarative add-in definition

• Configuration file that contains framework elements (buttons, dockpane, galleries)

• Can add, modify, delete any default ArcGIS Pro User Interface element

• Uses XML Syntax

<ArcGIS defaultAssembly="WorkingWithDAML.dll" defaultNamespace="WorkingWithDAML"xmlns="http://schemas.esri.com/DADF/Registry"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://schemas.esri.com/DADF/Registryfile:///C:/Program%20Files/ArcGIS/Pro/bin/ArcGIS.Desktop.Framework.xsd">

<AddInInfo id="{c6226a24-d69b-46c6-b5e7-9eee4ddad45d}" version="1.0" desktopVersion="1.1.2850">…</AddInInfo><modules>

<insertModule id="WorkingWithDAML" className="Module1" autoLoad="false" caption="Module1"><tabGroups>

<!--The new Tab Group is created here--><tabGroup caption="Example State Solution" id="working_with_DAML_ExampleStateTabGroup">

<color A="255" R="238" G="170" B="90" /><borderColor A="0" R="251" G="226" B="195" />

</tabGroup></tabGroups>

Page 8: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

.NET Configurations for Extending Pro

• Similar in structure to an Add-in plus:

- A Configuration Manager class that provides deeper

customization:

- Splash screen

- Startup page

- Conditional customization at runtime (e.g. based on user role)

- Also deployed as an archive (.proConfigX)

- Available to all logged-on users

- Multiple configurations can be installed but only one can be active per session.

Page 9: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Extensibility Points for Add-ins & Configurations

• Any Framework Element is an extensibility point

- Controls (Button, Tool, and variants)

- Hosted on Ribbons, Menus, Galleries

- Checkbox, Combobox, Label Control, Custom Controls

- Tabs, Tab Groups

- Toolbars

- Menus, Context Menus

- Panes, Dockpanes

- Galleries

- Property Sheets

• All Elements have a definition within DAML

• Majority of Framework Elements are represented by Visual Studio Item templates

- Automates generation of DAML

- Add relevant code-behind files to the project

Page 10: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Visual Studio Demo …. Project

and Item templates

Create an Add-in & Configuration

Demo:

Page 11: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Asynchronous Programming

• ArcGIS Pro is a multi-threaded 64 bit application

• Important asynchronous programming patterns for the

SDK:

- Async / Await

- Using the Pro Framework’s QueuedTask class

• Asynchronous Programming allows you to keep the User

Interface responsive !

Page 12: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

ArcGIS Pro Internal Threading Model

• ArcGIS Pro is multi-threaded- Incorporates the latest asynchronous language features from Microsoft

- Implements a threading infrastructure tailored to reduce complexity.

• Add-In developers should only need to contend with two

threads:

- The GUI thread

- A single specialized worker thread called the Main CIM Thread, MCT

- Internally, ArcGIS Pro uses a large number of threads for:

- Rasterization, rendering, data loading, GP

- But all this is Isolated from the API

• Simplifies coding, ensures consistency of Pro state.

Page 13: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Categories of Methods in ArcGIS Pro API

• Coarse-grained asynchronous methods:

- Can be called on any thread

• Finer grained synchronous methods:

- Must be called within a QueuedTask

Page 14: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Coarse Grained Methods

• Can be called from any thread. Typically invoked from the UI thread

- They execute in the background on Pro internal threads

- Use async/await semantic

//Execute a GP Toolawait Geoprocessing.ExecuteToolAsync("SelectLayerByAttribute_management",

new string[] {"parcels","NEW_SELECTION", "description = 'VACANT LAND'"});await MapView.Active.ZoomToSelectedAsync(new TimeSpan(0, 0, 3));

Page 15: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Coarse Grained Methods

PlenaryPopup Data

Demo:

Page 16: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Fine Grained, Synchronous Methods

Must be called within a QueuedTask

- A much greater number of fine grained methods and classes

- No async/await. Runs on the MCT

- Designed for aggregation into your own coarse-grained async methods

- In other words: this allows you to write your business logic as a ‘background’ task

await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>{

var layers = MapView.Active.Map.FindLayers("Parcels").OfType<FeatureLayer>().ToList();

var parcels = layers[0] as FeatureLayer;QueryFilter qf = new QueryFilter(){

WhereClause = "description = 'VACANT LAND'",SubFields = "*"

};parcels.Select(qf, SelectionCombinationMethod.New);

});

Page 17: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

QueuedTask

• QueuedTask uses the Pro framework’s custom Task scheduler

• Used to run synchronous ArcGIS Pro SDK methods in the

background

• These synchronous methods are listed in the API Reference guide like

this:

“This method must be called on the MCT. Use QueuedTask.Run”

• Example of synchronous methods in Pro:

- GetSpatialReference, QueryExtent, Geometry operations

• Usage:

Task t = QueuedTask.Run(() =>{

// Call synchronous SDK methods here});

Page 18: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Fine Grained Methods

PlenaryPopup Data

Demo:

Page 19: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

MVVM Pattern in Add-ins

• MVVM and variants are de-facto pattern for WPF UI implementations

• Pro MVVM is built on top of ActiPro

(http://www.actiprosoftware.com/products/controls/wpf )

• The Basic Pattern is:

- ViewModel declared in DAML and implemented in code

- View referenced in DAML and implemented as WPF UserControl

- Model is optional

• Note: To customize the Pro UI, you must use its MVVM Framework.

Substitutes are not allowed.

Page 20: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

MVVM Pattern in Add-ins

• Model-View-ViewModel (MVVM) Pattern used for many of the

Framework elements

- Dockpane

- Pane

- Custom Control

- Embeddable Control

- Property Page

Page 21: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

MVVM Implementation in Add-ins

• MVVM implementation in Add-ins follows the same Pattern used in

WPF / .Net

- Model: Classes that represent the data consumed by the app

- View: User interface (UI) elements the user interacts with (XAML)

- ViewModel: Classes that wrap data (coming from a model) and provide business

logic for the UI (views)

• Implement your Add-in UI just as you implement a user control in WPF/.Net

- You can use many available online WPF MVVM snippets

• Differences in MVVM for Add-ins versus WPF applications:

- Multi-threading considerations

- ArcGIS Pro Styling

Page 22: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Demo:New Dockpane using MVVM

Dockpane template

PlenaryPopup Data

Page 23: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Hooking Existing ArcGIS Pro Commands

• Reference an existing Button, Tool, Gallery:

- Done in your config.DAML

- Add Elements (button image and all)

or groups to your tab or tab group

- Snippet below

esri_mapping_bookmarksNavigateGallery

is a sample reference

Page 24: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Hooking Existing ArcGIS Pro Commands

• Get any Pro control’s ICommand and use it in your add-in:

- Done by using the Pro Framework’s “GetPlugInWrapper” method.

• A Pro control’s command can be added to your add-in button’s click method. (or

anywhere else in your add-in).

// ArcGIS Pro's Create button control DAML ID.var commandId = DAML.Button.esri_mapping_createBookmark;// get the ICommand interface from the ArcGIS Pro Button// using command's plug-in wrapper// (note ArcGIS.Desktop.Core.ProApp can also be used)var iCommand = FrameworkApplication.GetPlugInWrapper(commandId) as ICommand;if (iCommand != null){

// Let ArcGIS Pro do the work for usif (iCommand.CanExecute(null))

iCommand.Execute(null);}

Page 25: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Hooking Existing ArcGIS Pro Commands• Adding a button to the Dockpane to run the ‘Close ArcGIS Pro’ Command

• Adding a button to the Dockpane with our ‘custom’ Zoom in behavior

• RelayCommand is an implementation of ICommand which lets you specify your own

implementation of Execute and CanExecute

Page 26: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Demo:Hooking Existing Pro Commands

PlenaryPopup Data

Page 27: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Many Pro SDK Resources

• SDK home page – main resource page

• Esri Training – instructor-led Esri training course

• Documentation Wiki – primary documentation site

with concept and guide docs, and much more

• Community Samples – ready to use code solutions

categorized by functional area

• Snippets – code snippets by functional area

• GeoNet Pro SDK Group – developer community

• API Reference – full API reference

• FAQ – answers to common questions

• Blog posts – focused on the Pro SDK

Page 28: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Pro SDK Training

• Extending ArcGIS Pro with Add-Ins – Esri

Instructor-led training course on the Pro SDK

• Great way to get a comprehensive

introduction

• Online offerings – very interactive and

productive

• Esri.com/training

Page 29: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

SDK Sessions

Day Time ArcGIS Pro SDK for .NET Sessions Room

Tuesday, 24th 13:00 - 13:45 Intro and Pro-Add-in Programing Patterns B 07 - B 08

Wednesday, 25th

09:00 - 09:45 Intro and Pro-Add-in Programing Patterns B 05

10:00 - 10:45 Customize Pro to Streamline Workflows C 01

11:00 - 11:45 Advanced UI Development B 05

15:00 - 15:45 Map Exploration A 03 - A 04

Thursday, 26th 12:00 - 12:45 Customize Pro to Streamline Workflows B 09

Page 30: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects

Thank You to Our Generous Sponsor

Page 31: ArcGIS Pro SDK for .NET: Intro and Pro Add-in Programming ... · The Module Class •Hub and central access point for a subsystem •Similar to the Extension object used in the ArcObjects