building mobile apps with the arcgis api for javascript · managing app life-cycle working with...

71
Building Mobile Apps with the ArcGIS API for JavaScript Andy Gup & Lloyd Heberlie

Upload: others

Post on 18-Apr-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Building Mobile Apps with the ArcGIS API for JavaScript

Andy Gup & Lloyd Heberlie

Page 2: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Agenda

Capabilities

Managing app life-cycle

Working with locally hosted builds

Working from JS frameworks

Debugging

GPS

Page 3: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Expectations

Page 4: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Lloyd Heberlie

Capabilities

Page 5: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

TouchDemo

Page 6: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

BasemapGallery

Page 7: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

BasemapToggle

Page 8: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

BasemapToggle

Page 9: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Home

Page 10: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

LayerList

Page 11: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

LayerList action

Page 12: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Expand

Page 13: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Compass

Page 14: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Compass

Page 15: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

LocateDemo

Page 16: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Popups

Page 17: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Calcite Maps - Settings

Page 18: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Calcite Maps - Settings

Page 19: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Calcite Maps - Basemaps

Page 20: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Calcite Maps - Basemaps

Page 21: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

HTML5 input types

type=“email” type=“tel” type=“date”

Page 22: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Mobile media queries

1

2

Page 23: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Mobile media queries

macOS

Android

iPhone

iPad

Page 24: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Mobile media queries

Page 25: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Mobile media queries

Page 26: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

CapabilitiesDemos

Page 27: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Managing initial load times

Page 28: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Initial loading in a mobile browser

Often misunderstood

Many things happening

Vulnerable to timing issues

Consider user’s experience

Page 29: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Initial loading in a mobile browser

CSS

3rd party libraries

Frameworks

Framework plugins

ArcGIS JS API

GIS queries

GET map tiles

Page 30: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Initial loading in a mobile browser

CSS

3rd party libraries

Frameworks

Framework plugins

ArcGIS JS API

GIS queries

GET map tiles

Page 31: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Initial loading in a mobile browser

Wait for framework initialization

- In Angular: implements OnInit

- In Cordova: ‘deviceready’ event

- In ArcGIS: dojo/domReady!

Page 32: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Consider synchronous patterns

Framework init

dojo/ready!

Map ready

Feature service loaded

Page 33: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Lazy load modules and libraries

Wait for user input

Map ready

Load widget

Page 34: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Lazy load demo

Demo

Page 35: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Reserve async for after app load

Wait for framework initialization

- In Angular: implements OnInit

- In Cordova: ‘deviceready’ event

- In ArcGIS: dojo/domReady!

Page 36: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

MapView ready?

The View has a Map

View container size is greater than zero

View has a spatial reference

API Reference MapView.ready

Demo

Page 37: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Loadable Patterns

Any resource that handles async data access

Examples: feature layers, tasks, web maps

not-loaded

loading

failed

loaded

Page 38: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

API reference

WebMap.loadStatus

Page 39: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

load() example

Demo

Page 40: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Splash Screens

Distract end user from long load times

Gives you control over when main app visible

Wait for MapView.then()

https://github.com/andygup/splash-screen-js

Page 41: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Lloyd Heberlie

Using local builds

Page 42: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

More modules – more requests

Optimized build for app

Web application vs. Hybrid

Reduce http service calls for Hybrid apps

Why?

Page 43: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

ArcGIS API for JavaScript Web Optimizer – 3x

Bower

npm

How to create custom builds?

Page 44: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

• Optimizing Your JavaScript App for Performance

-Thursday, July 13 - 12:30 - 1:15 pm - 45 minutes

-SDCC - Demo Theater 11 - Developer

More information

Page 45: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Using local buildsDemo

Page 46: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Working with Cordova and IonicNative Mobile

Page 47: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Cordova/Phonegap

Wait for “deviceready” event

https://github.com/Esri/quickstart-map-phonegap

Page 48: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Ionic and loading ArcGIS JavaScript modules

Many helper libraries!

• angular-esri-loader (Angular 4+, wraps esri-loader)

• esri-loader (platform agnostic)

• Ionic2-esri-map (Sample app)

• ArcGIS TypeScript definitions

Page 49: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Working with FrameworksMobile browser-only

Page 50: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Other frameworks

• Plain old Bootstrap

• calcite-maps

• ember-esri-loader

• esri-loader-react

• esri-system-js

Page 51: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Test Mobile Performance

Page 52: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Google Chrome DevTools

https://developers.google.com/web/tools/chrome-

devtools/evaluate-performance/

Page 53: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Google Chrome DevTools

Performance > Capture Settings > CPU

Page 54: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Google Chrome DevTools

Performance > Capture Settings > Network

Page 55: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

WebPageTest

https://webpagetest.org/

Page 56: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd
Page 57: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Performance metrics to keep in mind

Time until first map tile

Time until last map tile

Example

Each new URL requires a DNS lookup + SSL negotiation

- Solution: self-host as much as possible

Page 58: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Lloyd Heberlie

Debugging and testing

Page 59: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Physical devices

http://blog.adtile.me/2014/01/08/adtile-device-lab/

Page 60: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Remote debugging

• Safari Web Inspector Remote

• Google Chrome remote debugging

• http://livereload.com/

• Browser-sync

Page 61: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Enable iOS remote web inspection

Page 62: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Enable Android remote web inspection

Page 63: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Content Security Policy (CSP)

Page 64: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Debugging MobileDemo

Page 65: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Working with GPS

Page 66: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Built-in GPS

Don’t use for field data collection!

Okay to use for approximate location

github.com/Esri/html5-geolocation-tool-js

Page 67: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

High-accuracy GPS

Bluetooth enabled

Bad Elf GNSS (left)

Trimble R1 (right)

Page 68: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

High-accuracy GPS and Web Mapping Apps

Best approach is Hybrid => Cordova, Ionic

Also consider ArcGIS Runtimes

NOTE: Regular browser Geolocation API may provide

incorrect data

Page 69: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

GPS Drift

Stationary device

Page 70: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd

Cordova plugin for high-accuracy on Android

Works with high-accuracy GPS via bluetooth

Separates GPS locations from Network locations

https://github.com/Esri/cordova-plugin-advanced-

geolocation

Page 71: Building Mobile Apps with the ArcGIS API for JavaScript · Managing app life-cycle Working with locally hosted builds Working from JS frameworks Debugging GPS. Expectations. Lloyd