Building Mobile Apps with the ArcGIS API for...

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

Transcript of Building Mobile Apps with the ArcGIS API for...

Page 1: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Building Mobile Apps with the ArcGIS API for JavaScript

Andy Gup & Lloyd Heberlie

Page 2: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Expectations

Page 4: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Lloyd Heberlie

Capabilities

Page 5: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

TouchDemo

Page 6: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

BasemapGallery

Page 7: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

BasemapToggle

Page 8: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

BasemapToggle

Page 9: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Home

Page 10: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

LayerList

Page 11: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

LayerList action

Page 12: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Expand

Page 13: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Compass

Page 14: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Compass

Page 15: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

LocateDemo

Page 16: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Popups

Page 17: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Calcite Maps - Settings

Page 18: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Calcite Maps - Settings

Page 19: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Calcite Maps - Basemaps

Page 20: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Calcite Maps - Basemaps

Page 21: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

HTML5 input types

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

Page 22: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Mobile media queries

1

2

Page 23: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Mobile media queries

macOS

Android

iPhone

iPad

Page 24: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Mobile media queries

Page 25: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Mobile media queries

Page 26: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

CapabilitiesDemos

Page 27: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Managing initial load times

Page 28: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Consider synchronous patterns

Framework init

dojo/ready!

Map ready

Feature service loaded

Page 33: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Lazy load modules and libraries

Wait for user input

Map ready

Load widget

Page 34: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Lazy load demo

Demo

Page 35: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

API reference

WebMap.loadStatus

Page 39: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

load() example

Demo

Page 40: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Lloyd Heberlie

Using local builds

Page 42: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

ArcGIS API for JavaScript Web Optimizer – 3x

Bower

npm

How to create custom builds?

Page 44: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

• 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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Using local buildsDemo

Page 46: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Working with Cordova and IonicNative Mobile

Page 47: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Cordova/Phonegap

Wait for “deviceready” event

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

Page 48: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Working with FrameworksMobile browser-only

Page 50: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Test Mobile Performance

Page 52: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Google Chrome DevTools

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

devtools/evaluate-performance/

Page 53: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Google Chrome DevTools

Performance > Capture Settings > CPU

Page 54: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Google Chrome DevTools

Performance > Capture Settings > Network

Page 55: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

WebPageTest

https://webpagetest.org/

Page 56: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy
Page 57: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Lloyd Heberlie

Debugging and testing

Page 59: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Physical devices

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

Page 60: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Enable iOS remote web inspection

Page 62: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Enable Android remote web inspection

Page 63: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Content Security Policy (CSP)

Page 64: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Debugging MobileDemo

Page 65: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

Working with GPS

Page 66: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

High-accuracy GPS

Bluetooth enabled

Bad Elf GNSS (left)

Trimble R1 (right)

Page 68: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

GPS Drift

Stationary device

Page 70: Building Mobile Apps with the ArcGIS API for JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy

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 JavaScriptproceedings.esri.com/library/userconf/proc17/tech-workshops/tw_601... · •ember-esri-loader ... Cordova plugin for high-accuracy