Leaflet, Java EE, and MongoDB for an Easy and Fun Web Mapping Experience

Presented by:

Steven Pousty


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


  1. A little about MongoDB Spatial
  2. Some JEE
  3. Learn a bit about PaaS
  4. See some demos


  1. You write Java code
  2. 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!



    Types of NoSQL datastores

    TYPEDocumentKey-ValueGraphData ProcessingMisc
    EXAMPLE MongoDB, Couchbase Redis, Riak, Memcahe Neo4J Hadoop, Cassandra, Voldemort Lucene/Solr/ElasticSearch, VoltDB
    USE-CASE Document storage and search Caching or Object Store Relationships between "things" Large data processing Depends

    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" } )

    JEE - CDI and JAX-RS

    • Context Dependency Injection - allows you to make classes availble whenever you need them and let the calling class decide which class it wants
    • JAX-RS - the antiSOAP (three cheers). Makes it super easy to write REST like architectures

    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

    Let's look at some code

    Build a spatial checkin service for national parks in US and Canada

    Java EE MongoDB Map

    Let's spin up a JEE (JBoss EAP) and MongoDB server

    One Source to Bind Them All


    Let's wrap it up

    1. Spatial is easy and fun with MongoDB, Flask, & 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