Переглянути джерело

ffho-site-auto-select: use geojson format
the file has to be stored in $(GLUONSITEDIR)/extra/geo.json and is later stored in /lib/gluon/site-select/geo.json. bevore storing, the data is decoded and encoded to get rid of spaces, comments and line break.

Karsten Böddeker 8 роки тому
батько
коміт
6be410d9fb

+ 1 - 0
ffho/ffho-site-auto-select/Makefile

@@ -37,6 +37,7 @@ endef
 
 define Package/ffho-site-auto-select/install
   $(CP) ./files/* $(1)/
+  lua -e 'print(require("cjson").encode(require("cjson").decode(io.open("$(GLUON_SITEDIR)/extra/geo.json"):read('*a'))))' >  $(1)/lib/gluon/site-select/geo.json
 endef
 
 $(eval $(call BuildPackage,ffho-site-auto-select))

+ 9 - 6
ffho/ffho-site-auto-select/files/lib/gluon/upgrade/003-site-auto-select

@@ -5,6 +5,8 @@ local json = require 'luci.json'
 local tools = require 'gluon.site_generate'
 local shape = require 'gluon.pointwithinshape'
 
+local geo_default_site = "ffho_yho"
+
 function get_config(file)
   local f = io.open(file)
   if f then
@@ -36,17 +38,18 @@ function set_currentsite(site_code)
 end
 
 function get_site_by_geo(latitude, longitude)
-  os.execute('gunzip -c /lib/gluon/site-select/site-coords.gz > /tmp/site-coords.json')
-  local sites = tools.get_config('/tmp/site-coords.json')
-  os.remove('/tmp/site-coords.json')
+  if not latitude or not longitude then
+    return nil
+  end
 
+  local sites = tools.get_config('/lib/gluon/site-selcet/geo.json').features
   for _,site in ipairs(sites) do
-    if shape.PointWithinShape(site.coords, latitude, longitude) == true then
-      return site.site_code
+    if site.geometry and site.geometry.coordinates and shape.PointWithinShape(site.geometry.coordinates, latitude, longitude) then
+      return site.properties.site_code
     end
   end
 
-  return "ffho_yho"
+  return geo_default_site
 end
 
 local currentsite = uci:get('currentsite', 'current', 'name')