Leaflet, Node.JS, and MongoDB for an Easy and Fun Web Mapping Experience


Presented by:

Steven Pousty

@TheSteve0 on Twitter, Ingress, SmugMug, IRC, and Github


  1. A little about MongoDB Spatial
  2. A little about Node.JS
  3. A little about Leaflet.js
  4. Learn a bit about PaaS
  5. Make a cool mapping app


  1. You have worked with data
  2. You write some JS code
  3. You will ask questions

What's the scenario

  • We work for a Vendor that sells souvenirs at National Parks in the United States and Canada
  • We are making a check in service to help drive traffic to our stands
  • We want FOSS on the whole stack - NO LOCK IN
  • Due next week
  • By the end of this talk you can build this!


    On to Mongo


    A bit about MongoDB

    • A document is just a bunch of attributes and values - think of it like HashMap
    • Can be nested - helps avoid joins
    • Schemaless
    • Really good at fast writes - but you give up immediate consistency
    • Easy to horizontally scale

    Now some spatial

    The spatial functionality Mongo currently has is:

    1. Near ($near)
    2. Containment ($geoWithin)
    3. Intersection ($geoIntersects )

    Two types of indices:

    1. 2D - for flat surfaces
    2. 2dsphere - helps with coords on an earth like sphere

    Good to Know

    How do you make it work

    1a. Put coordinates into an array

    { loc : [ 50 , 30 ] }    
        If you use lattitude and longitude with a default index 
               make sure to put [lon, lat]

    1b. Put coordinates in a GeoJSON format

    { loc : { type : "Point" ,
          coordinates : [ 40, 5 ]

    Make it work (cont.)

    2a. Make a 2DSphere index

    				    	db.places.ensureIndex( { loc : "2dsphere" } )
    				    	can be a compound index

    2b. Make a 2D index

    				    	db.places.ensureIndex( { loc : "2d" } )

    On to Node.JS


    Why all the fuss

    1. It's all in JavaScript
    2. You get great async behavior out of the box
    3. Fast and Lightweight for certain use cases - where you are not DB bound

    Steve's Unofficial "When you should use it"

    1. You are a team of JS programmers
    2. You want to serve up a lot of things really fast
    3. You don't need all the libraries that some other languages bring

    Don't drink the Kool-Aid

    Time for Leaflet


    Quick into

    1. Lighweight JS client side library for doing great maps
    2. Works out of the box with OpenStreetMap (OSM) - as well as others
    3. Mobile ready
    4. Has a rich library of Plugins

    Enough Talk - CODE!


    How ya feeling?


    One Source to Bind Them All



    But wait - there's more

    1. Free! No time limit
    2. 3 gears (like servers) - each 512 Mb RAM, 1 Gb disk
    3. Auto-scaling
    4. Simple pricing

    Let's wrap it up

    1. Spatial is easy and fun with MongoDB, Node, & Leaflet
    2. Openshift makes life great for you
    3. You can do all this for free in a matter of minutes
    4. The price ($0) makes it so you can do this for any projet you want
    5. @ghaff - So simple even a marketing person can do it :-) http://wwos-bitmason.rhcloud.com

    Come hang out with us:
    #openshift on freenode irc