1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

Merge pull request #1639 from georgejhunt/unmenu

Unmenu for OSM vector maps
This commit is contained in:
A Holt 2019-05-09 12:09:52 -04:00 committed by GitHub
commit 8eb10a8fe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 154 additions and 165 deletions

View file

@ -13,6 +13,12 @@
when: named_install when: named_install
tags: base, named, network, domain tags: base, named, network, domain
- name: Installing vector map test page
include_role:
name: osm-vector-maps
when: osm_vector_maps_install
tags: base, map
- name: Installing captive portal - name: Installing captive portal
include_tasks: roles/captive-portal/tasks/main.yml include_tasks: roles/captive-portal/tasks/main.yml
when: captive_portal_install when: captive_portal_install

View file

@ -0,0 +1,8 @@
osm_vector_maps_install: True
osm_vector_maps_enabled: True
vector_map_path: '{{ content_base }}/www/osm-vector-maps'
# All above are set in: github.com/iiab/iiab/blob/master/vars/default_vars.yml
# If nec, change them by editing /etc/iiab/local_vars.yml prior to installing!
iiab_map_url : http://download.iiab.io/content/OSM/vector-tiles/maplist/hidden

View file

@ -1,16 +1,16 @@
// osm_functions.js -- (non authoritative see below) src = iiab/roles/files/ // map_functions.js -- (non authoritative see below) src = iiab/roles/files/
// copyright 2019 George Hunt // copyright 2019 George Hunt
// CAUTION -- this file is duplicate to admin-console/console/files/js/osm_fuctions.js -- please think of admin-console as authoritative // CAUTION -- this file is duplicate to admin-console/console/files/js/map_fuctions.js -- please think of admin-console as authoritative
// Placed here in duplicate to ease debugging, and simplify dependences // Placed here in duplicate to ease debugging, and simplify dependences
var regionGeojson = {}; var regionGeojson = {};
var regionList = []; var regionList = [];
var regionInstalled = []; var regionInstalled = [];
var commonAssetsDir = '/common/assets/'; var commonAssetsDir = '/common/assets/';
var mapAssetsDir = '/osm-vector/maplist/assets/'; var mapAssetsDir = '/osm-vector-maps/maplist/assets/';
var iiab_config_dir = '/etc/iiab/'; var iiab_config_dir = '/etc/iiab/';
var onChangeFunc = "setSize"; var onChangeFunc = "setSize";
var osmCatalog = {}; var mapCatalog = {};
// following 2 lines an experiment to see if test page and console can be common // following 2 lines an experiment to see if test page and console can be common
//var jquery = require("./assets/jquery.min"); //var jquery = require("./assets/jquery.min");
@ -19,7 +19,7 @@ var osmCatalog = {};
function getOsmStat(){ function getOsmStat(){
// called during the init // called during the init
console.log('in getOsmStat'); console.log('in getOsmStat');
readOsmCatalog( true ); // we want checkboxes readMapCatalog( true ); // we want checkboxes
readOsmIdx(); readOsmIdx();
} }
@ -27,25 +27,25 @@ function readOsmIdx(){
//consoleLog ("in readOsmIdx"); //consoleLog ("in readOsmIdx");
var resp = $.ajax({ var resp = $.ajax({
type: 'GET', type: 'GET',
url: consoleJsonDir + 'osm-vector-idx.json', url: consoleJsonDir + 'osm-vector-maps-idx.json',
dataType: 'json' dataType: 'json'
}) })
.done(function( data ) { .done(function( data ) {
osmInstalled = data['regions']; mapInstalled = data['regions'];
regionInstalled = []; regionInstalled = [];
for (region in data['regions']) { for (region in data['regions']) {
if (data['regions'].hasOwnProperty(region)) { if (data['regions'].hasOwnProperty(region)) {
regionInstalled.push(region); regionInstalled.push(region);
} }
} }
//consoleLog(osmInstalled + ''); //consoleLog(mapInstalled + '');
}) })
.fail(jsonErrhandler); .fail(jsonErrhandler);
return resp; return resp;
} }
function readOsmCatalog(checkbox){ function readMapCatalog(checkbox){
checkbox = checkbox || true; checkbox = checkbox || true;
console.log ("in readOsmCalalog"); console.log ("in readOsmCalalog");
regionList = []; regionList = [];
@ -56,11 +56,11 @@ function readOsmCatalog(checkbox){
}) })
.done(function( data ) { .done(function( data ) {
regionJson = data; regionJson = data;
osmCatalog = regionJson['regions']; mapCatalog = regionJson['regions'];
for(var key in osmCatalog){ for(var key in mapCatalog){
//console.log(key + ' ' + osmCatalog[key]['title']); //console.log(key + ' ' + mapCatalog[key]['title']);
osmCatalog[key]['name'] = key; mapCatalog[key]['name'] = key;
regionList.push(osmCatalog[key]); regionList.push(mapCatalog[key]);
} }
}) })
.fail(jsonErrhandler); .fail(jsonErrhandler);
@ -120,13 +120,13 @@ function genRegionItem(region,checkbox) {
function instOsmItem(name) { function instOsmItem(name) {
var command = "INST-OSM-VECT-SET"; var command = "INST-OSM-VECT-SET";
var cmd_args = {}; var cmd_args = {};
cmd_args['osm_vect_id'] = name; cmd_args['map_vect_id'] = name;
cmd = command + " " + JSON.stringify(cmd_args); cmd = command + " " + JSON.stringify(cmd_args);
sendCmdSrvCmd(cmd, genericCmdHandler); sendCmdSrvCmd(cmd, genericCmdHandler);
osmDownloading.push(name); mapDownloading.push(name);
if ( osmWip.indexOf(name) != -1 ) if ( mapWip.indexOf(name) != -1 )
osmWip.push(osmCatalog[name]); mapWip.push(mapCatalog[name]);
console.log('osmWip: ' + osmWip); console.log('mapWip: ' + mapWip);
return true; return true;
} }
@ -161,19 +161,19 @@ function updateOsmSpace(cb){
} }
function updateOsmSpaceUtil(region, checked){ function updateOsmSpaceUtil(region, checked){
var size = parseInt(osmCatalog[region].size); var size = parseInt(mapCatalog[region].size);
var modIdx = selectedOsmItems.indexOf(region); var modIdx = selectedOsmItems.indexOf(region);
if (checked){ if (checked){
if (regionInstalled.indexOf(region) == -1){ // only update if not already installed mods if (regionInstalled.indexOf(region) == -1){ // only update if not already installed mods
sysStorage.osm_selected_size += size; sysStorage.map_selected_size += size;
selectedOsmItems.push(region); selectedOsmItems.push(region);
} }
} }
else { else {
if (modIdx != -1){ if (modIdx != -1){
sysStorage.osm_selected_size -= size; sysStorage.map_selected_size -= size;
selectedOsmItems.splice(modIdx, 1); selectedOsmItems.splice(modIdx, 1);
} }
} }
@ -188,29 +188,29 @@ function totalSpace(){
$( ".extract" ).each(function(ind,elem){ $( ".extract" ).each(function(ind,elem){
var data = JSON.parse($(this).attr('data-region')); var data = JSON.parse($(this).attr('data-region'));
var region = data.name; var region = data.name;
var size = parseInt(osmCatalog[region]['size']); var size = parseInt(mapCatalog[region]['size']);
var chk = $( this ).find(':checkbox').prop("checked") == true; var chk = $( this ).find(':checkbox').prop("checked") == true;
if (chk && typeof size !== 'undefined') if (chk && typeof size !== 'undefined')
sum += size; sum += size;
}); });
var ksize = sum / 1000; var ksize = sum / 1000;
$( "#osmDiskSpace" ).html(readableSize(ksize)); $( "#mapDiskSpace" ).html(readableSize(ksize));
} }
$( '#instOsmRegion').on('click', function(evnt){ $( '#instOsmRegion').on('click', function(evnt){
readOsmCatalog(); readMapCatalog();
osm.render(); map.render();
}); });
*/ */
function renderOsm(){ function renderOsm(){
console.log('in renderOsm'); console.log('in renderOsm');
window.map.setTarget($("#osm-container")[0]); window.map.setTarget($("#map-container")[0]);
window.map.render(); window.map.render();
renderRegionList(true); renderRegionList(true);
} }
function initOsm(){ function initOsm(){
var dummy = 0; var dummy = 0;
sysStorage.osm_selected_size = 0; sysStorage.map_selected_size = 0;
$.when(readOsmCatalog(true)).then(renderRegionList); $.when(readMapCatalog(true)).then(renderRegionList);
} }

View file

@ -0,0 +1,4 @@
<head>
<meta http-equiv="refresh" content="0; URL=/osm-vector-maps/maplist/" />
</head>

View file

@ -0,0 +1,84 @@
- name: Make sure the osm-vector-maps directory exists
file:
path: '{{ vector_map_path }}/maplist/assets'
state: directory
owner: '{{ apache_user }}'
group: '{{ apache_user }}'
mode: '0755'
- name: Fetch the catalog for osm maps
get_url:
url: "{{ iiab_map_url }}/assets/regions.json"
dest: '{{ vector_map_path }}/maplist/assets/'
- name: Create a link to osm catalog in /common/assets
file:
src: "{{ vector_map_path }}/maplist/assets/regions.json"
dest: "{{ doc_root }}/common/assets/regions.json"
state: link
- name: Fetch the javascript bundle with openlayers for test page
get_url:
url: "{{ iiab_map_url }}/../main.js"
dest: '{{ vector_map_path }}/maplist/'
- name: Fetch the index.html for test page
template:
src: "index.html"
dest: '{{ vector_map_path }}/maplist/index.html'
# Bboxes (bounding boxes) are currently square. But geofabrik has non-rectangular bboxes.
# So bring the bounding box definition from cloud (bboxes.geojson is big)
- name: Fetch the bounding box description for osm maps
get_url:
url: "{{ iiab_map_url }}/assets/bboxes.geojson"
dest: '{{ vector_map_path }}/maplist/assets/'
- name: Install python-geojson package, that helps with geojson
package:
name: python-geojson
state: present
- name: Install the script to update osm catalog
template:
src: iiab-update-map
dest: /usr/bin/iiab-update-map
mode: "0755"
- name: Run the script that does osm-vector-maps housekeeping
shell: /usr/bin/iiab-update-map
- name: Copy the Countries geojson to assets
copy:
src: countries.json
dest: '{{ vector_map_path }}/maplist/assets'
# It is too complicated to use a single file for both iiab and admin-console
- name: Copy the duplicated javascript to assets
copy:
src: map_functions.js
dest: '{{ vector_map_path }}/maplist/assets'
- name: Install /etc/{{ apache_config_dir }}/osm-vector-maps.conf from template
template:
src: osm-vector-maps.conf
dest: "/etc/{{ apache_config_dir }}/osm-vector-maps.conf"
- name: Create symlink osm-vector-maps.conf from sites-enabled to sites-available (debuntu, not nec for redhat)
file:
src: /etc/apache2/sites-available/osm-vector-maps.conf
path: /etc/apache2/sites-enabled/osm-vector-maps.conf
state: link
when: osm_vector_maps_enabled and is_debuntu
- name: Remove symlink /etc/apache2/sites-enabled/osm-vector-maps.conf (debuntu)
file:
path: /etc/apache2/sites-enabled/osm-vector-maps.conf
state: absent
when: not osm_vector_maps_enabled and is_debuntu
- name: Copy the redirect to the test page -- delete this if more than one map
copy:
src: test-index.redirect
dest: "{{ vector_map_path }}/index.html"

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# Scan the osm-vector directory, update the osm-vector-idx.json, add menu-defs # Scan the osm-vector-maps directory, update the osm-vector-maps-idx.json, add menu-defs
from geojson import Feature, Point, FeatureCollection, Polygon from geojson import Feature, Point, FeatureCollection, Polygon
import geojson import geojson
@ -25,9 +25,9 @@ else:
doc_root = get_iiab_env('WWWROOT') doc_root = get_iiab_env('WWWROOT')
menuDefs = doc_root + "/js-menu/menu-files/menu-defs/" menuDefs = doc_root + "/js-menu/menu-files/menu-defs/"
osm_vector_idx_dir = doc_root + "/common/assets" vector_map_idx_dir = doc_root + "/common/assets"
#map_doc_root = '{{ osm_vector_path }}' #map_doc_root = '{{ vector_map_path }}'
map_doc_root = '/library/www/osm-vector' map_doc_root = '/library/www/osm-vector-maps'
# map_catalog will be global, assumed always available # map_catalog will be global, assumed always available
map_catalog = {} map_catalog = {}
map_menu_def_list = [] map_menu_def_list = []
@ -43,7 +43,7 @@ def main():
installed_maps = get_installed_regions() installed_maps = get_installed_regions()
print(installed_maps) print(installed_maps)
write_osm_vector_idx(installed_maps) write_vector_map_idx(installed_maps)
# For installed regions, check that a menu def exists, and it's on home page # For installed regions, check that a menu def exists, and it's on home page
for fname in installed_maps: for fname in installed_maps:
@ -106,7 +106,7 @@ def get_installed_regions():
installed.append('maplist') installed.append('maplist')
return installed return installed
def write_osm_vector_idx(installed_maps): def write_vector_map_idx(installed_maps):
map_dict ={} map_dict ={}
idx_dict = {} idx_dict = {}
for fname in installed_maps: for fname in installed_maps:
@ -125,7 +125,7 @@ def write_osm_vector_idx(installed_maps):
idx_dict[item]['region'] = region idx_dict[item]['region'] = region
idx_dict[item]['language'] = map_dict['perma_ref'][:2] idx_dict[item]['language'] = map_dict['perma_ref'][:2]
with open(osm_vector_idx_dir + '/osm_version_idx.json','w') as idx: with open(vector_map_idx_dir + '/osm_version_idx.json','w') as idx:
idx.write(json.dumps(idx_dict,indent=2)) idx.write(json.dumps(idx_dict,indent=2))
def create_menu_def(region,default_name,intended_use='map'): def create_menu_def(region,default_name,intended_use='map'):

View file

@ -46,12 +46,12 @@
return (bytes / Math.pow(1024, e)).toFixed(2) + " " + s[e]; return (bytes / Math.pow(1024, e)).toFixed(2) + " " + s[e];
} }
</script> </script>
<script src="/osm-vector/maplist/assets/osm_functions.js"></script> <script src="/osm-vector-maps/maplist/assets/map_functions.js"></script>
<script> <script>
window.$ = window.$ = jQuery; window.$ = window.$ = jQuery;
$.when(readOsmCatalog()).done(function() { $.when(readMapCatalog()).done(function() {
renderRegionList(false); renderRegionList(false);
}); });
</script> </script>
<script type="text/javascript" src="/osm-vector/maplist/main.js"></script></body> <script type="text/javascript" src="/osm-vector-maps/maplist/main.js"></script></body>
</html> </html>

View file

@ -1,7 +1,7 @@
# For downloadable regional vector tilesets # For downloadable regional vector tilesets
Alias /maps {{ osm_vector_path }} Alias /maps {{ vector_map_path }}
Alias /osm-vector {{ osm_vector_path }} Alias /osm-vector-maps {{ vector_map_path }}
<Directory {{ osm_vector_path }}> <Directory {{ vector_map_path }}>
Options Indexes FollowSymLinks Options Indexes FollowSymLinks
AllowOverride All AllowOverride All
Require all granted Require all granted

View file

@ -1,9 +0,0 @@
osm_vector_install: True
osm_vector_enabled: True
osm_vector_path: '{{ content_base }}/www/osm-vector'
# All above are set in: github.com/iiab/iiab/blob/master/vars/default_vars.yml
# If nec, change them by editing /etc/iiab/local_vars.yml prior to installing!
menu_def_dir: '{{ doc_root }}/js-menu/menu-files/menu-defs'
iiab_osm_url : http://download.iiab.io/content/OSM/vector-tiles/maplist/hidden

View file

@ -1,4 +0,0 @@
<head>
<meta http-equiv="refresh" content="0; URL=/osm-vector/maplist/" />
</head>

View file

@ -1,100 +0,0 @@
- name: Make sure the osm-vector directory exists
file:
path: '{{ osm_vector_path }}/maplist/assets'
state: directory
owner: '{{ apache_user }}'
group: '{{ apache_user }}'
mode: '0755'
- name: Fetch the catalog for osm maps
get_url:
url: "{{ iiab_osm_url }}/assets/regions.json"
dest: '{{ osm_vector_path }}/maplist/assets/'
- name: Create a link to osm catalog in /common/assets
file:
src: "{{ osm_vector_path }}/maplist/assets/regions.json"
dest: "{{ doc_root }}/common/assets/regions.json"
state: link
- name: Fetch the javascript bundle with openlayers for test page
get_url:
url: "{{ iiab_osm_url }}/../main.js"
dest: '{{ osm_vector_path }}/maplist/'
- name: Fetch the index.html for test page
template:
src: "index.html"
dest: '{{ osm_vector_path }}/maplist/index.html'
# Bboxes (bounding boxes) are currently square. But geofabrik has non-rectangular bboxes.
# So bring the bounding box definition from cloud (bboxes.geojson is big)
- name: Fetch the bounding box description for osm maps
get_url:
url: "{{ iiab_osm_url }}/assets/bboxes.geojson"
dest: '{{ osm_vector_path }}/maplist/assets/'
- name: Install python-geojson package, that helps with geojson
package:
name: python-geojson
state: present
- name: Install the script to update osm catalog
template:
src: iiab-update-osm
dest: /usr/bin/iiab-update-osm
mode: "0755"
- name: Run the script that does osm-vector housekeeping
shell: /usr/bin/iiab-update-osm
- name: Copy the Countries geojson to assets
copy:
src: countries.json
dest: '{{ osm_vector_path }}/maplist/assets'
# It is too complicated to use a single file for both iiab and admin-console
- name: Copy the duplicated javascript to assets
copy:
src: osm_functions.js
dest: '{{ osm_vector_path }}/maplist/assets'
- name: Install /etc/{{ apache_config_dir }}/osm-vect.conf from template
template:
src: osm-vector.conf
dest: "/etc/{{ apache_config_dir }}/osm-vector.conf"
- name: Create symlink osm-vector.conf from sites-enabled to sites-available (debuntu, not nec for redhat)
file:
src: /etc/apache2/sites-available/osm-vector.conf
path: /etc/apache2/sites-enabled/osm-vector.conf
state: link
when: osm_vector_enabled and is_debuntu
- name: Remove symlink /etc/apache2/sites-enabled/osm-vector.conf (debuntu)
file:
path: /etc/apache2/sites-enabled/osm-vector.conf
state: absent
when: not osm_vector_enabled and is_debuntu
- name: Copy the redirect to the test page -- delete this if more than one map
copy:
src: test-index.redirect
dest: "{{ osm_vector_path }}/index.html"
- name: Create a directory for map menu-def
file:
path: '{{ menu_def_dir }}'
state: directory
- name: Determine status of splash menu def
stat:
path: '{{ menu_def_dir }}/en-map_test.json'
ignore_errors: True
register: menu_def
- name: Do not overwrite if it already exists
copy:
src: en-map_test.json
dest: '{{ menu_def_dir }}/en-map_test.json'
when: menu_def.stat.exists is defined and not menu_def.stat.exists

View file

@ -15,7 +15,7 @@ pip_packages_dir: "{{ iiab_base }}/pip-packages"
yum_packages_dir: "{{ iiab_base }}/yum-packages" yum_packages_dir: "{{ iiab_base }}/yum-packages"
downloads_dir: "{{ iiab_base }}/downloads" downloads_dir: "{{ iiab_base }}/downloads"
iiab_download_url: http://download.iiab.io/packages iiab_download_url: http://download.iiab.io/packages
iiab_osm_url : http://download.iiab.io/content/OSM/vector-tiles/maplist/hidden iiab_map_url : http://download.iiab.io/content/OSM/vector-tiles/maplist/hidden
content_base: "/library" content_base: "/library"
doc_base: "{{ content_base }}/www" doc_base: "{{ content_base }}/www"
@ -352,9 +352,9 @@ mongodb_enabled: False
mongodb_port: 27018 mongodb_port: 27018
# Regional OSM vector maps use much less disk space than bitmap/raster versions # Regional OSM vector maps use much less disk space than bitmap/raster versions
osm_vector_install: True osm_vector_maps_install: True
osm_vector_enabled: True osm_vector_maps_enabled: True
osm_vector_path: '{{ content_base }}/www/osm-vector' vector_map_path: '{{ content_base }}/www/osm-vector-maps'
# roles/sugarizer/meta/main.yml auto-invokes 2 above prereqs: mongodb & nodejs # roles/sugarizer/meta/main.yml auto-invokes 2 above prereqs: mongodb & nodejs
# Might stall MongoDB on Power Failure: github.com/xsce/xsce/issues/879 # Might stall MongoDB on Power Failure: github.com/xsce/xsce/issues/879

View file

@ -230,8 +230,8 @@ moodle_enabled: True
# If using Moodle intensively, set apache_high_php_limits in 3-BASE-SERVER # If using Moodle intensively, set apache_high_php_limits in 3-BASE-SERVER
# Regional OSM vector maps use much less disk space than bitmap/raster versions # Regional OSM vector maps use much less disk space than bitmap/raster versions
osm_vector_install: True osm_vector_maps_install: True
osm_vector_enabled: True osm_vector_maps_enabled: True
# Might stall MongoDB on Power Failure: github.com/xsce/xsce/issues/879 # Might stall MongoDB on Power Failure: github.com/xsce/xsce/issues/879
# Sugarizer 1.0.1+ strategies to solve? github.com/iiab/iiab/pull/957 # Sugarizer 1.0.1+ strategies to solve? github.com/iiab/iiab/pull/957

View file

@ -230,8 +230,8 @@ moodle_enabled: False
# If using Moodle intensively, set apache_high_php_limits in 3-BASE-SERVER # If using Moodle intensively, set apache_high_php_limits in 3-BASE-SERVER
# Regional OSM vector maps use much less disk space than bitmap/raster versions # Regional OSM vector maps use much less disk space than bitmap/raster versions
osm_vector_install: True osm_vector_maps_install: True
osm_vector_enabled: True osm_vector_maps_enabled: True
# Might stall MongoDB on Power Failure: github.com/xsce/xsce/issues/879 # Might stall MongoDB on Power Failure: github.com/xsce/xsce/issues/879
# Sugarizer 1.0.1+ strategies to solve? github.com/iiab/iiab/pull/957 # Sugarizer 1.0.1+ strategies to solve? github.com/iiab/iiab/pull/957

View file

@ -230,8 +230,8 @@ moodle_enabled: False
# If using Moodle intensively, set apache_high_php_limits in 3-BASE-SERVER # If using Moodle intensively, set apache_high_php_limits in 3-BASE-SERVER
# Regional OSM vector maps use much less disk space than bitmap/raster versions # Regional OSM vector maps use much less disk space than bitmap/raster versions
osm_vector_install: True osm_vector_maps_install: True
osm_vector_enabled: True osm_vector_maps_enabled: True
# Might stall MongoDB on Power Failure: github.com/xsce/xsce/issues/879 # Might stall MongoDB on Power Failure: github.com/xsce/xsce/issues/879
# Sugarizer 1.0.1+ strategies to solve? github.com/iiab/iiab/pull/957 # Sugarizer 1.0.1+ strategies to solve? github.com/iiab/iiab/pull/957