Packages

LiveMap is a Phoenix LiveView component for interactive map with dynamic data.

Current section

Files

Jump to
live_map lib live_map.html.heex
Raw

lib/live_map.html.heex

<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
width={@width} height={@height}
>
<title><%= @title %></title>
<%# Thanks to SVG scaling, we can simply place the 1x1 tile images at their
exact X, Y location. The viewBox is then used to offset the view to the map.
The tile layer then uses preserveAspectRatio to make the tiles cover. %>
<svg viewBox={viewbox(@tiles)} preserveAspectRatio="xMidYMid slice">
<title>Tile Layer</title>
<%= for tile <- @tiles do %>
<image
href={"https://tile.openstreetmap.org/#{@zoom}/#{tile.x}/#{tile.y}.png"}
x={tile.x} y={tile.y} width="1" height="1"
/>
<% end %>
</svg>
<style></style>
</svg>