Exercise: Creating a Mobile Demographic Viewing Application

Similar documents
Final Project: Integrating ArcGIS Server with Google Maps Creating a Southern California Wildfire Mapping Application

Basic Steps for Creating an Application with the ArcGIS Server API for JavaScript

Chapter 8: Using Toolbars

GNAHRGIS MAP MIGRATION

In this exercise you will display the Geo-tagged Wikipedia Articles Fusion Table in Google Maps.

No Programming Required Create web apps rapidly with Web AppBuilder for ArcGIS

US Geo-Explorer User s Guide. Web:

(1) How can I use SimplyMap to determine the top PRIZM Segments in my neighborhood?

Lesson 2 - Analyzing Census Data Using USA Demographics for Schools

Geography 281 Mapmaking with GIS Project One: Exploring the ArcMap Environment

Geography 281 Mapmaking with GIS Project One: Exploring the ArcMap Environment

Downloading shapefiles and using essential ArcMap tools

Creating Effective School and PTA Websites. Sam Farnsworth Utah PTA Technology Specialist

Advanced Dreamweaver CS6

Developing Web Applications for Smartphones with IBM WebSphere Portlet Factory 7.0

Guide to Mapping Website (Public) December 2016 GC_236594

Lab 1: Getting Started with IBM Worklight Lab Exercise

Week 8 Google Maps. This week you ll learn how to embed a Google Map into a web page and add custom markers with custom labels.

Introduction to GIS & Mapping: ArcGIS Desktop

John W. Jacobs Technology Center 450 Exton Square Parkway Exton, PA Introduction to

Important installation note Back to Top. Homepage Overview Back to Top

Dashboards. Overview. Overview, page 1 Dashboard Actions, page 2 Add Widgets to Dashboard, page 4 Run a Report from the Dashboard, page 6

GeoLytics. User Guide. Online Demographic Database

Add to the ArcMap layout the Census dataset which are located in your Census folder.

Office of Geographic Information Systems

SAMPLE CHAPTER. Rene Rubalcava MANNING

Rocket Theme. User Guide

[PACKT] HTML5, CSS3, and jquery. Dreamweaver CS5.5 Mobile. and Web Development with

John W. Jacobs Technology Center 450 Exton Square Parkway Exton, PA Introduction to

Chapter 20: Basic Application Design with Dojo and ArcGIS Templates

ACA Dreamweaver Exam Notes

Using Reports. Access 2013 Unit D. Property of Cengage Learning. Unit Objectives. Files You Will Need

Adobe Dreamweaver CS6 Digital Classroom

Configuring Ad hoc Reporting. Version: 16.0

Advanced Development with the ArcGIS API for JavaScript. Jeremy Bartley, Kelly Hutchins, Derek Swingley

Drupal Cloud Getting Started Guide Creating a Lab site with the MIT DLC Theme

Intellicus Enterprise Reporting and BI Platform

Welcome to Book Display Widgets

E-Business Systems 1 INTE2047 Lab Exercises. Lab 5 Valid HTML, Home Page & Editor Tables

Developing Apps for the BlackBerry PlayBook

Mobile Application Development

Connecture Platform Manager

GIS Basics for Urban Studies

MAP ASPEN Training Manual. Navigate back to City of Aspen Home, GIS Home, Map Aspen Home or the Data Catalog from any page in the site.

INTERACTIVE MAP TUTORIAL

~Arwa Theme~ HTML5 & CSS3 Theme. By ActiveAxon

Using Dreamweaver CS6

ArcGIS API for JavaScript Advanced Topics

Data Visualization Techniques with Google Earth

Ace Corporate Documentation

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

Geography 281 Map Making with GIS Project Three: Viewing Data Spatially

Geocoding Reference USA data in ArcMap 9.3

ArcGIS Online Tutorial

Things to note: Each week Xampp will need to be installed. Xampp is Windows software, similar software is available for Mac, called Mamp.

WEBSITE INSTRUCTIONS. Table of Contents

Assignment #3 CSCI 201 Spring % of course grade Title Weathermeister Back-End API Integration

Technical Product Overview. This guide provides an overview of the DocuNECT v4.8 Product, a solution for Electronic Document Management.

1. Start ArcMap by going to the Start menu > All Programs > ArcGIS > ArcMap.

Google Map for Magento 2

Welcome to Book Display Widgets

Interactive Maps Purpose: Login to the System: Interactive Maps ONTINUE AGREE

Using an ArcGIS Server.Net version 10

Web Development. With PHP. Web Development With PHP

Chapter 6. Building Maps with ArcGIS Online

Readme for the JQueryMobile Tagset

ImageNow Interact for Esri ArcGIS Server for Silverlight Getting Started Guide

WEBSITE INSTRUCTIONS

SAW Stand-alone Application for Web GIS Configuration and Deployment. PhD. Bogdan Cheveresan Esri Romania

Quick Start Guide - Contents. Opening Word Locating Big Lottery Fund Templates The Word 2013 Screen... 3

Mapping 2001 Census Data Using ArcView 3.3

Guidelines for doing the short exercises

Mn/DOT MnCMAT Crash Analysis Application Help

Intro to GIS (requirements: basic Windows computer skills and a flash drive)

GEOCORTEX INTERNET MAPPING FRAMEWORK VERSION RELEASE NOTES

Using analytical tools in ArcGIS Online to determine where populations vulnerable to flooding and landslides exist in Boulder County, Colorado.

Widget ID Each user type widget should have a unique identifier within a single controller (ID). Any string can be as ID.

Geographical Information Systems Institute. Center for Geographic Analysis, Harvard University. LAB EXERCISE 1: Basic Mapping in ArcMap

Challenge: Working with the MIS2402 Template

SSJS Server-Side JavaScript WAF Wakanda Ajax Framework

Introduction to ArcGIS Desktop

SIX REASONS. You Should Use ArcGIS API 4.0 for JavaScript. By Julie Powell, Esri Product Management

20480B - Version: 1. Programming in HTML5 with JavaScript and CSS3

Web AppBuilder for ArcGIS Dive Into Mobile Development. Yiwei Ma & Kevin Gao

BindTuning Installations Instructions, Setup Guide. Invent Setup Guide

Geographical Information Systems Institute. Center for Geographic Analysis, Harvard University

Node-RED dashboard User Manual Getting started

Getting Started with ArcGIS Background and Introduction

Guides. Tutorial: A Node-RED dashboard using node-re... dashboard. What is Node RED? 1 of 9 7/29/17, 9:27 AM

-In windows explorer navigate to your Exercise_4 folder and right-click the DEC_10_SF1_P1.csv file and choose Open With > Notepad.

Introduction. Part I: jquery API 1. Chapter 1: Introduction to jquery 3

Using Dreamweaver CC. Logo. 4 Creating a Template. Page Heading. Page content in this area. About Us Gallery Ordering Contact Us Links

Reporting. Guide: Variable. nightly.

GEO 425: SPRING 2012 LAB 9: Introduction to Postgresql and SQL

Using Dreamweaver CC. 6 Styles in Websites. Exercise 1 Linked Styles vs Embedded Styles

Rev. C 11/09/2010 Downers Grove Public Library Page 1 of 41

QGIS LAB SERIES GST 102: Spatial Analysis Lab 3: Advanced Attributes and Spatial Queries for Data Exploration

PCC Local File Viewer User Guide. Version /23/2015 Copyright 2015

IBM TRIRIGA Application Platform Version 3 Release 4.0. Connector User Guide

Tutorial 1: Finding and Displaying Spatial Data Using ArcGIS

Transcription:

Exercise: Creating a Mobile Demographic Viewing Application In this exercise you will combine what you have learned about the ArcGIS Server API for JavaScript, the Geolocation API, and jquery Mobile to build a mobile demographic viewing application. The end result should look similar to the images you see below. The application will use the Geolocation API to determine the current location of the mobile device. Using this point coordinate you will use the ArcGIS Server API for JavaScript to query a demographic service and pull various pieces of demographic information including population per square mile, median age, average household size, and average family size. This information will be written to a Report page within the application.

Step 1: Open the Exercise File Navigate to the C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lab\mobile\exercises\demographics folder and open index.htm in your favorite HTML or text editor. We have pre-written only the code that imports the jquery and AGIS API for JavaScript libraries along with a small amount of CSS styling.

Step 2: Create the User Interface For this mobile application we are going to create two pages and various widgets for each page. The initial page will contain a header with a title and refresh button, the map, and footer that functions as a navigation toolbar. The report page will contain slider widgets that we use to display demographic information about the current location of the device. First we ll create the initial page of the application. As I mentioned, this page will contain a header, map, and navigation bar for the footer. In the body tag, add the following code block. This code block create the page and adds a header. The code highlighted in yellow represents the page and the green highlighted code the header. Note that we ve given our header a title of Search, defined with an <h3> tag. We also want our header to include a Refresh button that gives the user the ability to refresh the map and demographic information when they have changed location. There are more sophisticated ways of doing this through events on the Geolocation API that will periodically update the location of a mobile device, but this will be suffice for now. Add the following line of code to your header. This line of code will add a button without text. This is accomplished using the dataiconpos= notext role along with the provided refresh icon defined by the dataicon= refresh role.

Now create the content role which will contain the map. Create the structure for the footer. We want the footer to act as a navigation bar so we ll now add a new <div> with a datarole= navbar.

Next we ll add the buttons that will be part of the navigation bar. I ll point out a few things about these buttons. First, they re each defined as <a> link buttons within a <li> element rather than actual button widgets. Each button will contain both text and an icon. For instance, the Search button also has a search icon defined with the data-icon role. Finally, we ve defined that the Search button should also be active initially by assigning it the ui-btn-active class. What this does is change the background color of the button (see below). That s it for the initial page of the application. Next we ll define the interface for the Report page. We re not going to define content for the Settings page in this exercise, but the content could contain a number of items such as the location accuracy, demographic level, and others. Below the closing <div> tag for the initial page define a new page with the code block you see below.

Just as we saw with the initial application page, the Report page is defined with a datarole= page and we ve included a header with a title. The Report page is going to contain a handful of slider widgets which will be used to display demographic information about the current location of the mobile device. You can see a screen shot of these widgets below. Create the Population Per Square Mile widget with the code block below. Each widget will also contain a label which is tied to the widget through the unique identifier of the widget. For instance, this slider has an id of popsqmi. The <label> tag has a property called for which is set equal to popsqmi. This ties the two together. The slider

widget is created using an <input type= range > tag. Each slider has several attributes that can be set including min, max, value, and data-theme. For this particular slider you will need to define a minimum value of 0 and a maximum value of 10000. These numbers will vary depending upon your data so you ll need to get to know your data pretty well before defining them. The initial value of this widget is set to 0. After the application has defined the location of the mobile device and queried the demographic service it will be updated with the new information. Finally, to add some styling we define a data-theme= e which gives our slider the blue/yellow combination. Add the label and slider widgets for each of the other demographic variable we intend to display. The final thing we need to do in this step is add an orientationchange event to the <body> tag. This will trigger a JavaScript function to resize and reposition the map when the user changes the orientation of the mobile device from portrait to landscape or visa versa. Add the following code to your <body> tag. Step 3: JavaScript Code to Handle Map Creation and Geolocation At this point we have a user interface for our application but it doesn t do anything. In this step you ll create a basemap for the application and use the HTML5 Geolocation API to locate the mobile device. Create a new <script> tag and import the ESRI map resource. The map resource, as you ll remember from the ArcGIS Server API for JavaScript section of the course, is needed to

create a map. Add the code you see highlighted below. Add the dojo.addonload() event which will call the init function that we ll create next. Create the stub for the init function. Create the map, set the initial map extent, and add a base map layer. Note: The line of code that creates the streetmaplayer variable can be a single line of code. I ve just broken it into two lines to improve the readability.

The initial extent that we ve set for the map will be used in the event that the end user doesn t want to share the location of the mobile device. That of course would defeat the purpose of the application, but we need some sort of fallback in case this happens.

Add code to use the Geolocation API to determine the current position of the mobile device. The getcurrentposition() method will determine the current location of the mobile device. If the location can be determined it is passed to the success callback function which in this case is called zoomtolocation(). We will create this function in the next step. If there is an error of some sort in the attempt to determine the location then the locationerror() function will be called. We ll create that function soon as well. Create the zoomtolocation() function seen below and then we ll discuss what this code does. The zoomtolocation() function is passed a location object (highlighted in yellow below). This object contains various objects and properties. For example, you can obtain the latitude/longitude coordinates of the location by accessing the longitude and latitude properties on the Coordinate object (highlighted in green below).

These coordinates are used in the creation of a new Point object from the AGIS API for JavaScript. You ll also notice that the first line of code in this function creates a new PictureMarkerSymbol object from a bluedot.png file that has been included in the images folder for this particular application. After the point and symbol objects have been created a new Graphic object is created from these objects and it is added to the GraphicsLayer of the map. Finally, the map is centered and zoomed to the location of the mobile device. Create the locationerror() function to handle any problems with the geolocation request. Step 4: Query the Demographic Service Now that we have the location of the mobile device we can query a demographics service that contains information for various levels of geography including census block group, census tract, county, and state. We re going to use the lowest level possible (block group) since we should have a pretty accurate determination of the mobile device. You can examine the service that we ll use for our query at: http://sampleserver1.arcgisonline.com/arcgis/rest/services/demographics/esri_census_usa/mapserv er/1 Add a the QueryTask resource.

Add variables for the Query and QueryTask objects. Inside the init() function create a QueryTask object that references the demographic service. Build the query filter. There are several attribute fields from our block groups layer that we re going to use. They include population per square mile, median age, average household size, and average family size. These are indicated in the outfields property. Note: We ll add the query.geometry property in the zoomtolocation() function.

Add the Geolocation point to the query object. This will be inside the zoomtolocation() function. Next we ll create a new JavaScript function that executes the QueryTask using the Query object that we just created. Add the following function. In ZoomToLocation() add a call to this new JavaScript function. In the querytask.execute() method the second parameter passes in a callback function that will run when the query has finished executing. This callback function is called showresult (see below). The showresults() function is going to need to set a few variables that hold the demographic information that we want to pull from the demographic service. Add the following variables.

Create the showresults() function with the code block below. The variables that we created are being populated by the attributes pulled from the census block group intersected by the current location of the mobile device. The last thing that we need to do in this step is create the orientationchanged function to handle changes in orientation of the mobile device. Remember that we added an event handler for this in the <body> tag. Step 5: Add Global Options and Page Change Event Handler At this point we ve created the user interface and added JavaScript functions to handle location of the mobile device, query of the demographic service based on the location, and device orientation changes. There are still a couple things we need to do though. We still need to add a back button to our Reports and Settings pages. Rather than adding these buttons individually to each page you can set a global option variable that will add this button to all pages except the initial page. We also need to add a page change event handler for the Reports page. Remember that we initially assigned a value of 0 to all our sliders. These values need to be updated with the demographic information we queried from the demographic service. These attributes were assigned to variables in the showresults() function. So, we ll define an event handler that updates these values. Add a mobileinit event handler that adds the global back button. This event handler needs to be placed very specifically between the references to jquery and jquery Mobile. It needs access to the resources in jquery before it can be run. So, make sure you place the code block highlighted in yellow below between the library references highlighted in green.

What this code block does is create an event handler that runs after the mobile library has been initialized. It adds a back button and back button text to each page (not the initial page) through the use of global variables Finally, add an event handler for the page change event that refreshes the sliders with the new demographic information. Step 6: View the Application That s all there is to this particular application. We didn t define the Settings page for this particular exercise, but as I mentioned earlier you would add things like the geography level for the demographics, perhaps a location accuracy setting, and other items related to the application. Save the application and view it in your simulator. You can also view the completed application on an actual mobile device by going to: https://s3.amazonaws.com/virtualgisclassroom/buildingmobilearcgisserverapplications/d emos/demographics/index.htm Extra Work? If you d like to do some additional work on this application you could update the code to automatically update the demographic information at periodic intervals (say every 5 minutes). This would account for mobile devices that are currently in transit to other locations. To accomplish this task you could use the Geolocation APIs watchlocation() function and have it perform the query and update the contents of the report periodically. You could also investigate adding various properties to the Setting page.