mirror of
https://github.com/iiab/iiab.git
synced 2025-03-09 15:40:17 +00:00
change directory name
This commit is contained in:
parent
ba07100220
commit
612032da31
10 changed files with 0 additions and 0 deletions
189
roles/osm-vector-maps/templates/iiab-update-map
Executable file
189
roles/osm-vector-maps/templates/iiab-update-map
Executable file
|
@ -0,0 +1,189 @@
|
|||
#!/usr/bin/env python
|
||||
# Scan the osm-vector-maps directory, update the osm-vector-maps-idx.json, add menu-defs
|
||||
|
||||
from geojson import Feature, Point, FeatureCollection, Polygon
|
||||
import geojson
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import fnmatch
|
||||
import re
|
||||
|
||||
IIAB_PATH='/etc/iiab'
|
||||
if not IIAB_PATH in sys.path:
|
||||
sys.path.append(IIAB_PATH)
|
||||
from iiab_env import get_iiab_env
|
||||
|
||||
SCRIPT_DIR = '/opt/admin/cmdsrv/scripts'
|
||||
if not SCRIPT_DIR in sys.path:
|
||||
sys.path.append(SCRIPT_DIR)
|
||||
if os.path.exists(os.path.join(SCRIPT_DIR,'iiab_update_menus.py')):
|
||||
import iiab_update_menus as menus
|
||||
console_installed = True
|
||||
else:
|
||||
console_installed = False
|
||||
|
||||
doc_root = get_iiab_env('WWWROOT')
|
||||
menuDefs = doc_root + "/js-menu/menu-files/menu-defs/"
|
||||
vector_map_idx_dir = doc_root + "/common/assets"
|
||||
#map_doc_root = '{{ vector_map_path }}'
|
||||
map_doc_root = '/library/www/osm-vector-maps'
|
||||
# map_catalog will be global, assumed always available
|
||||
map_catalog = {}
|
||||
map_menu_def_list = []
|
||||
|
||||
def main():
|
||||
global map_menu_def_list
|
||||
get_map_catalog()
|
||||
#print(json.dumps(map_catalog,indent=2))
|
||||
|
||||
map_menu_def_list = get_menu_def_names()
|
||||
print(json.dumps(map_menu_def_list,indent=2))
|
||||
|
||||
installed_maps = get_installed_regions()
|
||||
print(installed_maps)
|
||||
|
||||
write_vector_map_idx(installed_maps)
|
||||
|
||||
# For installed regions, check that a menu def exists, and it's on home page
|
||||
for fname in installed_maps:
|
||||
region = extract_region_from_filename(fname)
|
||||
print('checking for %s region'%region)
|
||||
if region == 'maplist': # it is the splash page, display only if no others
|
||||
menu_ref = 'en-map_test'
|
||||
item = { "perma_ref" : "en-map_test" }
|
||||
if len(installed_maps) == 1:
|
||||
menus.update_menu_json(menu_ref)
|
||||
return
|
||||
else:
|
||||
item = map_catalog['regions'][region]
|
||||
menu_ref = item['perma_ref']
|
||||
if not (region in map_menu_def_list):
|
||||
print('creating menu def for %s'%item['perma_ref'])
|
||||
create_menu_def(region,item['perma_ref'] + '.json')
|
||||
if fetch_menu_json_value('autoupdate_menu'):
|
||||
print('autoudate of menu items is enabled:%s. Adding %s'%(\
|
||||
fetch_menu_json_value('autoupdate_menu'),region,))
|
||||
# verify this menu def is on home page
|
||||
menus.update_menu_json(menu_ref)
|
||||
|
||||
def get_map_catalog():
|
||||
global map_catalog
|
||||
input_json = map_doc_root + '/maplist/assets/regions.json'
|
||||
with open(input_json,'r') as regions:
|
||||
reg_str = regions.read()
|
||||
map_catalog = json.loads(reg_str)
|
||||
#print(json.dumps(map_catalog,indent=2))
|
||||
|
||||
def get_menu_def_names(intended_use='map'):
|
||||
menu_def_list =[]
|
||||
os.chdir(menuDefs)
|
||||
for filename in os.listdir('.'):
|
||||
if fnmatch.fnmatch(filename, '*.json'):
|
||||
try:
|
||||
with open(filename,'r') as json_file:
|
||||
readstr = json_file.read()
|
||||
data = json.loads(readstr)
|
||||
except:
|
||||
print("failed to parse %s"%filename)
|
||||
print(readstr)
|
||||
if data.get('intended_use','') != intended_use:
|
||||
continue
|
||||
map_name = data.get('name','')
|
||||
if map_name != '':
|
||||
menu_def_list.append(data['name'])
|
||||
return menu_def_list
|
||||
|
||||
def get_installed_regions():
|
||||
installed = []
|
||||
os.chdir(map_doc_root)
|
||||
for filename in os.listdir('.'):
|
||||
if fnmatch.fnmatch(filename, '??-osm-omt*'):
|
||||
region = re.sub(r'^..-osm-omt_(.*)',r'\1',filename)
|
||||
installed.append(region)
|
||||
# add the splash page if no other maps are present
|
||||
if len(installed) == 0:
|
||||
installed.append('maplist')
|
||||
return installed
|
||||
|
||||
def write_vector_map_idx(installed_maps):
|
||||
map_dict ={}
|
||||
idx_dict = {}
|
||||
for fname in installed_maps:
|
||||
region = extract_region_from_filename(fname)
|
||||
if map == 'maplist': continue # not a real region
|
||||
map_dict = map_catalog['regions'].get(region,'')
|
||||
if map_dict == '': continue
|
||||
|
||||
# Create the idx file in format required bo js-menu system
|
||||
item = map_dict['perma_ref']
|
||||
idx_dict[item] = {}
|
||||
idx_dict[item]['file_name'] = os.path.basename(map_dict['url'][:-4])
|
||||
idx_dict[item]['menu_item'] = map_dict['perma_ref']
|
||||
idx_dict[item]['size'] = map_dict['size']
|
||||
idx_dict[item]['date'] = map_dict['date']
|
||||
idx_dict[item]['region'] = region
|
||||
idx_dict[item]['language'] = map_dict['perma_ref'][:2]
|
||||
|
||||
with open(vector_map_idx_dir + '/osm_version_idx.json','w') as idx:
|
||||
idx.write(json.dumps(idx_dict,indent=2))
|
||||
|
||||
def create_menu_def(region,default_name,intended_use='map'):
|
||||
item = map_catalog['regions'][region]
|
||||
if len(item.get('language','')) > 2:
|
||||
lang = item['language'][:2]
|
||||
else: # default to english
|
||||
lang = 'en'
|
||||
filename = lang + '-' + item['perma_ref'] + '.json'
|
||||
# create a stub for this zim
|
||||
menuDef = {}
|
||||
default_logo = 'osm.jpg'
|
||||
menuDef["intended_use"] = "map"
|
||||
menuDef["lang"] = lang
|
||||
menuDef["logo_url"] = default_logo
|
||||
menuitem = lang + '-' + item['perma_ref']
|
||||
menuDef["menu_item_name"] = default_name
|
||||
menuDef["title"] = "OpenStreetMap: 18 Levels of Zoom for <b> " + item.get('title','ERROR') + '</b>'
|
||||
menuDef["map_name"] = item['perma_ref']
|
||||
menuDef["file_name"] = lang + '-osm-omt_' + region + '_' + \
|
||||
os.path.basename(item['url'])[:-4]
|
||||
menuDef["description"] = '<p>Resolution of the Whole World to 5 KM. OpenStreetMap data for <b>' + item.get('title','') + '</b> with details down to 5 Meters</p>'
|
||||
menuDef["extra_html"] = ""
|
||||
menuDef["automatically_generated"] = "true"
|
||||
if not os.path.isfile(menuDefs + default_name): # logic to here can still overwrite existing menu def
|
||||
print("creating %s"%menuDefs + default_name)
|
||||
with open(menuDefs + default_name,'w') as menufile:
|
||||
menufile.write(json.dumps(menuDef,indent=2))
|
||||
return default_name[:-5]
|
||||
|
||||
def human_readable(num):
|
||||
# return 3 significant digits and unit specifier
|
||||
num = float(num)
|
||||
units = [ '','K','M','G']
|
||||
for i in range(4):
|
||||
if num<10.0:
|
||||
return "%.2f%s"%(num,units[i])
|
||||
if num<100.0:
|
||||
return "%.1f%s"%(num,units[i])
|
||||
if num < 1000.0:
|
||||
return "%.0f%s"%(num,units[i])
|
||||
num /= 1000.0
|
||||
|
||||
def fetch_menu_json_value(key):
|
||||
with open( doc_root + '/home/menu.json','r') as menudef:
|
||||
data = json.loads(menudef.read())
|
||||
return data.get(key,'')
|
||||
|
||||
def extract_region_from_filename(fname):
|
||||
substitutions = { "north": "north_america",\
|
||||
"central": "central_america",\
|
||||
"southeast": "southeast_asia",
|
||||
"south": "south_america" }
|
||||
# wish I had used - as separator between key and date
|
||||
nibble = fname.split('_')[0]
|
||||
nibble = substitutions.get(nibble,nibble)
|
||||
return(nibble)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if console_installed:
|
||||
main()
|
57
roles/osm-vector-maps/templates/index.html
Normal file
57
roles/osm-vector-maps/templates/index.html
Normal file
|
@ -0,0 +1,57 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Osm-Vector Splash Page</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- Bootstrap -->
|
||||
<link href="/common/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script src='/common/js/jquery.min.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
<h2>Vector Maps Test Page -- Use The Admin Console to Download a Selected Region</h2>
|
||||
<p>The IIAB vector maps are based upon OpenStreetMap Data. Each map has general geographic information that covers the <b>whole world </b>with a resolution of about 5 KM. The detailed regions provide data about items that are 5 meters apart. </p>
|
||||
<div class="row">
|
||||
<div class="col-sm-12"><a href="/admin"><button id="INST-MODS" type="button" class="btn btn-lg btn-primary">Go To Admin Console</button></a></div>
|
||||
</div>
|
||||
|
||||
<div id="osmRegionSelection" >
|
||||
<style>
|
||||
#map-container{
|
||||
background-color: #b2d3f8;
|
||||
float: right;
|
||||
width: 70%;
|
||||
right: 10px;
|
||||
height: 500px;
|
||||
}
|
||||
body {
|
||||
padding: 40px;
|
||||
}
|
||||
</style>
|
||||
<div id="map-container"></div>
|
||||
|
||||
</div>
|
||||
<div id='regionlist'>placeholdr</div>
|
||||
</div> <!-- End instOsmRegion Submenu Option Pane -->
|
||||
<script>
|
||||
function readableSize(kbytes) {
|
||||
if (kbytes == 0)
|
||||
return "0";
|
||||
var bytes = 1024 * kbytes;
|
||||
var s = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'];
|
||||
var e = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
return (bytes / Math.pow(1024, e)).toFixed(2) + " " + s[e];
|
||||
}
|
||||
</script>
|
||||
<script src="/osm-vector-maps/maplist/assets/map_functions.js"></script>
|
||||
<script>
|
||||
window.$ = window.$ = jQuery;
|
||||
$.when(readMapCatalog()).done(function() {
|
||||
renderRegionList(false);
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" src="/osm-vector-maps/maplist/main.js"></script></body>
|
||||
</html>
|
89
roles/osm-vector-maps/templates/main.js
Normal file
89
roles/osm-vector-maps/templates/main.js
Normal file
|
@ -0,0 +1,89 @@
|
|||
import {Fill, Stroke, Style} from 'ol/style';
|
||||
import 'ol/ol.css';
|
||||
import GeoJSON from 'ol/format/GeoJSON';
|
||||
import Map from 'ol/Map';
|
||||
import VectorLayer from 'ol/layer/Vector';
|
||||
import VectorSource from 'ol/source/Vector';
|
||||
import View from 'ol/View';
|
||||
//import XYZSource from 'ol/source/XYZ';
|
||||
//import MVT from 'ol/format/MVT';
|
||||
|
||||
// a global variable to control which features are shown
|
||||
var show = {};
|
||||
var mapData = "/common/assets";
|
||||
|
||||
|
||||
var map = new Map({
|
||||
target: 'map-container',
|
||||
layers: [
|
||||
new VectorLayer({
|
||||
source: new VectorSource({
|
||||
format: new GeoJSON(),
|
||||
url: mapData + '/countries.json'
|
||||
}),
|
||||
style: new Style({
|
||||
fill: new Fill({
|
||||
color: 'rgb(219, 180, 131)'
|
||||
}),
|
||||
stroke: new Stroke({
|
||||
color: 'white'
|
||||
})
|
||||
})
|
||||
}),
|
||||
|
||||
],
|
||||
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 2
|
||||
})
|
||||
});
|
||||
|
||||
var setBoxStyle = function(feature) {
|
||||
var name = feature.get("name");
|
||||
//alert(keys+'');
|
||||
if (typeof show !== 'undefined' &&
|
||||
show != null && name == show) {
|
||||
return new Style({
|
||||
fill: new Fill({
|
||||
color: 'rgba(67, 163, 46, 0.2)'
|
||||
}),
|
||||
stroke: new Stroke({
|
||||
color: 'rgba(67, 163, 46, 1)',
|
||||
width: 2
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return new Style({
|
||||
fill: new Fill({
|
||||
color: 'rgba(255,255,255,.10)'
|
||||
}),
|
||||
stroke: new Stroke({
|
||||
color: 'rgba(255,255,255,.3)'
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var boxLayer = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
format: new GeoJSON(),
|
||||
url: mapData + '/bboxes.geojson'
|
||||
}),
|
||||
id: 'boxes',
|
||||
style: setBoxStyle
|
||||
});
|
||||
map.addLayer(boxLayer);
|
||||
|
||||
$( document ).on("mouseover",".extract",function(){
|
||||
|
||||
var data = JSON.parse($(this).attr('data-region'));
|
||||
show = data.name;
|
||||
//setBoxStyle();
|
||||
boxLayer.changed();
|
||||
});
|
||||
$( document ).on("mouseout",".extract",function(){
|
||||
var data = JSON.parse($(this).attr('data-region'));
|
||||
show = '';
|
||||
boxLayer.changed();
|
||||
});
|
8
roles/osm-vector-maps/templates/vector-maps.conf
Normal file
8
roles/osm-vector-maps/templates/vector-maps.conf
Normal file
|
@ -0,0 +1,8 @@
|
|||
# For downloadable regional vector tilesets
|
||||
Alias /maps {{ vector_map_path }}
|
||||
Alias /osm-vector-maps {{ vector_map_path }}
|
||||
<Directory {{ vector_map_path }}>
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
Loading…
Add table
Add a link
Reference in a new issue