Skip to content

Commit

Permalink
gluon-config-mode-geo-location-osm: add OSM-based location picker
Browse files Browse the repository at this point in the history
gluon-config-mode-geo-location-osm extends the
gluon-config-mode-geo-location with a location picker based on
OpenStreetMaps.

Based-on-patch-by: Jan-Tarek Butt <tarek@ring0.de>
  • Loading branch information
neocturne committed Aug 22, 2018
1 parent c3bb882 commit b0cc8cf
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 18 deletions.
15 changes: 15 additions & 0 deletions docs/user/site.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ config_mode \: optional
package. Set *geo_location.show_altitude* to *true* if you want the altitude
field to be visible.

The *geo_location.osm* section is only relevant when the *gluon-config-mode-geo-location-osm*
package is used. The *center.lon* and *center.lat* values are mandatory in this case and
define the default center of the map when no position has been picked yet. The *zoom* level
defaults to 12 in this case. *openlayers_url* allows to override the base URL of the
*build/ol.js* and *css/ol.css* files (the default is
``https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.1.3``).

The remote login page only shows SSH key configuration by default. A
password form can be displayed by setting *remote_login.show_password_form*
to true; in this case, *remote_login.min_password_length* defines the
Expand All @@ -419,6 +426,14 @@ config_mode \: optional
},
geo_location = {
show_altitude = true,
osm = {
center = {
lon = 52.951947558,
lat = 7.844238281,
},
zoom = 13,
openlayers_url = 'http://ffac/ol',
},
},
remote_login = {
show_password_form = true,
Expand Down
20 changes: 20 additions & 0 deletions package/gluon-config-mode-geo-location-osm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=gluon-config-mode-geo-location-osm
PKG_VERSION:=1

include ../gluon.mk

define Package/gluon-config-mode-geo-location-osm
TITLE:=Set geographic location of a node (map support)
DEPENDS:=+gluon-config-mode-geo-location +gluon-web-osm
endef

define Package/gluon-config-mode-geo-location-osm/install
$(Gluon/Build/Install)

$(INSTALL_DIR) $(1)/lib/gluon/config-mode/www/static/
$(LN) /lib/gluon/web/www/static/gluon-web-osm.js $(1)/lib/gluon/config-mode/www/static/
endef

$(eval $(call BuildPackageGluon,gluon-config-mode-geo-location-osm))
4 changes: 4 additions & 0 deletions package/gluon-config-mode-geo-location-osm/check_site.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
need_number(in_site({'config_mode', 'geo_location', 'osm', 'center', 'lon'}))
need_number(in_site({'config_mode', 'geo_location', 'osm', 'center', 'lat'}))
need_number(in_site({'config_mode', 'geo_location', 'osm', 'zoom'}), false)
need_string(in_site({'config_mode', 'geo_location', 'osm', 'openlayers_url'}), false)
17 changes: 17 additions & 0 deletions package/gluon-config-mode-geo-location-osm/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: gluon-config-mode-geo-location\n"
"Last-Translator: Matthias Schiffer <mschiffer@universe-factory.net>\n"
"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid ""
"You may also select the position on the map displayed below if your computer "
"is connected to the internet at the moment."
msgstr ""
"Wenn dein Computer aktuell mit dem Internet verbunden ist, kann die Position "
"auch auf der hier angezeigten Karte ausgewählt werden."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"

msgid ""
"You may also select the position on the map displayed below if your computer "
"is connected to the internet at the moment."
msgstr ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local osm = require 'gluon.web.model.osm'
local site = require 'gluon.site'

local tonumber = tonumber


module 'gluon.config-mode.geo-location-osm'

MapValue = osm.MapValue

function help(i18n)
local pkg_i18n = i18n 'gluon-config-mode-geo-location-osm'
return pkg_i18n.translate(
'You may also select the position on the map displayed below if your computer is connected to the internet at the moment.'
)
end

function options(lon, lat)
local config = site.config_mode.geo_location.osm

local map_options = {
openlayers_url = config.openlayers_url(),
zoom = config.zoom(12),
pos = config.center(),
}

if lon and lat then
map_options.zoom = 18
map_options.pos = { lon = tonumber(lon), lat = tonumber(lat) }
map_options.set = true
end

return map_options
end
12 changes: 6 additions & 6 deletions package/gluon-config-mode-geo-location/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ msgid "Altitude"
msgstr "Höhe"

msgid ""
"If you want the location of your node to be displayed on the map, you can "
"enter its coordinates here."
"If you want the location of your node to be displayed on public maps, you "
"can enter its coordinates here."
msgstr ""
"Um deinen Knoten auf der Karte anzeigen zu können, benötigen wir seine "
"Koordinaten. Hier hast du die Möglichkeit, diese zu hinterlegen."
"Um deinen Knoten auf öffentlichen Karten anzeigen zu können, benötigen wir "
"seine Koordinaten. Hier hast du die Möglichkeit, diese zu hinterlegen."

msgid "Latitude"
msgstr "Breitengrad"

msgid "Longitude"
msgstr "Längengrad"

msgid "Show node on the map"
msgstr "Knoten auf der Karte anzeigen"
msgid "Advertise node position"
msgstr "Knotenposition veröffentlichen"

msgid ""
"Specifying the altitude is optional; it should only be filled in if a "
Expand Down
10 changes: 4 additions & 6 deletions package/gluon-config-mode-geo-location/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ msgid "Altitude"
msgstr "Hauteur"

msgid ""
"If you want the location of your node to be displayed on the map, you can "
"enter its coordinates here."
"If you want the location of your node to be displayed on public maps, you "
"can enter its coordinates here."
msgstr ""
"Pour Afficher votre nœud sur la Carte nous avons besoin de ses coordonnées. "
"Ici vous pouvez entrer sa position."

msgid "Latitude"
msgstr "Latitude"

msgid "Longitude"
msgstr "Longitude"

msgid "Show node on the map"
msgstr "Afficher le nœud sur la carte"
msgid "Advertise node position"
msgstr ""

msgid ""
"Specifying the altitude is optional; it should only be filled in if a "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgid "Altitude"
msgstr ""

msgid ""
"If you want the location of your node to be displayed on the map, you can "
"enter its coordinates here."
"If you want the location of your node to be displayed on public maps, you "
"can enter its coordinates here."
msgstr ""

msgid "Latitude"
Expand All @@ -15,7 +15,7 @@ msgstr ""
msgid "Longitude"
msgstr ""

msgid "Show node on the map"
msgid "Advertise node position"
msgstr ""

msgid ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ return function(form, uci)

local site = require 'gluon.site'

local osm
pcall(function() osm = require 'gluon.config-mode.geo-location-osm' end)

local location = uci:get_first("gluon-node-info", "location")

local show_altitude = site.config_mode.geo_location.show_altitude(false)
Expand All @@ -14,6 +17,9 @@ return function(form, uci)
'If you want the location of your node to ' ..
'be displayed on the map, you can enter its coordinates here.'
)
if osm then
text = text .. ' ' .. osm.help(i18n)
end
if show_altitude then
text = text .. ' ' .. pkg_i18n.translate(
'Specifying the altitude is optional; it should only be filled in if a accurate ' ..
Expand All @@ -26,7 +32,7 @@ return function(form, uci)

local o

local share_location = s:option(Flag, "location", pkg_i18n.translate("Show node on the map"))
local share_location = s:option(Flag, "location", pkg_i18n.translate("Advertise node position"))
share_location.default = uci:get_bool("gluon-node-info", location, "share_location")
function share_location:write(data)
uci:set("gluon-node-info", location, "share_location", data)
Expand All @@ -37,21 +43,32 @@ return function(form, uci)
end
end

local lat = uci:get("gluon-node-info", location, "latitude")
local lon = uci:get("gluon-node-info", location, "longitude")

local map = {}
if osm then
map = s:option(osm.MapValue, "map", osm.options(lon, lat))
map:depends(share_location, true)
end

o = s:option(Value, "latitude", pkg_i18n.translate("Latitude"), pkg_i18n.translatef("e.g. %s", "53.873621"))
o.default = uci:get("gluon-node-info", location, "latitude")
o.default = lat
o:depends(share_location, true)
o.datatype = "float"
function o:write(data)
uci:set("gluon-node-info", location, "latitude", data)
end
map.lat = o

o = s:option(Value, "longitude", pkg_i18n.translate("Longitude"), pkg_i18n.translatef("e.g. %s", "10.689901"))
o.default = uci:get("gluon-node-info", location, "longitude")
o.default = lon
o:depends(share_location, true)
o.datatype = "float"
function o:write(data)
uci:set("gluon-node-info", location, "longitude", data)
end
map.lon = o

if show_altitude then
o = s:option(Value, "altitude",
Expand Down

0 comments on commit b0cc8cf

Please sign in to comment.