Martin Builds
  • Home
  • About/Contact
  • Privacy Policy
4 October 2019 by Martin
Find My Bricks, Lego

Deploying Leaflet Maps

Deploying Leaflet Maps
4 October 2019 by Martin
Find My Bricks, Lego

I use Leaflet, an open-source JavaScript library, as the engine for the interactive portion of my website. If you head over to the find-bricks part of my site you will likely realise you have used a Leaflet app before, most likely for its intended application of mapping.

In my app I take images of Lego and convert these to street map tiles, minus the actual mapping part. I have some experience with building Lego streets, but that’s limited to my collection of Lego Modular buildings

I recently learned how to use the Leaflet package in R as well as creating Shiny apps. The simplicity of combining these two was the catalyst to start this project.

Why Leaflet?

Smoothness and ease of use are two key criteria as data input needs to be as frictionless as possible to encourage people to use it. I could write my own JavaScript library however it would be a significant time investment to implement all the desirable features of Leaflet, such as smooth zoom & panning and being mobile friendly.

My skill level is more “full-stack”, where I can get by in JavaScript and quickly learn to do what I need to do but I’m not an expert in it. In the interest of getting the project online I felt it better to instead build upon the excellent groundwork of others and focus my energy on my strengths around application programming.

Map Tiles

Leaflet uses tiles at different zoom-levels where one tile at one level consists of four tiles of the previous.

For each map, I’m using the same image for each zoom level so I simply need to crop and re-size the image for each tile at each zoom level I am implementing. The tiles are saved in directory structure easy to point URLs at and I can then use these as tiles within Leaflet.

Leaflet with Shiny

Leaflet works very well with Shiny. A key functionality is Leaflet will pass events through to the shiny app’s inputs which can be observed and acted on. This allows me to detect when and where a map has been clicked, and add a marker at the coordinates.

I also use this to detect when a marker has been clicked, and what it’s ID is. This allows me to implement an “undo” function where clicking on a marker removes it from the map.

Whilst the majority of Leaflet runs client-side, the shiny code runs server side. This allows my shiny app to interact privately with database to ingest the markers representing the detected pieces.

Going Stateless?

Shiny is a key part of my solution however it is also a main limiter to saleability since a session needs to be established for each user. A better solution would be to implement a JavaScript library which does all the processing client-side and then uses a highly scaleable stateless protocol like S3 to “put” the data into a store without requiring an established connection.

However this being a hobby project, it will have to do. If the project does gain sufficient traction that I need more AWS resources then that would be a good problem to have.

Leaflet lego Maps R Shiny Server

Previous articleSite Launch - MartinBuilds.comNext article Opinion: Five Percent Accuracy
  • Fake it ’till you make it
    In AI / ML, Find My Bricks, Lego, Technology
  • Fooling the Mind – Lessons Learned in VR
    In Game Dev, Gaming, VR
  • Re-visiting NHL Data
    In Data, Hockey
  • Starting Game Dev 10 Years Later
    In Game Dev, Gaming
  • Going Serverless
    In AWS, Site News
  • Cold Start
    In Find My Bricks, Opinion
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary Always Enabled

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Non-necessary

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.