3 approaches to mobile - an a to z primer

62
Building Mobile Applications with the ArcGIS API for JavaScript Andy Gup Esri Southwest User Conference September 17-19, 2012 | Denver, Colorado

Upload: agup2009

Post on 15-Jan-2015

756 views

Category:

Technology


3 download

DESCRIPTION

A must see A to Z mobile web primer. If you still only have one website built for desktop then you need to review this presentation. Examples are about mapping but the concepts apply to everyone!

TRANSCRIPT

Page 1: 3 Approaches to Mobile - An A to Z Primer

Building Mobile Applications with the ArcGIS API for JavaScript

Andy Gup

Esri Southwest User ConferenceSeptember 17-19, 2012 | Denver, Colorado

Page 2: 3 Approaches to Mobile - An A to Z Primer

Agenda

Goal: You’ll get an A to Z mobile web primer

Why build mobile map apps?

3 Approaches

Frameworks

CSS3 & HTML5

Hybrid Map apps

Page 3: 3 Approaches to Mobile - An A to Z Primer

Who am I?

Andy Gup, Esri

Tech Lead for Web APIs and Android

Esri Developer Network

Email: [email protected]

Twitter: @agup

Page 4: 3 Approaches to Mobile - An A to Z Primer

Who are you?

Page 5: 3 Approaches to Mobile - An A to Z Primer

Why mobile?

Page 6: 3 Approaches to Mobile - An A to Z Primer

Demo

Page 7: 3 Approaches to Mobile - An A to Z Primer
Page 8: 3 Approaches to Mobile - An A to Z Primer

X

Page 9: 3 Approaches to Mobile - An A to Z Primer
Page 10: 3 Approaches to Mobile - An A to Z Primer

Mobile usage stats for my website?

Web Server logs

Web analytic tools

Page 11: 3 Approaches to Mobile - An A to Z Primer

Sample web-site stats from esri.com

Page 12: 3 Approaches to Mobile - An A to Z Primer

Your 3 Approaches

Web app+

Native mobile app

Web app+

Web mobile app(a.k.a Hybrid)

Web app only

1.

2.

3.

Page 13: 3 Approaches to Mobile - An A to Z Primer

Many different screen sizes and pixel densities

1920x1080

Page 14: 3 Approaches to Mobile - An A to Z Primer

Wait…how do I pan and zoom the map??

Page 15: 3 Approaches to Mobile - An A to Z Primer

Hmmm…how many map layers do I load?

VS.

1 GB RAM 16 GB RAM

Page 16: 3 Approaches to Mobile - An A to Z Primer

How come my map loads so slooow?

VS.

Mostly connected Always connected

Page 17: 3 Approaches to Mobile - An A to Z Primer
Page 18: 3 Approaches to Mobile - An A to Z Primer

My survey crews use GPS heavily…

VS.

Limited battery Unlimited power

Page 19: 3 Approaches to Mobile - An A to Z Primer

arcgis.com

1440 x 900 480 x 800 hdpi

Page 20: 3 Approaches to Mobile - An A to Z Primer

resources.arcgis.com

1440 x 900 480 x 800 hdpi

Page 21: 3 Approaches to Mobile - An A to Z Primer

Portrait Landscape

Mobile app – flip view port easily

Page 22: 3 Approaches to Mobile - An A to Z Primer

Desktop app on smartphone

Page 23: 3 Approaches to Mobile - An A to Z Primer

ArcGIS API for JavaScript - Compact

http://esriurl.com/compactJS

<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.1compact">

Page 24: 3 Approaches to Mobile - An A to Z Primer

Library Size vs. Download vs. Parse

Compact

Full

Page 25: 3 Approaches to Mobile - An A to Z Primer

The challengeMany mobile frameworks, such as…

Page 26: 3 Approaches to Mobile - An A to Z Primer

Mobile frameworks help with…

Views

Visual Components

Themes

Page 27: 3 Approaches to Mobile - An A to Z Primer

Views

Image courtesy Dojo

Page 28: 3 Approaches to Mobile - An A to Z Primer

Views

<div id="mapView" dojoType="dojox.mobile.View“ style="width:100%;height:100%;"> <h1 dojoType="dojox.mobile.Heading" back="Back" moveTo="mainView"> 5 + 10 minute Drive Times </h1> <div id="map“ style="width:100%; height:100%;“/></div>

Easy!

Page 29: 3 Approaches to Mobile - An A to Z Primer

Visual Components

<div dojoType="dojox.charting.widget.Chart2D" theme="dojox.charting.themes.Claro" id="viewsChart" style="width: 550px; height: 550px;">

     <!-- Pie Chart: add the plot -->    <div class="plot" name="default" type="Pie"

radius="200" fontColor="#000" labelOffset="-20"></div>     <!-- pieData is the data source -->    <div class="series" name="Last Week's Visits" array="chartData"> </div> </div>

Page 30: 3 Approaches to Mobile - An A to Z Primer

Themes

  <!--Legend Dialog-->  <div data-role="dialog" id="legendDialog"   data-theme="f">    <div data-role="header">      <h1>Legend</h1>    </div>    <div data-role="content" >      <div id="legendDiv"></div>    </div>  </div>

Page 31: 3 Approaches to Mobile - An A to Z Primer

The view port

Page 32: 3 Approaches to Mobile - An A to Z Primer

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-

scalable=no"/>

Setting the mobile view port

Page 33: 3 Approaches to Mobile - An A to Z Primer

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-

scalable=no"/>

Setting the mobile view port

Minimum view port

Zoom level on page load

Force map to scale - not the page

Page 34: 3 Approaches to Mobile - An A to Z Primer

No viewport With viewport

Page 35: 3 Approaches to Mobile - An A to Z Primer

Map touch events

No Change!

function init() {        var map = new esri.Map(...);        dojo.connect(map, "onClick", myClickHandler);}

Page 36: 3 Approaches to Mobile - An A to Z Primer

Styling via resolution & rotation

CSS3 Media Queries

Page 37: 3 Approaches to Mobile - An A to Z Primer

CSS3 Media QueriesTarget specific devices by screen width

Apply styles by device orientation

Target high density screens such as iPhone 4

@media screen and (min-device-width:768px) and (max-device-width:1024px) {/* styles go here */}

@media (orientation: landscape) {/* styles go here */}

@media (-webkit-min-device-pixel-ratio: 2) {/* high resolution device styles go here */}

Page 38: 3 Approaches to Mobile - An A to Z Primer

Listen for device rotation

var supportsOrientationChange = "onorientationchange" in window,orientationEvent =

supportsOrientationChange ? "orientationchange" : "resize";

window.addEventListener(orientationEvent, dojo.hitch(this,function(){ //... TODO

this.orientationChanged = orientationChanged; }), false

);

Page 39: 3 Approaches to Mobile - An A to Z Primer

DemoPutting it all together

Page 40: 3 Approaches to Mobile - An A to Z Primer

Hybrid Web Apps

+

Android SDKJava Project

HTML + Mobile JavaScript

Framework

=

Page 41: 3 Approaches to Mobile - An A to Z Primer

Hybrid Web Apps

Page 42: 3 Approaches to Mobile - An A to Z Primer

Hybrid Web Apps

Direct access to:

GPS

Camera

SD Card

Page 43: 3 Approaches to Mobile - An A to Z Primer

Examples of Hybrid Web Apps

http://www.phonegap.com/app

???

Page 44: 3 Approaches to Mobile - An A to Z Primer

Hybrid Web App Platforms

Page 45: 3 Approaches to Mobile - An A to Z Primer

build.phonegap.com

Page 46: 3 Approaches to Mobile - An A to Z Primer

build.phonegap.com

Page 47: 3 Approaches to Mobile - An A to Z Primer

Scan the QR code to install

Page 48: 3 Approaches to Mobile - An A to Z Primer

Hello-World PhoneGap Map

Page 49: 3 Approaches to Mobile - An A to Z Primer
Page 50: 3 Approaches to Mobile - An A to Z Primer

Remote debugging

Page 51: 3 Approaches to Mobile - An A to Z Primer

HTML5

HTML + CSS3 + JavaScript

HTML5 Logo by W3C

Page 52: 3 Approaches to Mobile - An A to Z Primer

• Several new APIs

- Drag and drop API

- FileSystem API(s)

- Geolocation API

- Web Storage: localStorage/sessionStorage- Web Workers (threaded JavaScript!)

- Cross-Origin Resource Sharing (CORS)

- Browser History

HTML5 APIs

Page 53: 3 Approaches to Mobile - An A to Z Primer

• 5 MB limit vs. 4 KB per regular cookie

• Stores key/value pairs

• localStorage and sessionStorage

Web Storage API

// Put the object into storagelocalStorage.setItem(“address”, someAddress);

// Retrieve the object from storage var userAddress = localStorage.getItem(“address”);

// Save data to a the current session's store sessionStorage.setItem("username", "John");

// Access some stored data var userName = sessionStorage.getItem("username"));

Page 54: 3 Approaches to Mobile - An A to Z Primer

• Provides user’s approximate location

• Opt-in only!

navigator.geolocation.getCurrentPosition( zoomToLocation, locationError);

watchId = navigator.geolocation.watchPosition( updateLocation, locationError);

Geolocation API

Page 55: 3 Approaches to Mobile - An A to Z Primer

Geolocation API

Page 56: 3 Approaches to Mobile - An A to Z Primer

Understanding browsers

!= !=

Page 57: 3 Approaches to Mobile - An A to Z Primer

caniuse.com

Page 58: 3 Approaches to Mobile - An A to Z Primer

Feature detection pattern

useLocalStorage = supports_local_storage();

function supports_local_storage() { try { return 'localStorage' in window && window['localStorage'] !== null; } catch( e ){ return false; }}

function doSomething() { if(useLocalStorage == true){ //write to local storage } else {

//degrade gracefully }}

Page 59: 3 Approaches to Mobile - An A to Z Primer

Test on different devices

Page 60: 3 Approaches to Mobile - An A to Z Primer
Page 61: 3 Approaches to Mobile - An A to Z Primer

Andy Gup, Esri

Tech Lead for Web APIs and Android

Esri Developer Network

[email protected]

http://blog.andygup.net

@agup

Page 62: 3 Approaches to Mobile - An A to Z Primer