arcgis api for javascript customizing widgets€¦ · agen da set up dev environment create a......

31
ArcGIS API for JavaScript Customizing the Widgets Julian Kissling | Rene Rubalcava slides: https://git.io/Je0y6 1 / 31

Upload: others

Post on 03-Jun-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

ArcGIS API for JavaScriptCustomizing the WidgetsJulian Kissling | Rene Rubalcava

slides: https://git.io/Je0y6

1 / 31

Page 2: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Agenda

Set up dev environmentCreate a...

Custom ClassSimple WidgetCustom Widget

Enhance Custom Widget

2 / 31

Page 3: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Setting up the Dev

Environment

3 / 31

Page 4: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Developer

environmentJS API + TypeScript

4 / 31

Page 5: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

TypeScript

5 / 31

Page 6: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Typed JavaScriptinterfaceinterface  PersonPerson  {{    name  name::  stringstring;;    age  age::  numbernumber;;  }}    

constconst person person:: Person  Person ==  {{ name name::  "Rocky""Rocky",, age age::  3333  }};;    personperson..age age ==  "24""24";;  // TS2322: Type '"24"' is not assignable to type 'number'// TS2322: Type '"24"' is not assignable to type 'number'  personperson..height height ==  5.115.11;;  // TS2339: property 'height' does not exist on type 'Person'// TS2339: property 'height' does not exist on type 'Person'  

6 / 31

Page 7: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

JS of the future, now// let and const// let and const  letlet canChange  canChange ==  55;;  constconst cannotChange  cannotChange ==  55;;    // fat arrow functions// fat arrow functions  

constconst  logNamelogName  ==  ((personperson))  =>=>  consoleconsole..loglog((personperson..namename));;    // template strings// template strings  constconst greeting  greeting ==  `Hello, my name is `Hello, my name is ${${personperson..namename}} and I am  and I am ${${personperson..ageage}} years old.` years old.`;;    // destructuring// destructuring  constconst {{ namename ageage }} == personperson;;

7 / 31

Page 8: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

IDE SupportVisual StudioWebStormSublime Textand more!

8 / 31

Page 9: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Install TypeScript + JS API

9 / 31

Page 10: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Dev EnvironmentInstalled TypeScript + JS API typingsBuilt mapping application

10 / 31

Page 11: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Creating a Class

11 / 31

Page 12: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

esri/core/AccessorJavaScript API foundationConsistent developer experience

// unified object constructor// unified object constructor  constconst me  me ==  newnew  PersonPerson(({{ name name::  "Franco""Franco",, age age::  3333  }}));;    // watch for changes to `age`// watch for changes to `age`  meme..watchwatch(("age""age",, singHappyBirthday singHappyBirthday));;  

12 / 31

Page 13: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

// fetches webmaps from a portal and provides APIs to work with them// fetches webmaps from a portal and provides APIs to work with them  interfaceinterface  CustomClassCustomClass  {{  // used to fetch webmaps items// used to fetch webmaps items  portalportal:: Portal Portal;;  webMapGroupIdwebMapGroupId::  stringstring;;    // active webmap and all fetched ones// active webmap and all fetched ones  readonlyreadonly active active:: PortalItem PortalItem;;  readonlyreadonly webMaps webMaps:: PortalItem PortalItem[[]];;  

  // will be updated with the active webmap// will be updated with the active webmap  viewview:: MapView MapView;;  

13 / 31

Page 14: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Demo Recap: Custom Class

Implemented CustomClassExtended esri/core/AccessorCreated properties with @propertyTyped constructor argumentsCreated public + private methods

14 / 31

Page 15: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Writing a Widget

15 / 31

Page 16: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

About Widgets

What?Encapsulated UI componentsCohesive (integrated, uni�ed)Single-purpose pieces of functionality

Why?ReusableInterchangeable

How?Extend esri/Widgets/Widget

16 / 31

Page 17: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

esri/widgets/Widget

Base widget class (View)Extends esri/core/Accessor

PropertiesWatching properties

Lifecycle

17 / 31

Page 18: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Lifecycle

constructorpostInitializerenderdestroy

18 / 31

Page 19: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

renderDe�nes UIReacts to state changesUses JSX (VDOM)

19 / 31

Page 20: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Write simple widget

20 / 31

Page 21: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Simple View

Extended esri/widgets/WidgetImplemented render()Added a renderable() property

Added onclick event

Added CSS Object + Toggled property with event to re-render

BEM Methodology

21 / 31

Page 22: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Improving Our

Widget

22 / 31

Page 23: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

ArchitectureSeparation of concerns

Views + ViewModelsUI replacementEasier integration

23 / 31

Page 24: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

ViewsExtend esri/widgets/WidgetRely on ViewModelFocus on UI

24 / 31

Page 25: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

ViewModelsExtend esri/core/AccessorProvide APIs to support ViewFocus on business logic

25 / 31

Page 26: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

View + ViewModel in action

View renders the state of the VMLooks at properties on VM and renders accordingly

User interacts with View (property/method)Causes a change on VM or View

View updatesRenders again due to changes on VM

26 / 31

Page 27: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Demos

27 / 31

Page 29: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

Question Time

29 / 31

Page 30: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

30 / 31

Page 31: ArcGIS API for JavaScript Customizing Widgets€¦ · Agen da Set up dev environment Create a... Custom Class Simple Widget Custom Widget Enhance Custom Widget 2 / 31. Setting up

31 / 31