leaflet for some cats (with apologies to Max Ogden)

20
Leaflet For Some Cats. By Calvin Metcalf With apologies to Max Ogden

description

An introduction to leaflet so easy even a cat could understand it (Assuming your cat has a working knowledge of JavaScript like mine.)

Transcript of leaflet for some cats (with apologies to Max Ogden)

Page 1: leaflet for some cats (with apologies to Max Ogden)

Leaflet For Some Cats.By

Calvin MetcalfWith apologies to Max Ogden

Page 2: leaflet for some cats (with apologies to Max Ogden)

● I'm going to teach you all about Leaflet.js

● In a basic way that even a cat could understand

● Assuming your cat has a working knowledge of JavaScript like mine.

Page 3: leaflet for some cats (with apologies to Max Ogden)

Leaflet is a small library for making maps in the browser.

Page 4: leaflet for some cats (with apologies to Max Ogden)

It fills a similar niche to OpenLayers, GoogleMaps, or JQueryGeo

Page 5: leaflet for some cats (with apologies to Max Ogden)

Straight forward method chaining approch

var map = L.map("map-div") .setView([42.349993,-71.049858],16); .addLayer( L.tileLayer("http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg") );

Pro Tip: Method chaining is just a non pretension term for monad.

Page 6: leaflet for some cats (with apologies to Max Ogden)

What we made last slide

Page 7: leaflet for some cats (with apologies to Max Ogden)

Tell Me More

Page 8: leaflet for some cats (with apologies to Max Ogden)

Extendable

Large plugin community

Page 9: leaflet for some cats (with apologies to Max Ogden)

Clustering

or

Page 10: leaflet for some cats (with apologies to Max Ogden)

AJAXDid I mention it consumes GeoJSON natively?

Page 11: leaflet for some cats (with apologies to Max Ogden)

Usually you'd do:

L.geoJson(some geoJson object, {options}).addTo(map);

Page 12: leaflet for some cats (with apologies to Max Ogden)

L.GeoJSON.AJAX = L.GeoJSON.extend({ initialize: function (url, options) { this._layers = {}; L.Util.setOptions(this, options); var request = new XMLHttpRequest();

request.open("GET", url);var _this=this;request.onreadystatechange = function() {

if ( request.readyState === 4 && request.status === 200 ) {_this.addData( JSON.parse(request.responseText) );}

};request.send();

}});

Page 13: leaflet for some cats (with apologies to Max Ogden)

L.GeoJSON.AJAX = L.GeoJSON.extend({ initialize: function (url, options) { this._layers = {}; L.Util.setOptions(this, options); var request = new XMLHttpRequest();

request.open("GET", url);var _this=this;request.onreadystatechange = function() {

if ( request.readyState === 4 && request.status === 200 ) {_this.addData( JSON.parse(request.responseText) );}

};request.send();

}});

Page 14: leaflet for some cats (with apologies to Max Ogden)

L.geoJson.ajax=function(url,options){return new L.GeoJSON.AJAX(url,options);

}

Almost forgot

Page 15: leaflet for some cats (with apologies to Max Ogden)

Co

de

Wo

rkin

g

Page 16: leaflet for some cats (with apologies to Max Ogden)

Add D3 for double the awsome

Page 17: leaflet for some cats (with apologies to Max Ogden)

Easy: use D3 to transform your data before putting it onto a map

Page 18: leaflet for some cats (with apologies to Max Ogden)

Hard: use d3 to put the svg onto the map

Page 19: leaflet for some cats (with apologies to Max Ogden)

Pro: web worker fractals!(not d3, not me)

Page 20: leaflet for some cats (with apologies to Max Ogden)

leafletjs.com

github.com/calvinmetcalf

twitter.com/cwmma

kublaikat.tumblr.com

communistjs.com