77
Building Native Apps with ArcGIS API for JavaScript Using PhoneGap and jQuery Andy Gup, Lloyd Heberlie

ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Building Native Apps with ArcGIS API for JavaScript Using PhoneGap and jQuery

Andy Gup, Lloyd Heberlie

Page 2: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Agenda

•Getting to know PhoneGap• jQuery and jQuery mobile overview• jQuery and ArcGIS API for JavaScript• Putting it all together• Additional information

Page 3: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Technical workshops at Dev Summit

• Web- Building Mobile Web Apps with the ArcGIS API for JavaScript

• Hybrid- You are here!

• Native- Search the agenda for “Runtime SDK”

Page 4: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Application comparison: Native vs. Web

• ArcGIS Runtime SDK for Android• https://developers.arcgis.com/android/guide/native-vs-web.htm• ArcGIS Runtime SDK for iOS• https://developers.arcgis.com/ios/objective-c/guide/native-vs-web.htm

Page 5: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Lloyd Heberlie

Hello Cordova and Resources

Page 6: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Enable Safari remote web inspection

Page 7: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

What is PhoneGap?

• Application container technology• Core engine is 100% open source• Web view container, plus JS API• HTML5, CSS3, JS = Native App

PhoneGap

Page 8: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

PhoneGap architecture

PhoneGapPlugins

PhoneGap ApplicationCode

NativeApp

Page 9: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

PhoneGap Plugins

Page 10: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

PhoneGap Plugin options

Page 11: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Setup a developer machine

Source Control

Code quality and verification

web server

Page 12: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Preparing for PhoneGap

Page 13: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Installing PhoneGap and Apache Cordova

Page 14: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Check versions of PhoneGap and Apache Cordova

Page 15: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Updating PhoneGap and Apache Cordova

Page 16: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Creating your first PhoneGap CLI project

phonegap create path/to/my-app "com.example.app" "My App"

Page 17: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Lloyd Heberlie

Hello Cordova (cont.)

Page 18: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

PhoneGap: Featured Apps

Page 19: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Featured Apps: Tripcase, Untappd

Page 20: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Agenda

• Getting to know PhoneGap

• jQuery and jQuery mobile overview• jQuery and ArcGIS API for JavaScript• Putting it all together• Additional information

Page 21: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,
Page 22: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Theme roller

Page 23: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

data-attributes

Page 24: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Selections and filtering

Page 25: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Events

Page 26: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Dynamic content

Page 27: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

jQuery mobile page lifecycle

Page 28: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Application lifecycle

phone OS nativeapplication

Esrimap

Esrimap

layers

3rd party +Esri JS

Page 29: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Lloyd Heberlie

jQuery mobile lifecycle

Page 30: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

LifeCycleApplication

3rd Party JS

Map

Layers

Phone OS

Page 31: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

jQuery and ArcGIS API for JavaScriptAndy Gup

Page 32: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Jquery Mobile + ArcGIS

Page-based approach versus responsiveSingle page map appMultiple page map app

https://github.com/Esri/quickstart-map-phonegaphttps://github.com/Esri/jquery-mobile-map-js

Page 33: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Single Page view

Page Structure

Apply CSS, roles and themes

Page 34: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Viewport meta tag

Page 35: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Single Page Map - HTML

Page 36: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Single Page Map - HTML

Page 37: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Single Page Map - HTML

Page 38: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Single Page Map - CSS

Page 39: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Andy Gup

Single page app

Page 40: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multi Page View

Set up additional pages

Set up page navigation

Additional CSS

Page 41: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multi Page View

Page 42: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multi Page View

Page 43: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multi Page app – Page 2 HTML

Page 44: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multi Page app – Page 2 HTML

Page 45: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multi Page app – Page 2 HTML

Page 46: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multi Page app – Page 2 HTML

Page 47: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multi Page app – Page 2 CSS

Page 48: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Andy Gup

Multi-page map app

Page 49: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Page Transitions & Orientation Change

• Page and Orientation life cycle

• Map destruction and resizing

Use jQueryHelper.js!https://github.com/Esri/quickstart-map-phonegaphttps://github.com/Esri/jquery-mobile-map-js

Page 50: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Page Transitions

Page 1 Page 2

~250 ms

Page 51: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Events: leaving page

pagebeforechangepagechangepagechangefailed

http://api.jquerymobile.com/category/events/

Page 52: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Events: entering page

pagebeforeshow

pageshow

pagechangefailed

http://api.jquerymobile.com/category/events/

Page 53: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Page Transitions & Orientation Change

Page 1 Page 2 Page 2

Page 54: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

The following won’t work in all use cases:

map.reposition();map.resize();

Page 55: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,
Page 56: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,
Page 57: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Use Case - Recenter the map

Page 58: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

jQuery Helper library

Page rotation – landscape/portraitAuto-recenteringMultiple views

var helper = new jQueryHelper(map);

https://github.com/Esri/jquery-mobile-map-jshttps://github.com/Esri/quickstart-map-phonegap

Page 59: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Auto-recenter after orientation change

Page 60: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Multiple page app – Map Life CycleListen for “helper-map-loaded” event

Page 61: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Putting it all togetherPhoneGap + jQuery + ArcGIS

Andy Gup

Page 62: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Andy Gup

Quickstart-map-phonegap

Page 63: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

JavaScript API Web Optimizer

http://jso.arcgis.comCreates a single fileCDN hosted or downloadCustom modules

Optimizer session – Thurs 10am, Primrose B!- Optimizing your JavaScript app performance

Page 64: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Andy Gup

ArcGIS Web Optimizer

jso.arcgis.com

Page 65: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Going Offline with JavaScript

Mobile web map used in areas of intermittent or no internet

Ability to reload or restart web map in areas of intermittent or no internet

Lightweight cross-browser functionality

Github.com/esri/Offline-editor-js (Experimental)

Page 66: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Want a full feature, robus offline solution?

ArcGIS Runtimes for iOS, Android, Qt and .NET!

Includes integrated support for offline editing and synchronization.

Offline routing!

Fully supports related tables, sub-types, domains and much more.

Page 67: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

What does offline JavaScript mean?

Take map tiles offlineStoring/syncing feature editsLimited storing/syncing attachmentsView TPKs

These work in browser and with PhoneGap!

Page 68: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

What does offline JavaScript mean?

How much storage?- Limited by the browser!- Depends on device- How many browser tabs open- ~100MB to 500MB

Runtimes can store much more data!

Page 69: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Offline Demos

Page 70: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Working with GPS

Exact same Geolocation APISame coding pattern!

May require geolocation plugin

Page 71: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

$ plugman search geolocation

Page 72: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Does it use device GPS

Yes!! …but it depends.

If GPS is enabledMay also use WiFi and cell triangulation

Page 73: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Working with GPS

Page 74: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Recap!

Install Cordova command lineUse jQuery Mobile for AppStore/Google PlayOn github.com/esri > PhoneGap & jQueryWorks with GeolocationLimited offline tiles and feature support

Page 75: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Rate This Sessionwww.esri.com/RateMyDevSummitSession

Page 76: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,

Questions?

Andy GupDeveloper Evangelist [email protected]@agup

Lloyd HeberlieJavaScript API [email protected]@lheberlie

Page 77: ArcGIS API for JavaScript: Building Native Apps using PhoneGap … · 2015-04-24 · •Application container technology • Core engine is 100% open source • Web view container,