Leanpub Header

Skip to main content

Leaflet Tips and Tricks

Interactive Maps Made Easy

Presentation and control of interactive maps for traditional Internet and mobile platforms is now in your hands using leaflet.js. This book is aimed at helping people get started with this awesome JavaScript library. You can download for free or donate if you feel like contributing to further development :-).

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
6,935
Readers
152
Pages
About

About

About the Book

Leaflet Tips and Tricks is currently being updated to align it with the 1.x release version. The content is still good and relevant even while it is being updated, so feel free to download a copy and check frequently to get the latest (free!) updates.

leaflet.js can help you make the interactive maps YOU want.

Laeflet Tips and Tricks is a book written to help those who may be unfamiliar with JavaScript or web page creation get started bringing their map vision to the World.

Maps and geographic information is the new medium of choice for presenting compelling information and providing location context on the Internet and leaflet.js is an extraordinary library for presentation of maps on a web page.

Is this book for you?

It's not written for experts. It's put together as a guide to get you started if you're unsure what leaflet.js can do. It reads more like a story as it leads the reader through the basics of a simple map with advice on getting started and the sort of things that will help you expand your knowledge.

This book was originally written and published in 2014. Since then Leaflet has continued to grow in popularity. The plan is for me to update the book for the 1.x release of Leaflet

Why was Leaflet Tips and Tricks written?

Because in the process of learning things, it's a great way to remember them if you write them down :-).

As a result, learning how to do cool stuff with maps and Leaflet meant that I accumulated a sizeable number ways to help me out when the going got tricky. Then I realised that these could be useful for others who were trying out leaflet.js and who were at a similar knowledge level.

So here we are! A collection of tips and tricks for leaflet.js written by a noob for people who might consider that they're in the same situation :-).

What's in the book?

I've captured the appropriate code (in cool looking coloured text) and added in illustrations of what's going on so that you will get more traction at the start of your learning process than I did.

Download the whole book just to try it out!

I'm making the book available for free because I think it's a great way to give something back to the community as a whole, but if you find some value in the book, please consider contributing $4.99 when you download it so that Leanpub get something for hosting the book and providing such an awesome service (50 cents + 20% is their cut of any book sales and $4.99 is the minimum (apart from $0) that they will allow for a sale).

Enjoy.

So I hope you get something out of the book, please excuse the sometimes light-hearted conversational manner in which I approach the topic and enjoy Leaflet!

Share this book

Categories

Price

Pick Your Price...

Minimum price

Free!

$0.99

You pay

$0.00

Author earns

$0.00
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 0)

0
The author will earn $0.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Malcolm Maclean

I have a passion for knowledge and I realise that part of the responsibility of gathering knowledge is being able to advance the state of the human condition in some way.

My aims in writing these books are to play with software, achieve personal goals and try something new for fun. It also helps that I think Open Source, technology, the visual representation of data and information rock in serious ways.

The books that I write are a mechanism to support my own learning, so the way I explain things is focused on trying to impart understanding in a simple but functional way.

I'm totally in awe of the Open Source community that has made this type of work possible. If you feel that you would like to support continued development of this content, feel free to donate when you download.

If you're looking for a hard copy version of any of these publications, they will be available through Amazon (not all will be available sorry).

Contents

Table of Contents

Acknowledgements

  1. Make sure you get the most up to date copy of Leaflet Tips and Tricks

Introduction

What is leaflet.js?

What do you need to get started?

  1. DON’T FREAK OUT!
  2. HTML
  3. JavaScript
  4. Cascading Style Sheets (CSS)
  5. Full disclosure
  6. Web Servers
  7. PHP
  8. Other Useful Stuff
  9. Text Editor
  10. Getting Leaflet
  11. Access Leaflet via a CDN (Content Delivery Network)
  12. Where to get information on leaflet.js
  13. leafletjs.com
  14. Google Groups
  15. Stack Overflow
  16. Github
  17. bl.ocks.org
  18. Twitter
  19. Tutorials

Start With a Simple Map

  1. HTML
  2. JavaScript
  3. Declaring the starting parameters for the map
  4. Declaring the source for the map tiles
  5. And there’s your map!

Leaflet Features

  1. Adding a marker to our map
  2. Adding a popup to our marker
  3. Marker options
  4. Drag a marker
  5. Add a title to a marker
  6. Adjust the markers transparency
  7. Adding multiple markers to our map
  8. Adding a line to our map
  9. Adding options to our polyline
  10. Using multiple tile layers on your map
  11. Overlaying information interactively on your map

Leaflet Plugins

  1. Leaflet.draw
  2. Leaflet.draw code description
  3. Leaflet.draw configuration options
  4. Object colours
  5. Polygon line intersection
  6. Show and measure an area
  7. Repeating a drawing option automatically
  8. Place an alternative marker
  9. Place the Leaflet.draw toolbar in another position
  10. OSMGeocoder Search
  11. OSMGeocoder code description
  12. OSMGeocoder configuration options
  13. Leaflet.FileLayer load local GPX, KML, GeoJSON files
  14. Leaflet.FileLayer code description
  15. Generate a heatmap with Leaflet.heat
  16. Leaflet.heat code description
  17. radius configuration option
  18. blur configuration option
  19. maxZoom configuration option

Assorted Leaflet Tips and Tricks

  1. Make your map full screen
  2. Importing external data into leaflet.js
  3. Importing data as a JavaScript file
  4. Importing data from MySQL via php
  5. Extracting data from MySQL with php
  6. Making maps with d3.js and leaflet.js combined
  7. d3.js Overview
  8. Leaflet map with d3.js objects that scale with the map
  9. Leaflet map with d3.js elements that are overlaid on a map

Tile servers that can be used with Leaflet

  1. URL Template
  2. Usage Policy
  3. Attribution
  4. Open Street Map OSM Mapnik
  5. URL Template
  6. Usage policy
  7. Attribution
  8. Usage example
  9. Open Street Map Black and White
  10. URL Template
  11. Usage policy
  12. Attribution
  13. Usage example
  14. Open Cycle Map
  15. URL Template
  16. Usage policy
  17. Attribution
  18. Usage example
  19. Outdoors
  20. URL Template
  21. Usage policy
  22. Attribution
  23. Usage example
  24. Transport
  25. URL Template
  26. Usage policy
  27. Attribution
  28. Usage example
  29. Landscape
  30. URL Template
  31. Usage policy
  32. Attribution
  33. Usage example
  34. MapQuest Open Aerial
  35. URL Template
  36. Usage policy
  37. Attribution
  38. Usage example
  39. MapQuest-OSM
  40. URL Template
  41. Usage policy
  42. Attribution
  43. Usage example
  44. Stamen.Watercolor
  45. URL Template
  46. Usage policy
  47. Attribution
  48. Usage example
  49. Esri World Imagery
  50. URL Template
  51. Usage policy
  52. Attribution
  53. Usage example

Map Tips and Tricks

  1. How do maps get presented on a web page?
  2. Vectors and bitmaps.
  3. Vector graphics
  4. Bitmap graphics
  5. Vectors and bitmaps for maps.
  6. Map tiles and zoom levels
  7. How are the tiles on a map server organised?

MySQL Tips and Tricks for leaflet.js

  1. Using a MySQL database as a source of data.
  2. PHP is our friend
  3. phpMyAdmin
  4. Create your database
  5. Databases and Tables
  6. Importing your data into MySQL
  7. Querying the Database
  8. Using php to extract json from MySQL
  9. Getting the data into leaflet.js

Appendices

  1. Full Screen Map
  2. Leaflet.draw plugin with options.
  3. OSMGeocoder plugin with options.

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub