The task was to have a map that renders the location of 12,000+ sites by adding a circle marker and popup window when clicked. And it must be very fast, ideally so fast that it seems itβs instantaneous. In this article, I will share my implementation with Elixir, LiveView, and Leaflet.js along with optimization techniques I came up with.
If we were to zoom out, There are two main tasks that we need to do:
- Fetch data from database and pass it to the frontend
- Render the data on a map
First part is handled by the server while rendering the map happens on the client side. Because there is a lot of data we need to fetch and render, optimizations are needed on both server and client sides.
To implement the map using Elixir, LiveView, and Leaflet.js, we need to do the following:
- Elixir fetches data from the database and passes it to the LiveView
- LiveView receives the data and passes it to the client (JavaScript (JS) Hook with
push_event
)- JS handles the received data by creating a map with Leaflet.js and adding marker
continue reading on dev.to
β οΈ This post links to an external website. β οΈ
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.