Book Image

Leaflet.js Essentials

By : Paul Crickard III, Paul Crickard
Book Image

Leaflet.js Essentials

By: Paul Crickard III, Paul Crickard

Overview of this book

Table of Contents (13 chapters)
Leaflet.js Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Making maps used to require an extensive knowledge of cartography, expensive software, and technical know-how. Today, there are numerous tools available, many of which are free, that have simplified the map-making process. This book is about using one such library, Leaflet.js.

Leaflet.js is a JavaScript library that although small, is packed with almost every feature you could need. If a feature is not available in the core library, it may be available as one of the many plugins that have become available. The largest map-making software vendor, Environmental Systems Research Institute (ESRI), has even released a plugin for Leaflet.js. If you are interested in making maps or in data visualization, Leaflet.js is the library to learn.

Whether you are looking to build simple maps or advanced mapping applications, this book will build on your JavaScript knowledge to help you reach your goal. This book was designed to be accessible to individuals who are new to map making and also to those who may know maps but are just learning to code.

What this book covers

Chapter 1, Creating Maps with Leaflet, walks you through the basics of making maps in Leaflet.js. You start by creating an HTML file with the minimum JavaScript code required to display a map. You are going to learn how to select different basemaps and providers and different basemap formats. Then, you will learn how to display geographic features such as points, polylines, and polygons.

Chapter 2, Mapping GeoJSON Data, introduces you to a geographic version of the JSON data format. You will learn how to create your own GeoJSON data as well as consume data from other sources. In this chapter, you will learn how to style the data and iterate through features to add pop ups.

Chapter 3, Creating Heatmaps and Choropleth Maps, moves away from simply displaying points and towards displaying the significance or comparisons of the data. It builds on what you have learned so far and teaches you how to use different plugins to create heatmaps. You will also learn how to use your knowledge of styling GeoJSON to create choropleth maps.

Chapter 4, Creating Custom Markers, guides you through the customization of the markers you use in your maps. You will learn how to draw your own image or modify an existing image to use it as a marker in your map. You will be introduced to several plugins that offer premade markers that are customizable. Also, you will learn how to animate markers and combine plugins for added effects.

Chapter 5, ESRI in Leaflet, opens up the most commonly used data formats and server endpoints in mapping. This chapter will teach you how to load shapefiles in your maps. You will also learn how to connect to an ESRI server that has an exposed REST service. Using the ESRI-Leaflet plugin, you will learn how to geocode and reverse geocode addresses, filter data from a server, and query by location.

Chapter 6, Leaflet in Node.js, Python, and C#, expands on everything you have learned in order to teach you how to build applications in other frameworks and languages. This chapter teaches you how to build both the frontend and the backend. You will build servers in JavaScript and Python. You will be introduced to NoSQL databases and AJAX to display and update data without refreshing your web page. Lastly, you will learn how to create a Windows desktop application by embedding Leaflet in C#.

What you need for this book

You need, at a minimum, the following software for this book:

For the examples in Chapter 5, ESRI in Leaflet and Chapter 6, Leaflet in Node.js, Python, and C#, the following software is required:

Who this book is for

If you are a map maker with some JavaScript knowledge, this book is an ideal resource that teaches you how to bring your maps to the Web and make them interactive. If you are a JavaScript developer, this book will show you how to use those skills to build powerful mapping applications.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Create a text string of the query and initialize your StringBuilder() method to hold the JavaScript of the function and results."

A block of code is set as follows:

var layer = new L.TileLayer('http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png');
map.addLayer(layer);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<style>
  html, body, #map {
      padding: 0;
      margin: 0;
      height: 100%;
    }
#points.hidden {
    display: none;
}
</style>
<body>
<div id="map"></div>
<div id="points"></div>

Any command-line input or output is written as follows:

npm install –g connect

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "You now need to right-click on the project in the Solution Explorer window and select Add Reference."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.