52
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

Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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 2: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Who are your presenters?

Antoon Uijtdehaag, Esri NederlandTechnical Consultant

Email: [email protected] @uijtdehaag

Andy Gup, EsriTech Lead for Web APIs and AndroidEsri Developer Network

Email: [email protected] Twitter: @agup

Page 3: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Who are you?

Page 4: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Why mobile?

Page 5: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Demo

Page 6: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Mobile usage stats for my website?

Web Server logs

Web analytic tools

Page 7: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Sample web-site stats from esri.com

Page 8: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Your 3 Approaches

Web app+

Native mobile app

Web app+

Web mobile app(a.k.a Hybrid)

Web app only(Responsive)

1.

2.

3.

Page 9: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Many different screen sizes and pixel densities

1920x1080

Page 10: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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

Page 11: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Hmmm…how many map layers do I load?

VS.

1 GB RAM 16 GB RAM

Page 12: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

How come my map loads so slooow?

VS.

Mostly connected Always connected

Page 13: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

My survey crews use GPS heavily…

VS.

Limited battery Unlimited power

Page 14: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

resources.arcgis.com

1440 x 900 480 x 800 hdpi

Page 15: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Portrait Landscape

Mobile app – flip view port easily

Page 16: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Desktop app on smartphone

Page 17: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

ArcGIS API for JavaScript - Compact

http://esriurl.com/compactJS

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

Page 18: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Why use the compact library?

Compact

Full

Size Latency

32 modules vs. 80 modules

Page 19: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

The challengeMany mobile frameworks, such as…

Page 20: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Mobile frameworks help with…

Views

Visual Components

Themes

Page 21: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Views

Image courtesy Dojo

Page 22: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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 23: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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 24: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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 25: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

The view port

Page 26: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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

scalable=no"/>

Setting the mobile view port

Page 27: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

<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 28: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

No viewport With viewport

Page 29: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Map touch events

No Change!

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

Page 30: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Styling via resolution & rotation

CSS3 Media Queries

Page 31: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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 32: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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 33: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Responsive Frameworks…(partial list)

Boostrap

Less Framework 4

Foundation 3

Skeleton

Less+

jQuery

The Boiler

Wirefy

Susy

Titan

Ingrid

Page 34: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

DemoPutting it all together

Page 35: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Hybrid Web Apps

Wrap your app with native framework. Deploy to multiple platforms!

Page 36: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Hybrid Web Apps

Page 37: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Hybrid Web Apps

Direct access to:

GPS

Camera

Storage

Notification

Page 38: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Examples of Hybrid Web Apps

http://www.phonegap.com/app

???

Page 39: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

build.phonegap.com

Page 40: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

DemoPhonegap build

Page 41: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

HTML5

HTML + CSS3 + JavaScript

HTML5 Logo by W3C

Page 42: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

• 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 43: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

• 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 44: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

• Provides user’s approximate location

• Opt-in only!

navigator.geolocation.getCurrentPosition( zoomToLocation, locationError);

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

Geolocation API

Page 45: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Geolocation API

Page 46: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Understanding browsers

!= !=

Page 47: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

caniuse.com

Page 48: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

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 49: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Test on different devices

Page 50: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag
Page 51: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag

Antoon Uijtdehaag, Esri NederlandTechnisch Consultant

[email protected]@esrinederland

Andy Gup, EsriTech Lead for Web APIs and AndroidEsri Developer Network

[email protected] http://blog.andygup.net @agup

Page 52: Building mobile apps with the ArcGIS api for Javascript, Esri, Andy Gup and Antoon Uijtdehaag