Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript...

42
Building Your Own Widget with ArcGIS API for JavaScript Ben Ramseth Software Engineer - Esri

Transcript of Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript...

Page 1: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Building Your Own Widget with ArcGIS API for JavaScriptBen RamsethSoftware Engineer - Esri

Page 2: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Topics covered

• What is a widget?• Typescript• Setting up the Developer Environment• Creating a basic web mapping app with typescript• Implementing Accessor• Widget framework• Building a widget• @arcgis/cli• Summary

Page 3: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

About Widgets

• What?- Encapsulated UI components- Cohesive (integrated, unified)- Single-purpose pieces of functionality

• Why?- Reusable- Interchangeable

• How?- Extend esri/Widgets/Widget

Page 4: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Let’s take a look at a few…What are widgets

Page 5: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Widgets can also be views that make up an app

Page 6: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

JS API + TypeScriptDeveloper environment

Page 7: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Typescript - https://www.typescriptlang.org/

Page 8: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Typed JavaScriptinterface Person

name: string; age: number;

const person: Person = name: "Franco", age: 33 ;

person.age = "24"; // TS2322: Type '"24"' is not assignable to type 'number' person.height = 5.11; // TS2339: property 'height' does not exist on type 'Person'

Page 9: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

JS of the future,now// let and const

let canChange = 5;const cannotChange = 5;

// fat arrow functionsconst logName = (person) => console.log(person.name);

// template stringsconst greeting = `Hello, my name is $person.name and

I am $person.age years old

// destructuringconst name, age = person;

// property shorthandconst shorthand = person ;

Page 10: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

IDE SupportVisual Studio WebStorm Sublime Text and more!

Page 11: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

JSAPI API – Typescript - VSCode

Setting up the Dev Environment

Page 12: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

https://developers.arcgis.com/javascript/latest/guide/implementing-accessor/index.html

Implementing Accessor

Page 13: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

How we built it.Widget Framework

Page 14: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Pieces needed for the Widget Framework

• Typescript• JSX• esri/core/Accessor

Page 15: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Widget life cycle

• constructor (params)- widget is initially created- access to getting, setting, and watching properties

• postInitialize()- Runs after creation and before render

• render()- only required method- renders the UI

• destroy()- release widget instance

Page 16: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

TypeScript decorators

• Allows us to define and modify common behavior in existing properties, methods, and constructors at design time

- @subclass (used in conjunction with declared)- underlying glue that is used to create 4.x classes

- @property()- used to define an Accessor property

- @renderable()- schedules the render whenever a property is modified- @property() and @renderable() often used together

- @aliasOf()- keep code clean so as to not duplicate existing properties- links to properties in the ViewModel

Page 18: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Extend the widget

• extending from the base Widget class

Page 19: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Implement properties and methods

Page 20: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Render the widget

• render is the only required method

Page 21: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Widget rendering

• classes: use the classes helper method • styles: Allows styles to be changed dynamically• afterCreate: executes after the node is added to the DOM• afterUpdate: executes every time the node is updated• bind: set the value for event handlers• key: uniquely identify a DOM node. Needed if sibling elements with the same selector and

the elements are added/removed dynamically

Page 22: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Export module

• end of the code page

Page 24: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Beyond the basics…Building a Widget

Page 26: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

ArchitectureSeparation of concerns

Views + ViewModels UI replacement Easier integration

Page 27: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Views• Extend esri/widgets/Widget

• Rely on ViewModel Focus on UI

Page 28: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

ViewModelsExtend esri/core/Accessor Provide APIs to support View Focus on business logic

Page 29: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

View + ViewModel inactionView renders the state of the VM

Looks at properties on VM and renders accordingly User interacts with View (property/method)

Causes a change on VM or View View updates

Renders again due to changes on VM

Page 31: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Summary

Page 33: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Let’s have some questions…

Page 34: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,
Page 35: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Please Take Our Survey on the AppDownload the Esri Events app and find your event

Select the session you attended

Scroll down to find the feedback section

Complete answersand select “Submit”

Page 36: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Presentation TitlePresenter Names

Page 37: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,
Page 38: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,
Page 39: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,
Page 40: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Sample Name Here

Click HereFor DEMO

Page 41: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,
Page 42: Building Your Own Widget with ArcGIS API for JavaScript · release widget instance. TypeScript decorators • Allows us to define and modify common behavior in existing properties,

Please Take Our Survey on the AppDownload the Esri Events app and find your event

Select the session you attended

Scroll down to find the feedback section

Complete answersand select “Submit”