-
Notifications
You must be signed in to change notification settings - Fork 16
/
osm-vect_v2_finish_install.py
executable file
·103 lines (83 loc) · 2.96 KB
/
osm-vect_v2_finish_install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import argparse
import sys, os
import json
import glob
import shutil
import json
import iiab.iiab_lib as iiab
import iiab.adm_lib as adm
# GLOBALS
viewer_path = adm.CONST.map_doc_root + '/viewer'
vector_map_idx_dir = adm.CONST.vector_map_idx_dir
catalog_path = adm.CONST.common_assets_path + '/adm-map-catalog.json'
map_catalog = {}
base_catalog = {}
if len(sys.argv) != 2:
print("Argument 1=map_id")
sys.exit(1)
def main():
global map_catalog
global base_catalog
args = parse_args()
map_id = args.map_id
catalog = adm.read_json(catalog_path)
map_catalog = catalog['maps']
base_catalog = catalog['base']
#for k in catalog.keys():
#print(k)
is_map = map_id in map_catalog
is_base = map_id in base_catalog
if not is_base and not is_map:
print('Download URL not found in Map Catalog: %s'%args.map_id)
sys.exit(1)
# create init.json which sets initial coords and zoom
if is_map:
init = {}
osm_map = map_catalog[map_id]
init['region'] = osm_map['region']
init['zoom'] = osm_map['zoom']
init['center_lon'] = osm_map['center_lon']
init['center_lat'] = osm_map['center_lat']
init_fn = viewer_path + '/init.json'
adm.write_json_file(init, init_fn)
installed_maps = get_installed_tiles()
print('installed_maps')
print(repr(installed_maps))
write_vector_map_idx_v2(installed_maps)
def get_installed_tiles():
installed_maps = []
tile_list = glob.glob(viewer_path + '/tiles/*')
for index in range(len(tile_list)):
#if tile_list[index].startswith('sat'): continue
#if tile_list[index].startswith('osm-planet_z0'): continue
installed_maps.append(os.path.basename(tile_list[index]))
return installed_maps
def write_vector_map_idx_v2(installed_maps):
# modified from adm_lib for new maps
catalog = map_catalog
catalog.update(base_catalog)
map_dict = {}
idx_dict = {}
for fname in installed_maps:
map_id = fname
map_dict = catalog.get(map_id, None)
if not map_dict : continue
# Create the idx file in format required by js-menu system
item = map_dict['perma_ref']
idx_dict[item] = {}
idx_dict[item]['file_name'] = fname # ? os.path.basename(map_dict['detail_url'])
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'] = map_dict['region']
#idx_dict[item]['language'] = map_dict['perma_ref'][:2]
idx_dict[item]['language'] = 'en'
adm.write_json_file(idx_dict, vector_map_idx_dir + '/vector-map-idx.json')
def parse_args():
parser = argparse.ArgumentParser(description="Create init.json for a tile URL.")
parser.add_argument("map_id", help="The key field in the Map Catalog.")
return parser.parse_args()
if __name__ == '__main__':
main()