Skip to Main Content
Leaflet.js Essentials
book

Leaflet.js Essentials

by Paul Crickard III
August 2014
Intermediate to advanced content levelIntermediate to advanced
180 pages
3h 41m
English
Packt Publishing
Content preview from Leaflet.js Essentials

GeoJSON in Leaflet.js

GeoJSON is just another data format for you to add to your map. It can be added as a hardcoded variable. Leaflet.js geometries—markers, polylines, and polygons—can be converted to GeoJSON. You can style the data, apply options to each feature, and even filter the data. The next sections will cover these topics, starting with adding GeoJSON as a hardcoded variable.

GeoJSON as a variable

The easiest way to add GeoJSON to your map is to hardcode the data into a variable. In Leaflet.js, you will start by creating a variable that will contain GeoJSON. In the following code, GeoJSON data consisting of two points is assigned to the geojson variable:

vargeojson = [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-106.62987,35.10418] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

GeoServer Beginner's Guide - Second Edition

GeoServer Beginner's Guide - Second Edition

Stefano Iacovella
React Cookbook

React Cookbook

David Griffiths, Dawn Griffiths
Stop Guessing

Stop Guessing

Nat Greene

Publisher Resources

ISBN: 9781783554812Supplemental Content