Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Aug 3, 2024
1 parent b80d908 commit 24acf62
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 32 deletions.
16 changes: 12 additions & 4 deletions guide/guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,7 @@ Beats:: Lists received heartbeat messages, sorted by node id. The beat view
shows the time the heartbeat was sent and received, as well as the time passed
since then, additionally in
link:https://en.wikipedia.org/wiki/Swatch_Internet_Time[Swatch Internet Time].
Map:: Displays nodes, sensors, and targets inside an interactive map.

The style sheet of *dmweb* is based on https://missing.style/[missing.css].
It can be replaced with any other classless CSS theme. For best experience, the
Expand Down Expand Up @@ -2304,9 +2305,15 @@ export GDFONTPATH="/usr/local/share/fonts/webfonts/"
| `DM_DB_BEAT` | Path to heartbeat database (server).
| `DM_DB_LOG` | Path to log database (client, server).
| `DM_DB_OBSERV` | Path to observation database (client, server).
| `DM_TILE_URL` | URL of link:https://leafletjs.com/reference.html#tilelayer-url-template[tile server].
| `DM_READ_ONLY` | Set to `1` to enable read-only database access.
|===

The map view requires a URL to the tile server in environment variable
`DM_TILE_URL`. For example, set the variable to
`https://tile.openstreetmap.org/{z}/{x}/{y}.png` to use OpenStreetMap as
the backend.

Copy the directory `/usr/local/share/dmpack/dmweb` manually to the WWW root
directory, or create a symlink. Environment variables are used to configure
*dmweb*. Transport security and authentication have to be managed by the web
Expand Down Expand Up @@ -6530,7 +6537,12 @@ LOG%MESSAGE="dummy log message",
....
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 0.0, 0.0, 0.0 ]
},
"properties": {
"type": "node",
"id": "dummy-node",
"name": "Dummy Node",
"meta": "Description",
Expand All @@ -6540,10 +6552,6 @@ LOG%MESSAGE="dummy log message",
"longitude": 0.0,
"latitude": 0.0,
"altitude": 0.0
},
"geometry": {
"type": "Point",
"coordinates": [ 0.0, 0.0, 0.0 ]
}
}
....
Expand Down
35 changes: 31 additions & 4 deletions share/dmweb/dmpack.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*jshint esversion: 6 */

/**
* Creates map with Leaflet.
*
Expand All @@ -10,12 +12,15 @@
*/
function createMap(id, url, lon, lat, zoom, features)
{
const options = { attributionControl: false };
const view = { lat: lat, lng: lon };
const maxZoom = 19;
const geoJson = { "type": "FeatureCollection", "features": features };

const map = L.map(id, { attributionControl: false }).setView({lat: lat, lng: lon }, zoom);
const map = L.map(id, options).setView(view, zoom);

L.tileLayer(url, { maxZoom: maxZoom }).addTo(map);

const geoJson = { "type": "FeatureCollection", "features": features };

L.geoJson(geoJson, {
pointToLayer,
onEachFeature
Expand All @@ -42,5 +47,27 @@ function onEachFeature(feature, layer)
*/
function pointToLayer(feature, latlng)
{
return L.circleMarker(latlng, { radius: 2 });
let options = {
radius: 4,
fillColor: "black",
color: "black",
weight: 1,
opacity: 1,
fillOpacity: 0.8
};

switch (feature.properties.type)
{
case 'node':
options.fillColor = "indigo";
break;
case 'sensor':
options.fillColor = "crimson";
break;
case 'target':
options.fillColor = "seagreen";
break;
}

return L.circleMarker(latlng, options);
}
60 changes: 36 additions & 24 deletions src/dm_geojson.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module dm_geojson
use :: dm_error
use :: dm_json
use :: dm_kind
use :: dm_type
use :: dm_util
implicit none (type, external)
private
Expand Down Expand Up @@ -38,13 +39,22 @@ module dm_geojson
! ******************************************************************
! PUBLIC PROCEDURES.
! ******************************************************************
subroutine dm_geojson_feature_point(geojson, id, name, meta, x, y, z, longitude, latitude, altitude)
subroutine dm_geojson_feature_point(geojson, type, id, name, meta, x, y, z, longitude, latitude, altitude)
!! Returns a GeoJSON string of the following form:
!!
!! ```json
!! {
!! "type": "Feature",
!! "geometry": {
!! "type": "Point",
!! "coordinates": [
!! 10.4541194000,
!! 51.1642292000,
!! 10.0000000000
!! ]
!! },
!! "properties": {
!! "type": "node",
!! "id": "dummy-node",
!! "name": "Dummy Node",
!! "meta": "dummy description"
Expand All @@ -54,18 +64,11 @@ subroutine dm_geojson_feature_point(geojson, id, name, meta, x, y, z, longitude,
!! "longitude": 10.4541194000,
!! "latitude": 51.1642292000,
!! "altitude": 10.0000000000
!! },
!! "geometry": {
!! "type": "Point",
!! "coordinates": [
!! 10.4541194000,
!! 51.1642292000,
!! 10.0000000000
!! ]
!! }
!! }
!! ```
character(len=:), allocatable, intent(out) :: geojson !! Output GeoJSON string.
integer, intent(in) :: type !! Point type.
character(len=*), intent(in) :: id !! Point id.
character(len=*), intent(in) :: name !! Point name.
character(len=*), intent(in) :: meta !! Point meta data.
Expand All @@ -76,22 +79,28 @@ subroutine dm_geojson_feature_point(geojson, id, name, meta, x, y, z, longitude,
real(kind=r8), intent(in) :: latitude !! Point latitude.
real(kind=r8), intent(in) :: altitude !! Point altitude.

integer :: type_

type_ = TYPE_NONE
if (dm_type_valid(type)) type_ = type

geojson = &
'{"type":"Feature","properties":{' // &
'"id":"' // id // '",' // &
'"name":"' // name // '",' // &
'"meta":"' // dm_json_escape(meta) // '",' // &
'"x":' // dm_ftoa(x) // ',' // &
'"y":' // dm_ftoa(y) // ',' // &
'"z":' // dm_ftoa(z) // ',' // &
'"longitude":' // dm_ftoa(longitude) // ',' // &
'"latitude":' // dm_ftoa(latitude) // ',' // &
'"altitude":' // dm_ftoa(altitude) // &
'},"geometry":{"type":"Point",' // '"coordinates":[' // &
dm_ftoa(longitude) // ',' // &
dm_ftoa(latitude) // ',' // &
dm_ftoa(altitude) // &
']}}'
'{"type":"Feature",' // &
'"geometry":{"type":"Point",' // '"coordinates":[' // &
dm_ftoa(longitude) // ',' // &
dm_ftoa(latitude) // ',' // &
dm_ftoa(altitude) // ']},' // &
'"properties":{' // &
'"type":"' // trim(TYPE_NAMES(type_)) // '",' // &
'"id":"' // id // '",' // &
'"name":"' // name // '",' // &
'"meta":"' // dm_json_escape(meta) // '",' // &
'"x":' // dm_ftoa(x) // ',' // &
'"y":' // dm_ftoa(y) // ',' // &
'"z":' // dm_ftoa(z) // ',' // &
'"longitude":' // dm_ftoa(longitude) // ',' // &
'"latitude":' // dm_ftoa(latitude) // ',' // &
'"altitude":' // dm_ftoa(altitude) // '}}'
end subroutine dm_geojson_feature_point

! ******************************************************************
Expand All @@ -105,6 +114,7 @@ function geojson_from_node(node) result(geojson)
character(len=:), allocatable :: geojson !! Alloctable GeoJSON string.

call dm_geojson_feature_point(geojson = geojson, &
type = TYPE_NODE, &
id = trim(node%id), &
name = trim(node%name), &
meta = trim(node%meta), &
Expand All @@ -124,6 +134,7 @@ function geojson_from_sensor(sensor) result(geojson)
character(len=:), allocatable :: geojson !! Alloctable GeoJSON string.

call dm_geojson_feature_point(geojson = geojson, &
type = TYPE_SENSOR, &
id = trim(sensor%id), &
name = trim(sensor%name), &
meta = trim(sensor%meta), &
Expand All @@ -143,6 +154,7 @@ function geojson_from_target(target) result(geojson)
character(len=:), allocatable :: geojson !! Alloctable GeoJSON string.

call dm_geojson_feature_point(geojson = geojson, &
type = TYPE_TARGET, &
id = trim(target%id), &
name = trim(target%name), &
meta = trim(target%meta), &
Expand Down

0 comments on commit 24acf62

Please sign in to comment.