This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
defmodule ApresseWeb.APRSMap do | ||
@moduledoc """ | ||
TBD. A standalone plug module to pick APRS data from ETS | ||
and convert them into map data through templates. | ||
""" | ||
|
||
# Note for module development: | ||
# No compression | ||
# No caching (since the contents of directory may vary every time) | ||
|
||
@behaviour Plug | ||
@allowed_methods ~w(GET HEAD) | ||
|
||
import Plug.Conn | ||
alias Plug.Conn | ||
|
||
def init(_opts) do | ||
# do nothing here | ||
end | ||
|
||
def call(conn = %Conn{method: meth}, _) | ||
when meth in @allowed_methods do | ||
dump_aprs_map(conn) | ||
end | ||
|
||
def call(conn, _opts) do | ||
conn | ||
end | ||
|
||
defp dump_aprs_map(conn) do | ||
conn | ||
|> put_resp_header("content-type", "text/html") | ||
|> send_resp(200, make_aprs_map()) | ||
|> halt | ||
end | ||
|
||
require EEx | ||
|
||
EEx.function_from_file(:defp, :header_html, | ||
"lib/templates/apresse_web_header.html.eex", [ | ||
]) | ||
|
||
EEx.function_from_file(:defp, :footer_html, | ||
"lib/templates/apresse_web_footer.html.eex", [ | ||
]) | ||
|
||
EEx.function_from_file(:defp, :mapentry_html, | ||
"lib/templates/apresse_web_mapentry.html.eex", [ | ||
:source, | ||
:lat, | ||
:long | ||
]) | ||
|
||
defp make_aprs_map() do | ||
# Plug.conn.send_resp/3 accepts IOlist in the body | ||
[ | ||
header_html(), | ||
Enum.map(:ets.tab2list(:aprs_positions), | ||
fn({_, source, lat, long}) -> mapentry_html(source, lat, long) end), | ||
footer_html() | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
} | ||
showmap(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>apresse APRS map</title> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<!-- Google Maps API --> | ||
<script | ||
src="http://maps.google.com/maps/api/js?sensor=false&libraries=geomtry"> | ||
</script> | ||
<link rel="stylesheet" href="static/leaflet.css"> | ||
<script src="static/leaflet.js"></script> | ||
<script src='static/Leaflet.GoogleMutant.js'></script> | ||
</head> | ||
<body> | ||
<h1>apresse APRS map</h1> | ||
<div id="mapid" style="width: 1280px; height: 768px;"></div> | ||
<script> | ||
function showmap() { | ||
var mymap = L.map('mapid').setView([0.0, 0.0], 1); | ||
L.gridLayer.googleMutant({type: 'roadmap'}).addTo(mymap); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% | ||
popup = :io_lib.format("Source: ~s<br>Lat: ~.4f<br>Long: ~.4f", | ||
[source, lat, long]) | ||
%> | ||
var marker = L.marker([<%= lat %>, <%= long %>]).addTo(mymap).bindPopup('<%= popup %>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters