Building Your own Widget with ArcGIS API for JavaScript

Similar documents
Deep Dive on How ArcGIS API for JavaScript Widgets Were Built

Frontend UI Training. Whats App :

ArcGIS API for JavaScript

Modular JavaScript. JC Franco. Blake Stearman

Advanced React JS + Redux Development

ArcGIS API 4.x for JavaScript Advanced Topics. René

widgetjs Documentation

React + React Native. Based on material by Danilo Filgueira

ArcGIS API for JavaScript: Getting Started Andy René

Full Stack Developer with Java

Nick Senger & Jesse van den Kieboom

Stencil: The Time for Vanilla Web Components has Arrived

Advance Mobile& Web Application development using Angular and Native Script

Full Stack boot camp

"Charting the Course... MOC A: Developing with the SharePoint Framework. Course Summary

Angular 2 and TypeScript Web Application Development

Vue.js Framework. Internet Engineering. Spring Pooya Parsa Professor: Bahador Bakhshi CE & IT Department, Amirkabir University of Technology

Front End. Presentation Layer. UI (User Interface) User <==> Data access layer

Creating Content with iad JS

CREATE SASSY WEB PARTS. Developer Guide to SASS usage in SPFx

TypeScript. Types. CS144: Web Applications

55249: Developing with the SharePoint Framework Duration: 05 days

Lesson: Web Programming(6) Omid Jafarinezhad Sharif University of Technology

Lecture 8. ReactJS 1 / 24

Accessible Web Mapping Apps. Kelly Hutchins Tao Zhang

ArcGIS Runtime SDK for Qt: Building Apps. Koushik Hajra and Lucas Danzinger

ANGULAR 2.X,4.X + TYPESRCIPT by Sindhu

International Research Journal of Engineering and Technology (IRJET) e-issn: Volume: 05 Issue: 06 June p-issn:

Introduction to the SharePoint Framework Bob German Principal Architect - BlueMetal. An Insight company

PHP WITH ANGULAR CURRICULUM. What you will Be Able to Achieve During This Course

Templates and Databinding. SWE 432, Fall 2017 Design and Implementation of Software for the Web

CSCE 156 Computer Science II

ArcGIS Runtime SDK for.net: Building Xamarin Apps. Rich Zwaap Thad Tilton

ArcGIS Runtime SDK for.net Building Apps. Antti Kajanus David Cardella

JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology

04 Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio. Ben Riga

Web Development for Dinosaurs An Introduction to Modern Web Development

An Introduction to TypeScript. Personal Info

Angular 2 and TypeScript Web Application Development

Future Web App Technologies

Web AppBuilder Presented by

Front End Nanodegree Syllabus

Modern and Responsive Mobile-enabled Web Applications

ArcGIS Runtime: Building Cross-Platform Apps. Rex Hansen Mark Baird Michael Tims Morten Nielsen

ArcGIS Viewer for Flex Advanced Topics

Simple AngularJS thanks to Best Practices

One language to rule them all: TypeScript. Gil Fink CEO and Senior Consultant, sparxys

Front End Nanodegree Syllabus

FRONT END WEB. {< Course Details >}

AngularJS Fundamentals

Angular 2 Programming

SIX REASONS. You Should Use ArcGIS API 4.0 for JavaScript. By Julie Powell, Esri Product Management

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

Web AppBuilder for ArcGIS Dive Into Mobile Development. Yiwei Ma & Kevin Gao

Build Tizen HTML5 Apps w/ Sencha Architect & Sencha Touch

Vue.js Developer friendly, Fast and Versatile

JavaScript Rd2. -Kyle Simpson, You Don t Know JS

TypeScript. TypeScript. RxJS

ArcGIS Runtime: Building Cross-Platform Apps. Mike Branscomb Michael Tims Tyler Schiewe

THE GREAT CONSOLIDATION: ENTERTAINMENT WEEKLY MIGRATION CASE STUDY JON PECK, MATT GRILL, PRESTON SO

DECOUPLING PATTERNS, SERVICES AND CREATING AN ENTERPRISE LEVEL EDITORIAL EXPERIENCE

Welcome. Quick Introductions

Writing your first Web Data Connector

"Charting the Course... Comprehensive Angular. Course Summary

"Charting the Course... Comprehensive Angular 6 Course Summary

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

High Performance Single Page Application with Vue.js

ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins. Wolfgang Kaiser

Code Editor. The Code Editor is made up of the following areas: Toolbar. Editable Area Output Panel Status Bar Outline. Toolbar

Course 1: Microsoft Professional Orientation: Front-End Web Developer

Front End Programming

Implementing Subprograms

TypeScript coding JavaScript without the pain

Designing RIA Accessibility: A Yahoo UI (YUI) Menu Case Study

ArcGIS API for JavaScript: Using Arcade with your Apps. Kristian Ekenes & David Bayer

Angular 2 and Hexo. Static Meets Dynamic For the Best of Both Worlds! Copyright 2016 Code Career Academy

React Not Just Hype!

Chapter 15: Object Oriented Programming

ArcGIS Runtime SDK for Android: Building Apps. Shelly Gill

ArcGIS Pro SDK for.net: Add-in Fundamentals and Development Patterns. Wolf Kaiser, Uma Harano

JSX in Depth. Why JSX? The Transform. JSX is a JavaScript XML syntax transform recommended for use with React.

Cpt S 122 Data Structures. Introduction to C++ Part II

Bringing your Data to Life in the ArcGIS API for JavaScript: Vector Tiles. Craig Williams &

LEARN WITH INTRODUCTION TO TYPESCRIPT

Developing Add-Ins for ArcGIS Pro (.NET) Toronto Esri Canada UC Presented by: Gandhar Wazalwar & Kern Ranjitsingh October 11, 2018

Angular 4 Training Course Content

Course 1: Microsoft Professional Orientation: Front-End Web Developer

P a g e 1. Danish Technological Institute. Scripting and Web Languages Online Course k Scripting and Web Languages

CSE 341, Autumn 2015, Ruby Introduction Summary

Programming II (CS300)

Integrating New Visualizations with Pentaho Using the Viz API

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

CS304 Object Oriented Programming Final Term

Arjen de Blok. Senior Technical Consultant bij ICT Groep ( sinds 1995 Programmeren sinds 1990 Technologiën. Links

ArcGIS Online: Three-and-a-Half Ways to Create Tile Layers. Eric Anderson & Adam Eversole Esri Support Services

Down With JavaScript!

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016

McLab tools on the web. Deepanjan Roy Supervisor: Prof. Laurie Hendren

Treating Framework Fatigue With JavaScript

INF5750. Introduction to JavaScript and Node.js

Transcription:

Building Your own Widget with ArcGIS API for JavaScript Matt Driscoll @driskull JC Franco @arfncode

Agenda About Widgets Prerequisites Widget framework Theming DO IT! Tips & tricks

About Widgets What? Encapsulated Cohesive Single-purpose pieces of functionality Why? Reusable Interchangeable How? Different frameworks are available

Prerequisites Accessor (esri/core/accessor) TypeScript

Accessor JavaScript API Foundation Consistent developer experience TypeScript support

Accessor - Unified Object Constructor var view = new MapView({ container: "viewdiv", map: map }); var symbol = new SimpleMarkerSymbol({ style: "square", color: "blue" }); var widget = new BasemapToggle({ view: view, nextbasemap: "hybrid" });

Accessor - Defining Properties (getters + setters) var Foo = Accessor.createSubclass({ properties: { // read-only foo: { readonly: true, value: new // aliased bar: { aliasof: "foo" }, } }); // autocast baz: { type: SomeClass }

Accessor - Property watching // watch for changes using a property view.watch("map.basemap.title", handle // watch for changes to multiple prope view.watch("stationary, interacting",

TypeScript Superset of JavaScript Compiled to JavaScript Statically type-checked Syntactic sugar... sweet! Use ES6 syntax while targeting ES5 environments

Type safety let view: MapView SceneView; //... /* * TS2322: Type '"not-a-view"' is not * to type 'MapView SceneView'. */ view = "not-a-view";

Typings Help describe what things are: type PresenterName = "Alan" "Matt" interface Person { name: string; age: number; } interface Presenter extends Person { name: PresenterName; }

JS of the future, now Fat arrow functions const somefn = () => { /*... */ }; // instead of const somefn = function () { /*... */

JS of the future, now Template strings const text = `Hello. Nice to meet you, // instead of const text = "Hello. Nice to meet you,

JS of the future, now Destructuring const { map, zoom, scale } = view; // instead of const map = view.map; const zoom = view.zoom; const scale = view.scale;

JS of the future, now Rest Parameters function ignorefirst(first,...therest console.log(therest); } // instead of function ignorefirst() { var therest = Array.prototype.slice. } console.log(therest);

JS of the future, now Decorators @log() foo = "foo";

TypeScript IDE Support Visual Studio: 2015/2013, Code WebStorm Sublime Text Atom Eclipse Brackets Emacs Vim

TypeScript + JS API 4 Install TypeScript Install JavaScript API typings Start writing code! TypeScript setup

Let's see some widget decorators

Creating a class @subclass + declared @subclass("example.foo") class Foo extends declared(accessor) { //... }

Creating a class: multiple inheritance pattern @subclass + declared interface Foo extends Bar, Baz {} @subclass("example.foo") class Foo extends declared(accessor, B //... }

Defining a property @property @property() foo = new Foo();

Custom setter @property @property() set myproperty(value: string) { // note internal `_set` this._set("myproperty", value); this._ensurevalidity(value); }

Computed properties @property @property({ dependson: ["firstname, lastname"] }) get fullname() { return `${this.firstname} ${this.las }

Read-only value @property @property({ readonly: true }) myproperty = "I'm read-only";

Autocast @property @property({ type: MyClass }) myproperty; instance.myproperty = { /* params */ } console.log(instance.myproperty instan

Alias a property @property @property({ aliasof: "bar.baz" }) foo;

Alias a property @aliasof @aliasof("bar.baz") foo;

Handle click and key events @accessiblehandler @accessiblehandler private function _dosomething() { //... }

Rendering when properties change @renderable @property() @renderable() title = "hello"; @property() @renderable([ "viewmodel.foo", "viewmodel.bar" ]) viewmodel = new ViewModel();

More details in the SDK Implementing Accessor Widget Development

Widget framework JSX Lifecycle Properties Methods Events

Widget Framework: About esri/widgets/widget: Our new widget framework Accessor-based Built with TypeScript

Widget Framework: JSX JavaScript extension syntax adds XML syntax to JavaScript Looks similar to HTML Can use JS inline! <div class={classlookup.hello} onclick={this._handleclick} tabindex={0}> Hello World </div>

Widget Framework: Lifecycle constructor() postinitialize() render() destroy()

constructor() constructor(params?: any) { super(); // Do some stuff! }

postinitialize() postinitialize() { this.own( watchutils.on(this, "property", => ); }

render() Return JSX Virtual DOM render() { return ( <button>{this.title}</button> ); } Widget rendering (SDK)

destroy() destroy() { // cleanup listeners // destroy other widgets // dereference variables // etc. }

Framework: Getting/Setting Properties // normal setting of a prop mywidget.property = value; // normal getting of a prop console.log(mywidget.property); // internal set property // will not trigger setter this._set("property", propertyvalue); // internal get property // will not trigger getter this._get("property");

Framework: ViewModels (The brain) Core logic of widget resides here Provides necessary APIs for the view to do it's thing No DOM/UI concerns (think business logic)

ViewModels: Why? Framework integration Reusability Separates concerns

Widget Framework: Views (The face) esri/widgets/widget Uses ViewModel APIs to render the UI View-specific logic resides here

Views: Why? Separates concerns Framework compatibility

Views: Defining ViewModel @property({ type: MyViewModel }) viewmodel: MyViewModel = new MyViewMod

Widget Framework: Method Convention Public Methods public mymethod() {} Private Methods private _mymethod() {}

Widget Framework: Events Views have ability to emit() an event. ViewModel needs to import dojo/evented in order to emit() Views can alias an event with vmevent decorator.

Widget Framework: View Events Widget views extend dojo/evented this.emit("my-event", {...});

Widget Framework: ViewModel Events 1. Import evented import Evented = require("dojo/evented 2. Extend Evented interface MyViewModel extends Evented... } 3. Emit event when necessary this.emit("my-event", {...});

Widget Framework: Aliased View Events @vmevent("my-event") @property({ type: MyViewModel }) viewmodel: MyViewModel = new MyViewMod

Widget Theming Out of the box themes SDK: Styling topic Sass BEM

Widget Theming: Guide SDK Guide: Styles

Widget Theming: Out of the box Themes Demo

Widget Theming: Sass CSS preprocessor Variables @mixin (group statements) @include - (use mixins) @import - (split up files) @extend - (inheritance) More power!

Sass makes it easier to... Restyle Theme Modular / DRY Be organized Write less code :)

Sass Install Installing Sass Themes source on Github

Widget Theming: BEM BEM: Block Element Modifier Methodology to create reusable components Uses delimiters to separate block, element, modifiers Provides semantics (albeit verbose) Keeps specificity low Scopes styles to blocks /* block */.example-widget {} /* block element */.example-widget input {}.example-widget submit {} /* block--modifier */.example-widget--loading {} /* block element--modifier */.example-widget submit--disabled {}

DO IT! Build a widget! Demo

Setup HTML & CSS with Sass HTML Setup Steps Sass Setup Steps

Tips & Tricks Collections Accessibility i18n

Rethinking Widget APIs Using esri/core/collection instead of Arrays Using esri/core/accessor instead of plain objects Adding properties to manage widget state Hiding nodes with Widget framework JSX instead of CSS setting JSX node to null when necessary Private/protected variables

Accessibility tabindex aria roles keyboard events

i18n Import language file import * as i18n from "dojo/i18n!./myw Setup root language file with languages // "/nls/mywidget" define({ root: ({ helloworld: "Hello World" }), "es": 1 }); Setup other languages. (\es) // "/nls/es/mywidget" define({ helloworld: "Hola Mundo" });

Suggested Sessions Building Classes Using Accessor and the ArcGIS API for JavaScript Using TypeScript with ArcGIS API for Javascript Deep Dive on How ArcGIS API for JavaScript Widgets Were Built

Additional Resources Styling Implementing Accessor Setting up TypeScript Widget Development JavaScript Sessions at DevSummit Documentation 4.3

Use the source luke esriurl.com/buildwidgets2017

Please Take Our Survey! 1. Download the Esri Events app and go to DevSummit 2. Select the session you attended 3. Scroll down to the "Feedback" section 4. Complete Answers, add a Comment, and Select "Submit"

Questions?

Thank you!