Chapter 1. GIS as a tool

This chapter covers

  • What a geographic information system (GIS) is and how it’s used
  • The significance of spatial applications
  • Trends for pros and opportunities for beginners
  • Parts of a GIS web application

Where we are, and our understanding of location, has an impact on our daily lives. Walk around almost any public space and you’ll see people staring at their smartphones, updating their statuses, or looking for the closest taco joint. You may have shopped for a house online, and been able to view homes in your area and even see nearby schools. When shopping for a car online, you can usually limit the search to within so many miles of a zip code. Formerly, a paper map book was essential in every vehicle, but today, drivers keep a GPS (Global Positioning System) on the dashboard or have a system that speaks to them, directing them when to turn. If you’re following directions on paper, chances are you printed them from an online map. Location has become a key component of the way we get many tasks done. A simple map can be a driving force in delivering information, sometimes in the most subtle ways. ArcGIS, a key subject of this book, is a geographic information system (GIS) platform that allows users to work with maps and geographic information. With it, users can create and use maps, gather and analyze geographic data, and use that data in a variety of applications.

This chapter gives you a quick overview of the key pieces of information in this book:

  • The ArcGIS platform
  • Why you should consider learning how to add spatial capabilities to your applications
  • Benefits of the ArcGIS API for JavaScript
  • Dojo Toolkit and how it relates to the ArcGIS API for JavaScript
  • Useful GIS concepts

Volumes have been written on the subject of GIS alone, but for our purposes, I’ll discuss what GIS means and how location-aware applications impact our daily lives.

1.1. GIS: here, there, everywhere

For years, GIS was something used by academics and government agencies for studies or infrastructure purposes. GIS is “a system designed to capture, store, manipulate, analyze, manage, and present all types of geographical data.”[1] GIS is the way we work with spatial information. It’s also a technology that’s been used mainly in the realm of desktop computers, with large enterprise applications that require extensive training.

1 “Geographic Information System,” Wikipedia, last modified May 24, 2014, http://en.wikipedia.org/wiki/Geographic_information_system.

The World Wide Web has caused an explosion in most technologies today, including the use of GIS tools. Since the mid-1990s, you’ve been able to find addresses and get directions from websites like MapQuest. Projects like Google Maps and OpenStreetMap emerged a few years later to bring GIS to the masses, introducing the power of maps to everyday people. Esri, founded in 1969, has grown into a leading company that provides GIS tools and services, including a suite of web mapping tools, which is why you’re reading this book. Before we take a closer look at Esri’s GIS offerings, let’s sample the other tools available.

1.1.1. The GIS tools landscape

You have a number of choices when it comes to developing web mapping applications with JavaScript, including robust open-source options. Some options come in the form of an API, which is an interface for an underlying web service, like maps and directions.

What exactly is a web service?

The World Wide Web Consortium (W3C) defines a web service as “a standard means of interoperating between different software applications, running on a variety of platforms and/or frameworks.”[a]

a “Web services Architecture,” W3C Web Services Architecture Working Group, last modified Feb 2004, www.w3.org/TR/ws-arch/

Google and MapQuest provide web mapping APIs that are popular for embedding maps and directions into websites. Microsoft offers a Bing mapping API to showcase its mapping data. Various open-source mapping libraries also have much to offer:

  • OpenLayers— A popular open-source mapping library with a large community of users
  • Leaflet— A mapping library that has grown in popularity due to its ease of use and focus on performance for mobile browsers
  • Modest Maps— A super-lightweight mapping library that does a good job of displaying interactive maps

This list is a sampling of open-source options for building web mapping applications, and I encourage you to try them out. The explosion of mapping in the browser has only increased the importance of location for everyday users. Personally, when I’m out running errands, my phone keeps me updated as to how long it’ll take me to get home based on my current location and traffic conditions. That’s pure location-awareness in action.

GIS plays a large role in many areas of technology. Knowing the location of something can be critical in large asset-management systems that track construction and maintenance information of certain infrastructures, such as water and power. GIS is commonly used in crime analyses to help local law enforcement officials focus their resources. GIS is also used to project population growth in urban areas to help determine future infrastructure needs. GIS is used to assist the public when a disaster strikes—for example, mapping out damage after storms and floods.

Considering the various web mapping APIs available to developers other than the ArcGIS API for JavaScript, such as OpenLayers and Leaflet, you wonder which is the better choice: proprietary or open source. This decision may depend on many factors but usually boils down to preference. Are you working with data stored in an existing ArcGIS database? Are you working with services in an existing ArcGIS Server? Is the entire GIS ecosystem being built from scratch? What is the budget? Are there any regulatory guidelines on vendors? Do you require on-call customer support? There are varying advantages and disadvantages to each choice. A few of these pros and cons are listed in table 1.1.

Table 1.1. Pros and cons of proprietary and open-source web mapping
 

Proprietary

Open-source

Cost Infrastructure can get expensive, but API is cost-free Infrastructure and API are cost-free
Community support Available in Esri forums Quite extensive
Professional support Available with ArcGIS licensing Can be purchased from various providers

Like most open-source debates, the question of whether to use a proprietary or open-source web mapping API can get heated. In my experience, it usually boils down to what’s currently in place and what you’re willing to spend to get something done quickly. This book assumes that you, as a developer, are working with ArcGIS Server or ArcGIS Online services, so it makes sense for you to work with the ArcGIS API for JavaScript. This API isn’t an open-source toolkit, but rather was developed by Esri, a leader in GIS technologies. It’s a powerful library built to interact with ArcGIS Server.

1.1.2. Introducing the ArcGIS platform

ArcGIS is a platform for providing location-based tools and functionality that range from desktop to server and mobile. The ArcGIS API for JavaScript works with ArcGIS Server, a gateway to GIS data that can be shared on the web to provide access to GIS data via web services. I’ll discuss these services in more detail in chapter 2, but for now, all you need to know is that the ArcGIS API for JavaScript is designed to interact with those services so you can build powerful web mapping applications.

Tip

Before I get into the details of the ArcGIS API for JavaScript, you may want to visit http://esriurl.com/js for a quick overview of the code samples and reference materials. This book doesn’t regurgitate the documentation, but the documentation is the source material for the API and will be a key source of information in your exploration of the ArcGIS API for JavaScript.

The ArcGIS API for JavaScript is a natural choice if you’re working with ArcGIS Server. The JavaScript API seamlessly translates the information from ArcGIS Server to provide a rich web mapping experience. Figure 1.1 shows how GIS data that previously was accessible only to a few users can now be shared using ArcGIS Server and the ArcGIS API for JavaScript.

Figure 1.1. Producing maps with ArcGIS API for JavaScript

The purpose of this book is to introduce you to the basics of the ArcGIS API for JavaScript and how use the API to interact with various ArcGIS services. You’ll also look at how to interact directly with ArcGIS Server if you need information that you can’t easily use the API for, and you’ll learn how to extend the API to build your own tools to meet your needs.

The second half of the book covers how to build a more involved web mapping application that collects data in a field application. The term “field,” in this context, means “not behind a desk.” Field applications present their own unique challenges, which I’ll cover in later chapters.

Note

I’ll cover aspects of how to use ArcGIS Server services with the API, but I won’t cover how to install ArcGIS Server (which isn’t required for this book), publish services, or create services using ArcGIS for Desktop.

A look ahead

In chapter 4, you’ll set up a free ArcGIS developer account so you can create your own services for use in your application. You’ll also use free services from ArcGIS Online, a cloud-based version of ArcGIS Server.

For now, let’s broaden the discussion to talk more about what spatial applications are and how the internet has changed what you expect from these applications. As developers (beginner or advanced), what does GIS bring to the table and why should you care?

1.1.3. Why care about spatial applications?

My first car was small, it was old, and it was rusty, but it was mine, and I was excited to have my own ride to school, something that I think my parents were excited about as well. The first thing my father gave me when I got my car, after a brief yet stern word of caution about being a safe driver, was an awkward and heavy map book. As a kid, I remember sitting in the backseat of the car on long road trips, and my duty was to periodically flip the pages of an identical map book and point out what town was coming up or how many streets we needed to pass before making a right turn. I used to marvel at the detail each page provided, from the winding roads we’d already traveled to the upcoming hills I could look forward to. The map book was a staple in my travels as well as the travels of many others.

These days you may not rely on spiral-bound bricks of paper to navigate the road, but many people do rely on GPS, either on a smartphone or in the car. If you’re using a paper map, you probably printed it from a website and folded it up in your pocket for later use.

Navigation isn’t the only way our information-consuming society uses spatial information in our daily lives. For years, the retail industry has used your location for targeted advertising. From something as simple as the paper advertisements that fill your mailbox, to an application on your smartphone that can give you a coupon for a nearby restaurant without your asking for it, location can be a key component to targeting an audience in a meaningful way. We constantly share messages, photos, and videos via mobile devices, and each of these bits of information we share carry with them location information. You can even play games on your smartphone that interact with your location, using real-world streets to direct you to victory. When a new fast-food restaurant is built, time has been put into analyzing the benefits of placing that restaurant at that location. A study was probably done to review the demographics of the area (for example, the average household income), proximity to freeways or major highways, average drive-time from major business areas, and more. Similar analyses are also done when new schools are built or new roads are paved. At the end of the day, location matters.

1.1.4. Trends in the GIS industry

Previously, people who worked in the GIS industry needed the skills not only to analyze data but also to employ cartography to display that data. Today, GIS professionals are typically required to have an expanded skillset that allows them to adapt to challenges they face, but they don’t need to be versed in all aspects of using GIS. Professionals who prefer to focus on one particular aspect of GIS may not have masterful cartographic skills, rock-star spatial analysis skills, or ninja-level developer skills, but familiarity with all these skillsets is helpful. You may already be working in the GIS field or you may be a student looking forward to cutting your teeth in the job market. Or you may already have experience working with web applications and JavaScript and want to expand your skillset with a web mapping API. Whatever the case, anyone with a skillset in building location-based web applications can find many opportunities.

A cursory review of recent GIS-related job postings reveals that employers are looking for employees who not only can analyze and work with data, but also have programming knowledge. Programming skills could include a language like Python, which has cemented itself in the GIS industry as a staple in automating GIS analysis, thanks to some robust spatial libraries. Skills could also include languages like C# or Java, which are typically used to extend desktop tools or build web services. Employers also need current GIS professionals and developers who can use web technologies to provide quick and efficient access to much of the GIS data that has traditionally been inaccessible to the general public.

The web development aspect of using GIS is an exciting area not only for GIS professionals but also for anyone learning web development with maps. I started working with GIS in early 2002 as a drafting technician recruited into doing GIS technician work to help out with various projects. One of my tasks was manually adjusting hundreds of small boundaries. It was tedious, and I was unfamiliar with the tools, which at that time ranged from somewhat familiar drawing tools to some odd command-line tasks. I was asked to edit script files that added new menus to the software I used, which magically searched a database for related information. I was still green and didn’t realize the power of the automation I was working with. Today, a majority of my time is spent doing GIS web development. I attend regular GIS conferences and local events, and over the years I’ve noticed the growing need for GIS professionals to have a basic understanding of programming to get daily tasks done. I’ve seen presentations that include not only the analytic details of the way a project was completed but also the customizations that were done via programming tasks that were critical in completing the project. These customizations could be automating tasks or developing a web application to allow stakeholders to collaborate during the project lifecycle.

The goal of this book is to give you a solid working foundation in using the ArcGIS API for JavaScript to build web applications that meet the needs of the task at hand. This could be an application that’s used by first responders during a natural disaster or a work-order application to keep track of work that’s being done. A web application can be used in an office setting or on mobile devices, making it a flexible platform to work on.

Let’s shift our focus to the structure of a GIS web mapping application.

1.2. Understanding the GIS bits

Various components contribute to building a web mapping application. Each one is critical to the process. As shown in figure 1.2, all these components ultimately lead to one thing: a happy user, which means the data is communicated in a clear manner and provides meaning to the user.

Figure 1.2. The pieces that make up a web mapping application

The GIS data is behind the ArcGIS Server. To get to this data, you communicate with the ArcGIS Server via a collection of URL endpoints. You can communicate with these endpoints through a variety of methods, such as Silverlight and Flex, but this book’s focus is on the ArcGIS API for JavaScript. This communication process, combined with your impeccable skills, leads to happy users. This is method of communication is called a REST API, which is discussed in more detail in section 1.2.2.

In this section, I’ll introduce you to each of these components of building a web mapping application, starting with the key component: the data.

1.2.1. The what and the where of GIS data

Data is the starting point to a successful application. Someone has to compile the data, possibly analyzing and even digitizing (the process of using drawing tools) the data based on external sources. For example, a company or government agency will need to translate old, hand-drawn maps into a digital format, usually parcel or park boundaries. The data often is drawn based on aerial images, such as locations of trees or possible routes to navigate to areas without road access. Infrared aerials frequently are used to find vegetation, which appears in hues of red in an infrared image. This method is used to look at the way areas of vegetation change over a certain period of time. Without data, you’d have nothing to display in a web mapping application.

This data can be stored in a few formats but usually resides in a database. Regardless of format, it’s still data, and it’s easier to manage a lot of data when it’s kept in a database. This allows it to be searched quickly, backed up, and shared easily. To share this data, you could print out paper maps or you could email it back and forth in a digital format. Although these are still valid methods of sharing digital GIS data, users expect to have quicker and easier access to this type of information (see figure 1.3). This is where the need to share this data to the web comes into play.

Figure 1.3. ArcGIS Server provides access to GIS data, which is composed of different types of data, such as tabular, vector, terrain, streets, communities, and so on, via services.

With a wealth of valuable data to be shared, the next critical component of a web mapping application is a web server.

1.2.2. Serving GIS data: ArcGIS Server and the REST API

A web server’s job, as you may already know, is to serve data from a physical computer out to the World Wide Web so people can view it in their web browsers. An ArcGIS-specific server performs specialized tasks, such as serving aerial imagery, which I’ll cover briefly in chapter 2. Sharing data online is done through web services. A web service is a URL (pronounced U-R-L) that returns a web page, an image, or another form of data. This book focuses on data that’s accessed via ArcGIS Server services.

ArcGIS Server is enterprise server software that provides a quick method to build web services that serve GIS data. It has more functionality than merely serving data, which I’ll cover in later chapters, but all interaction is done through the REST (representational state transfer) API, which is an interface for interacting with the server (see figure 1.4).

Figure 1.4. Data served via ArcGIS Server is made available as various services; each service has a specific purpose.

To properly communicate with the ArcGIS Server REST API, you use a specially designed web API—the next component of a web mapping application.

1.2.3. Choosing an ArcGIS web API

The ArcGIS Server REST API is the foundation for all ArcGIS web APIs. A developer has a few choices when deciding to build a web application based on ArcGIS technology:

  • ArcGIS API for Flex
  • ArcGIS API for Silverlight
  • ArcGIS API for JavaScript
  • and others

The ArcGIS API for Flex, based on the Flex software development kit (SDK), used to be an Adobe product but has been open-sourced in recent years. It’s built on top of Flash technology and can be used to build interactive applications. The ArcGIS API for Silverlight uses Microsoft Silverlight to build applications that, similar to the Flex API, can provide fluid and interactive applications.

The drawbacks to both of these APIs are that they require users to have a browser plug-in installed for each of them, and they don’t work on the web browsers in mobile devices. This has led many developers to embrace the ArcGIS API for JavaScript. JavaScript runs on all browsers, with minor differences in the way it runs on each browser, and it also provides a fluid and interactive application.

All these web APIs are translators for the ArcGIS REST API, and they make it easy to interact with ArcGIS Server to provide data-rich web mapping applications (see figure 1.5). The web APIs may be built on different technologies, but once you learn one API, it’s easy to pick up another one without much trouble.

Figure 1.5. The ArcGIS API for JavaScript is the only API that doesn’t require a browser plug-in.

The ultimate goal of these various components is to make the user of the application happy. Providing an easy-to-use web mapping application that delivers the necessary data for the user to accomplish a task or find the right information without stumbling through the application is the key to a happy user.

Whether you’re a seasoned GIS pro looking to enhance your skills with JavaScript or a JavaScript ninja who wants to add GIS web mapping notches to your belt, you’ll want to be familiar with a few items before working with the ArcGIS API for JavaScript.

1.3. Things to know

No matter your level of competence in either GIS or JavaScript, you should know a few things before working with the ArcGIS API for JavaScript. I’ll cover the following topics in detail in chapters 2 and 3, but I want to touch on them briefly in this section to give you an overview of what you’ll need to know to work with the ArcGIS API:

  • JavaScript stylistics
  • GIS concepts

1.3.1. JavaScript, Dojo Toolkit, and Dijit

This book is about using JavaScript to build web mapping applications, but you don’t need to be a JavaScript master to use this book. I don’t explicitly cover what I consider JavaScript best practices when building your applications, but the code I provide is written in a style I think is best suited for the task at hand. For example, sometimes you use a single JavaScript file to build an application; other times, you load up to half a dozen JavaScript files.

Dojo and AMD loading

The Dojo Toolkit is a popular JavaScript library that offers many tools for writing JavaScript, in particular for larger applications. The ArcGIS API for JavaScript is based on Dojo, so it’s inevitable that you’ll also learn Dojo as you begin using the API. Dojo provides an extensive suite of tools that you can use in building your web mapping applications. I’ll dig deeper into Dojo tools in chapters 2 and 3, but Dojo’s use and how it applies to the ArcGIS API for JavaScript is something you should be aware of.

Another typical JavaScript stylistic choice is the way files are loaded. A common and still acceptable way to load JavaScript files to your web page is to use a <script> tag, as follows:

<script src="file1.js"></script>
<script src="file2.js"></script>
<script src="file3.js"></script>

Loading JavaScript files in this manner isn’t wrong, and you need at least one script tag to load a file. But, as you can imagine, as the application grows and the amount of JavaScript files grow, this method gets unwieldy. Not to mention that there’s no guarantee that the JavaScript files will load in the order in which you place them on the page.

The ArcGIS API for JavaScript uses a method called asynchronous module definition (AMD), which loads your JavaScript files on an as-needed basis. The reason for using it boils down to the fact that the ArcGIS API for JavaScript is built with the Dojo Toolkit. Dojo uses AMD to build applications, so AMD loading is another method you’ll learn to build your applications. A quick example of AMD loading is shown here:

I’ll cover more details of the AMD loader in chapter 3 when you build a custom widget.

Using Dijit

Dojo has a library called Dijit, which is used to build the JavaScript components that provide an interface in a web application. The interface could be a form to enter information or it could be a calendar date-picker. A process is in place for building these custom components, commonly referred to as widgets. Using Dojo, a developer can create custom widgets using the Dijit library’s base set of tools, which simplifies the process and makes writing reusable widgets much easier as an application grows. I’ll cover custom widgets in chapters 3 and 4.

1.3.2. Introducing a tad of GIS

I’m focusing on building web mapping applications using the ArcGIS API for JavaScript, and although knowledge of GIS isn’t a requirement to get into this subject, I want to review a few GIS concepts:

  • Interactive maps— An interactive map serves a specific purpose: a map is there to show you where. Show you where what? Maps communicate location information: it could be streets, neighborhoods, homes for sale, or how much income people make in certain cities, but the information revolves around where this information is displayed. As shown in figure 1.6, when you’re looking for a particular answer, sometimes you need to ask, “Where are you?”
    Figure 1.6. A map can communicate many things but often asks a simple question.

  • Maps and layers— You’ll learn about the parts of a map and how to use layers in chapter 2, but for now, all you need to know is that the map is the starting point for relaying information. For example, a point on the map could represent the location of a gas station, a series of lines on the map could show a city’s road network, or polygons on the map could display voting areas.
  • GIS data analysis— GIS helps you answer questions about the information you’re working with. How close am I to a certain location? How do I find a house that’s closest to schools, shopping centers, and where I work? Using the ArcGIS API for JavaScript, you can do interesting analyses. I won’t cover anything too extensive, but the capability is there should you need it, and you’ll learn how to access the tools to do so.

1.3.3. Interacting with the ArcGIS REST API

The engine that keeps the ArcGIS API for JavaScript running is the ArcGIS REST API, which I discussed in section 1.2.2. I’ll cover how to access the ArcGIS REST API to meet needs you might have that aren’t provided in the ArcGIS API for JavaScript in chapter 3. What it boils down to is being able to use the ArcGIS REST API to find out more information about the data you’re working with. You can think of it as metadata about your services. In this case, metadata includes information about a map service, such as what data is in the service, and whether the data is made up of points, lines, or polygons, or all of the above. Is the map service compatible with your other map services? What is the default look of your map service?

In terms of being able to fill possible gaps in functionality of the ArcGIS API for JavaScript, in chapter 3 you’ll build an extension in JavaScript that will display a legend that allows you turn individual layers on and off. This is a handy tool that isn’t provided out of the box with the ArcGIS API for JavaScript. These types of custom tools that require you to interact with the ArcGIS REST API aren’t always necessary, but when they are, you’ll be grateful to have a basic understanding of working with the ArcGIS REST API to cover your bases.

1.4. Summary

  • In this chapter, I discussed the prevalence of spatial applications in our everyday lives. From how we shop to where we live, location plays a vital role in our society.
  • I discussed various options available for building web mapping applications, each with its own merits. In this book, the focus is on the ArcGIS API for JavaScript, which is best suited for working with ArcGIS Server map services.
  • Trends in the GIS industry have shown a sharp increase for GIS professionals to have familiarity with a programming language, even if it’s to supplement GIS analyses and automate workflows. This opens up the opportunity for non-GIS professionals to dive into building web mapping applications that use the power of GIS data.
  • I covered the basics of accessing GIS data through web services, which you can use to build web mapping applications.
  • I provided a quick overview of concepts that you’ll know by the end of this book, such as JavaScript, the relevant parts of the Dojo Toolkit, the bits of GIS in your web maps, and what to look forward to when working with the ArcGIS REST API.

In chapter 2 you’ll learn how to use the ArcGIS API for JavaScript to work with various map services, query data from these services, and filter that data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.68.18