SlideShare a Scribd company logo
1 of 22
Adding To The Leaf Pile

Leaflet.js Plugin Development
Michael Moore
Flat Rock Geographics

https://github.com/stuporglue/leaflet-spiders
Leaflet in 30 Seconds
●

JavaScript web mapping Library

●

Free

●

Lightweight
–

●

9k LOC vs. OpenLayer's 85k

Many plugins for other use cases
–

Some things are still missing!
Setup

1. Follow a tutorial on leafletjs.com
2. Change leaflet.js to leaflet-src.js
3. Get as close as you can without
customizing
Finding What To Change: API
●

Good API docs. Start there.
–

Find objects & methods related to task
Finding What To Change: API

Find those objects or in leaflet-src.js
● “L.Point = “
● “L.Point.prototype = ”
● “L.point = “
● “methodname: function(“
●
Object Types
●

L.Object – the object itself
–

●

Initialization defined here

L.Object.prototype – the object definition
–

This is what we actually want to modify

–

May be inherited, or may be defined explicitly
●

●

If inherited, you won't find it in the code

L.object – convenience method
–

May have extra initialization options
Special functions to know
●

L.Class
–

●

L.Class.extend
–

●

Create a new class by extending another with
additional functions

L.Class.include
–

●

Most Leaflet things inherit from this

Set functions in existing class

L.Class.mergeOptions
–

Set new default option values

L.NewClass = L.Marker.extend({funcName: function(){}})
Finding What To Change: Debugger
●

Explore objects in debugger
–
–

●

Expand to see methods and variables
Use tab-completion!

Use debugger on-next to figure out what
gets called.
–

Step through to find which function you want
to change
Debugger Crash Course
Debugger Tools

1. Reload
2. Continue
3. Step In To
4. Step Over
5. Step Out
Spiders

Let's add some Halloween spiders to the map and make them dance
We will use 3 different methods!
Ways To Bend Leaflet To Your Will
●

Add new methods

●

Override existing methods

●

Create new objects by extending existing

●

Not covered
–
–

●

New Objects From Scratch
Modifying Leaflet Itself

Not recommended
–

Reaching Inside Leaflet Objects
Static Spiders

Demo
// Customization Code
/* NONE*/
// Add some spider code
var spiders = [];
var spider,lat,lng;
var spiderIcon = new L.Icon({iconUrl:'img/spider.png'});
for(var i = 0;i<10;i++){
lat = Math.random()*180 - 90;
lng = Math.random()*360 - 180;
spider = new L.Marker([lat,lng],{icon:spiderIcon});
spider.addTo(map);
}
Adding a New Method
DEMO
// Customization Code
// We add a new function called *crawl* to the Marker object
L.Marker.include({crawl: function(){
// Convert to a pixel and jiggle it up to 5 pixels in any direction
var pixel = this._map.latLngToLayerPoint(this._latlng);
pixel.x += Math.round(Math.random()*10) - 5;
pixel.y += Math.round(Math.random()*10) - 5;
this._latlng = this._map.layerPointToLatLng(pixel);
this.update();
}});
New Method (cont)
// Add some spiders code
var spiders = [];
var spider,lat,lng;
var spiderIcon = new L.Icon({iconUrl:'img/spider.png'});
for(var i = 0;i<10;i++){
lat = Math.random()*180 - 90;
lng = Math.random()*360 - 180;
spider = new L.Marker([lat,lng],{icon:spiderIcon});
spider.addTo(map);
spiders.push(spider);
}
// Every 200ms make each spider crawl
setInterval(function(){
for(var i = 0;i<spiders.length;i++){
spiders[i].crawl();
}
},200);
Override Method
DEMO
// Customization Code
L.Marker.include({
// Save off the original update function so we can use it later
_origUpdate: L.Marker.prototype.update,
// Define our new update function
update: function(){
// Convert to a pixel and jiggle it up to 5 pixels in any direction
var pixel = this._map.latLngToLayerPoint(this._latlng);
pixel.x += Math.round(Math.random()*10) - 5;
pixel.y += Math.round(Math.random()*10) - 5;

}
});

this._latlng = this._map.layerPointToLatLng(pixel);
return this._origUpdate();
Override Method (cont)
// Add some spiders code
var spiders = [];
var spider,lat,lng;
var spiderIcon = new L.Icon({iconUrl:'img/spider.png'});
for(var i = 0;i<10;i++){
lat = Math.random()*180 - 90;
lng = Math.random()*360 - 180;
spider = new L.Marker([lat,lng],{icon:spiderIcon});
spider.addTo(map);
spiders.push(spider);
}
setInterval(function(){
for(var i = 0;i<spiders.length;i++){
spiders[i].update();
}
},200);
Object Extending
DEMO
L.Spider = L.Marker.extend({
// Anything we don't define will call up to the L.Marker object
options: {
icon: new L.Icon({iconUrl:'img/spider.png'})
},
// Called when object created
initialize: function(){
var lat = Math.random()*180 - 90;
var lng = Math.random()*360 - 180;
this._latlng = L.latLng(lat,lng);

},

var self = this;
setInterval(function(){self.crawl();}, 200);

// Move the spider
crawl: function(){
var pixel = this._map.latLngToLayerPoint(this._latlng);
pixel.x += Math.round(Math.random()*10) - 5;
pixel.y += Math.round(Math.random()*10) - 5;
this._latlng = this._map.layerPointToLatLng(pixel);
return this.update();
}
});
L.spider = function(latlng,options){
return new L.Spider();
};
Object Extending (cont)

for(var i = 0;i<10;i++){
new L.Spider().addTo(map);
}
Get the Code on GitHub!
https://github.com/stuporglue/leaflet-spiders
Questions?

?
Resources
●

Leaflet Releases Source Code

●

Leaflet API

●

Leaflet Plugin Authoring Guide

●

Leaflet-Spiders on GitHub
–

Leaflet-Spiders Demo

More Related Content

What's hot

GraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchGraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchNikolas Burk
 
Code-first GraphQL Server Development with Prisma
Code-first  GraphQL Server Development with PrismaCode-first  GraphQL Server Development with Prisma
Code-first GraphQL Server Development with PrismaNikolas Burk
 
Agile web development Groovy Grails with Netbeans
Agile web development Groovy Grails with NetbeansAgile web development Groovy Grails with Netbeans
Agile web development Groovy Grails with NetbeansCarol McDonald
 
Google Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptGoogle Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptOmar Miatello
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Bruce McPherson
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerBruce McPherson
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseBruce McPherson
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptChanghwan Yi
 
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn TớiTech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn TớiNexus FrontierTech
 
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013Anton Bangratz
 
Do something in 5 with gas 7-email log
Do something in 5 with gas 7-email logDo something in 5 with gas 7-email log
Do something in 5 with gas 7-email logBruce McPherson
 
The JavaScript You Wished You Knew
The JavaScript You Wished You KnewThe JavaScript You Wished You Knew
The JavaScript You Wished You KnewTroy Miles
 
Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appBruce McPherson
 
Session 2 android study jam
Session 2 android study jamSession 2 android study jam
Session 2 android study jamAtharvKarbhari
 
From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2StefanTomm
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed versionBruce McPherson
 
JavaScript Reactivity - Angular Meetup Dhaka
JavaScript Reactivity - Angular Meetup DhakaJavaScript Reactivity - Angular Meetup Dhaka
JavaScript Reactivity - Angular Meetup DhakaSajib Khan
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & CollectionsCocoaHeads France
 
Angular & RXJS: examples and use cases
Angular & RXJS: examples and use casesAngular & RXJS: examples and use cases
Angular & RXJS: examples and use casesFabio Biondi
 

What's hot (20)

GraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchGraphQL & Prisma from Scratch
GraphQL & Prisma from Scratch
 
Code-first GraphQL Server Development with Prisma
Code-first  GraphQL Server Development with PrismaCode-first  GraphQL Server Development with Prisma
Code-first GraphQL Server Development with Prisma
 
Agile web development Groovy Grails with Netbeans
Agile web development Groovy Grails with NetbeansAgile web development Groovy Grails with Netbeans
Agile web development Groovy Grails with Netbeans
 
Google Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptGoogle Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScript
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as database
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascript
 
RxSubject And Operators
RxSubject And OperatorsRxSubject And Operators
RxSubject And Operators
 
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn TớiTech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
 
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
 
Do something in 5 with gas 7-email log
Do something in 5 with gas 7-email logDo something in 5 with gas 7-email log
Do something in 5 with gas 7-email log
 
The JavaScript You Wished You Knew
The JavaScript You Wished You KnewThe JavaScript You Wished You Knew
The JavaScript You Wished You Knew
 
Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing app
 
Session 2 android study jam
Session 2 android study jamSession 2 android study jam
Session 2 android study jam
 
From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
 
JavaScript Reactivity - Angular Meetup Dhaka
JavaScript Reactivity - Angular Meetup DhakaJavaScript Reactivity - Angular Meetup Dhaka
JavaScript Reactivity - Angular Meetup Dhaka
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & Collections
 
Angular & RXJS: examples and use cases
Angular & RXJS: examples and use casesAngular & RXJS: examples and use cases
Angular & RXJS: examples and use cases
 

Similar to Adding To the Leaf Pile

3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOMJalpesh Vasa
 
2008-03-04 - Geoprocessing with ArcGIS.pdf
2008-03-04 - Geoprocessing with ArcGIS.pdf2008-03-04 - Geoprocessing with ArcGIS.pdf
2008-03-04 - Geoprocessing with ArcGIS.pdfssuseref75f1
 
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...Holden Karau
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
Functional Programming in Go
Functional Programming in GoFunctional Programming in Go
Functional Programming in GoAaron Schlesinger
 
Untangling spring week7
Untangling spring week7Untangling spring week7
Untangling spring week7Derek Jacoby
 
Data Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreData Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreRyan Morlok
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)Jose Manuel Pereira Garcia
 
BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...
BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...
BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...Ron Reiter
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On RailsSteve Keener
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineRoman Kirillov
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with DancerDave Cross
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNico Ludwig
 

Similar to Adding To the Leaf Pile (20)

3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
 
2008-03-04 - Geoprocessing with ArcGIS.pdf
2008-03-04 - Geoprocessing with ArcGIS.pdf2008-03-04 - Geoprocessing with ArcGIS.pdf
2008-03-04 - Geoprocessing with ArcGIS.pdf
 
SAADATMAND_PYTHON
SAADATMAND_PYTHONSAADATMAND_PYTHON
SAADATMAND_PYTHON
 
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
Gephi Toolkit Tutorial
Gephi Toolkit TutorialGephi Toolkit Tutorial
Gephi Toolkit Tutorial
 
Functional Programming in Go
Functional Programming in GoFunctional Programming in Go
Functional Programming in Go
 
Untangling spring week7
Untangling spring week7Untangling spring week7
Untangling spring week7
 
Data Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreData Migrations in the App Engine Datastore
Data Migrations in the App Engine Datastore
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
React inter3
React inter3React inter3
React inter3
 
BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...
BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...
BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Java Script Overview
Java Script OverviewJava Script Overview
Java Script Overview
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Javascript
JavascriptJavascript
Javascript
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
 

Recently uploaded

call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..nishakur201
 
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改atducpo
 
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfBreath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfJess Walker
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfpastor83
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushShivain97
 
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...anilsa9823
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改atducpo
 
Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666nishakur201
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...PsychicRuben LoveSpells
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...ur8mqw8e
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,dollysharma2066
 
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...CIOWomenMagazine
 
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual serviceanilsa9823
 
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...Leko Durda
 
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceanilsa9823
 
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxABMWeaklings
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girlsPooja Nehwal
 

Recently uploaded (20)

call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..
 
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
 
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfBreath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdf
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by Mindbrush
 
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
 
Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
 
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
 
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
 
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
 
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
 
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptx
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
 
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
 

Adding To the Leaf Pile

  • 1. Adding To The Leaf Pile Leaflet.js Plugin Development Michael Moore Flat Rock Geographics https://github.com/stuporglue/leaflet-spiders
  • 2. Leaflet in 30 Seconds ● JavaScript web mapping Library ● Free ● Lightweight – ● 9k LOC vs. OpenLayer's 85k Many plugins for other use cases – Some things are still missing!
  • 3. Setup 1. Follow a tutorial on leafletjs.com 2. Change leaflet.js to leaflet-src.js 3. Get as close as you can without customizing
  • 4. Finding What To Change: API ● Good API docs. Start there. – Find objects & methods related to task
  • 5. Finding What To Change: API Find those objects or in leaflet-src.js ● “L.Point = “ ● “L.Point.prototype = ” ● “L.point = “ ● “methodname: function(“ ●
  • 6. Object Types ● L.Object – the object itself – ● Initialization defined here L.Object.prototype – the object definition – This is what we actually want to modify – May be inherited, or may be defined explicitly ● ● If inherited, you won't find it in the code L.object – convenience method – May have extra initialization options
  • 7. Special functions to know ● L.Class – ● L.Class.extend – ● Create a new class by extending another with additional functions L.Class.include – ● Most Leaflet things inherit from this Set functions in existing class L.Class.mergeOptions – Set new default option values L.NewClass = L.Marker.extend({funcName: function(){}})
  • 8. Finding What To Change: Debugger ● Explore objects in debugger – – ● Expand to see methods and variables Use tab-completion! Use debugger on-next to figure out what gets called. – Step through to find which function you want to change
  • 10. Debugger Tools 1. Reload 2. Continue 3. Step In To 4. Step Over 5. Step Out
  • 11. Spiders Let's add some Halloween spiders to the map and make them dance We will use 3 different methods!
  • 12. Ways To Bend Leaflet To Your Will ● Add new methods ● Override existing methods ● Create new objects by extending existing ● Not covered – – ● New Objects From Scratch Modifying Leaflet Itself Not recommended – Reaching Inside Leaflet Objects
  • 13. Static Spiders Demo // Customization Code /* NONE*/ // Add some spider code var spiders = []; var spider,lat,lng; var spiderIcon = new L.Icon({iconUrl:'img/spider.png'}); for(var i = 0;i<10;i++){ lat = Math.random()*180 - 90; lng = Math.random()*360 - 180; spider = new L.Marker([lat,lng],{icon:spiderIcon}); spider.addTo(map); }
  • 14. Adding a New Method DEMO // Customization Code // We add a new function called *crawl* to the Marker object L.Marker.include({crawl: function(){ // Convert to a pixel and jiggle it up to 5 pixels in any direction var pixel = this._map.latLngToLayerPoint(this._latlng); pixel.x += Math.round(Math.random()*10) - 5; pixel.y += Math.round(Math.random()*10) - 5; this._latlng = this._map.layerPointToLatLng(pixel); this.update(); }});
  • 15. New Method (cont) // Add some spiders code var spiders = []; var spider,lat,lng; var spiderIcon = new L.Icon({iconUrl:'img/spider.png'}); for(var i = 0;i<10;i++){ lat = Math.random()*180 - 90; lng = Math.random()*360 - 180; spider = new L.Marker([lat,lng],{icon:spiderIcon}); spider.addTo(map); spiders.push(spider); } // Every 200ms make each spider crawl setInterval(function(){ for(var i = 0;i<spiders.length;i++){ spiders[i].crawl(); } },200);
  • 16. Override Method DEMO // Customization Code L.Marker.include({ // Save off the original update function so we can use it later _origUpdate: L.Marker.prototype.update, // Define our new update function update: function(){ // Convert to a pixel and jiggle it up to 5 pixels in any direction var pixel = this._map.latLngToLayerPoint(this._latlng); pixel.x += Math.round(Math.random()*10) - 5; pixel.y += Math.round(Math.random()*10) - 5; } }); this._latlng = this._map.layerPointToLatLng(pixel); return this._origUpdate();
  • 17. Override Method (cont) // Add some spiders code var spiders = []; var spider,lat,lng; var spiderIcon = new L.Icon({iconUrl:'img/spider.png'}); for(var i = 0;i<10;i++){ lat = Math.random()*180 - 90; lng = Math.random()*360 - 180; spider = new L.Marker([lat,lng],{icon:spiderIcon}); spider.addTo(map); spiders.push(spider); } setInterval(function(){ for(var i = 0;i<spiders.length;i++){ spiders[i].update(); } },200);
  • 18. Object Extending DEMO L.Spider = L.Marker.extend({ // Anything we don't define will call up to the L.Marker object options: { icon: new L.Icon({iconUrl:'img/spider.png'}) }, // Called when object created initialize: function(){ var lat = Math.random()*180 - 90; var lng = Math.random()*360 - 180; this._latlng = L.latLng(lat,lng); }, var self = this; setInterval(function(){self.crawl();}, 200); // Move the spider crawl: function(){ var pixel = this._map.latLngToLayerPoint(this._latlng); pixel.x += Math.round(Math.random()*10) - 5; pixel.y += Math.round(Math.random()*10) - 5; this._latlng = this._map.layerPointToLatLng(pixel); return this.update(); } }); L.spider = function(latlng,options){ return new L.Spider(); };
  • 19. Object Extending (cont) for(var i = 0;i<10;i++){ new L.Spider().addTo(map); }
  • 20. Get the Code on GitHub! https://github.com/stuporglue/leaflet-spiders
  • 22. Resources ● Leaflet Releases Source Code ● Leaflet API ● Leaflet Plugin Authoring Guide ● Leaflet-Spiders on GitHub – Leaflet-Spiders Demo

Editor's Notes

  1. {"5":"When we find the name of the object we want to modify, we now need to find the code behind it. We&apos;ll search for it in leaflet-src.js \nThis is one of the slightly tricky conventions about the leaflet code. For any given leaflet object type there are three places you may need to look for code.\n","11":"So, here comes the code intensive part of the presentation. \nLike I said earlier, the WFS-Transactional plugin grew too unwieldy to present in a session like this, so instead I created three very simple plugins that all do the same thing. \nOn a very basic map, we&apos;re going to add dancing haloween spiders.\n","6":"The L.Point function is the actual object type that we will see in a minute the debugger. It includes initialization code.\nThe .prototype is like an object template. The .prototype is where class functions and variables are defined.\nThe L.point function handles fancy initialization, like if you want to be able to pass in several types of objects. \n","1":"Good Morning Everybody!\nThank you for coming to “Adding to the leaf pile” a presentation on Leaflet plugin development. \nI&apos;m Michael Moore, I&apos;m a GIS web developer for Flat Rock Geographics I&apos;m also a 2nd year MGIS student at the University of Minnesota.\nThis spring I started developing a website which uses Leaflet and it came to a point where we needed to use WFS-Transactional, which Leaflet doesn&apos;t support out of the box. So, I dug into Leaflet plugin development. \nThe actual code for that plugin ended up being to complex for a simple presentation, so I made a simple example to use instead, but we&apos;ll get to that in a minute. \n","7":"There are several special object types and functions in the code, but there are just three that deserve special mention today. \nL.extend adds a hash of new methods to an existing object and returns a new object type.\nL.Class.mergeOptions will set new default options in a class.\n","2":"For those of you who aren&apos;t familiar with Leaflet, here&apos;s a 30 second overview. It is a free JavaScript web mapping library. Other popular web mapping libraries include OpenLayers or The Google Maps API. \nLeaflet is very light weight, with only 9000 lines of code, as compared to OpenLayers 85,000 lines of code. The code is also very neatly organized and easy to read. \nLeaflet itself covers 90% of use cases that developers will have, and there are plugins for many other use cases. However, some things are still missing or maybe you just want to customize something that is already there. If that&apos;s the case you may want to make a leaflet plugin. \n","8":"Next up we&apos;re going to explore objects in the debugger. If you&apos;re going to do Leaflet development, or any other JavaScript development the debugger is going to be your best friend.\nYou can inspect variables, objects and functions. You can step through live code a line at a time and lots of other cool stuff. \n","3":"To develop a leaflet plugin, start by setting up your map, possibly by following one of the simple tutorials on the Leaflet website.\nOnce the map is working, change the reference to leaflet.js to leaflet-src.js The leaflet.js file is compressed, making it difficult to read or to use for debugging. The leaflet-src.js file is the full 9000 lines of code. \nNext, especially if you&apos;re extending existing functionality, get the map as close to working as you can. \nFor example, if you want popups to behave differently than normal, get regular popups working first. \n","9":"Here&apos;s a brief introduction to the Firebug debugger. Chrome, Safari and Internet Explorer all have built-in debuggers that are similar to this one. \nI have circled a couple of the key features.\n","4":"The next step is to find what you need to change. Ideally we will be able to modify an existing object type to do what we want instead of writing a new Leaflet object type from scratch. \nThe Leaflet API is s very good, so we&apos;ll start there. \n","10":"These buttons let you control the debugger when you&apos;re stepping through code a line at a time. \nWe will do a demo of this at the end, if there is time.\n"}