From e83b909e00c0b0a58d7b69b24e99590bc34b705b Mon Sep 17 00:00:00 2001 From: kauevestena Date: Mon, 17 Jun 2024 00:14:32 -0300 Subject: [PATCH] preparation for bigger changes --- constants.py | 6 ++++ create_webmap_new.py | 60 ------------------------------------- todo | 3 ++ webmap/create_webmap_new.py | 32 ++++++++++++++++++++ webmap/webmap_base.html | 59 ++++++++++++++++++++++++++++++++---- webmap/webmap_lib.py | 56 ++++++++++++++++++++++++++++++++++ 6 files changed, 151 insertions(+), 65 deletions(-) delete mode 100644 create_webmap_new.py create mode 100644 webmap/create_webmap_new.py create mode 100644 webmap/webmap_lib.py diff --git a/constants.py b/constants.py index 03f6b2d..e86ec92 100644 --- a/constants.py +++ b/constants.py @@ -40,6 +40,8 @@ 'pedestrian_areas' : {} #defined only by geometry type (Polygon,Multipolygon) } +other_footways_geometry_types = {k:'LineString' for k, v in other_footways_subcatecories.items()} +other_footways_geometry_types['pedestrian_areas'] = 'Polygon' # ogr2ogr path OGR2OGR_PATH = 'ogr2ogr' @@ -555,6 +557,10 @@ 'other_footways':['LineString','Polygon','MultiPolygon'] } +all_layers_geom_types = {k:v[0] for k,v in geom_type_dict.items()} +del all_layers_geom_types['other_footways'] +for subcategory in other_footways_geometry_types: + all_layers_geom_types[subcategory] = other_footways_geometry_types[subcategory] statistics_basepath = 'statistics' diff --git a/create_webmap_new.py b/create_webmap_new.py deleted file mode 100644 index 2f21507..0000000 --- a/create_webmap_new.py +++ /dev/null @@ -1,60 +0,0 @@ -from functions import * -import argparse - -# create a --development flag: -parser = argparse.ArgumentParser() -parser.add_argument('--development', action='store_true') -args = parser.parse_args() - -in_dev = args.development - -# first, reading the parameters -params = read_json(webmap_params_original_path) - -# then override: (TODO) - -# # generating the "sources" and layernames: -params['sources'] = {} -for layername in paths_dict['map_layers']: - params[f'{layername}_url'] = f'{node_homepage_url}data/tiles/{layername}.pmtiles' - - params['sources'][f'oswm_pmtiles_{layername}'] = { - "type": "vector", - "url": f"pmtiles://{params[f'{layername}_url']}", - "promoteId":"id", - "attribution": '© OpenStreetMap Contributors'} - -params['boundaries_url'] = f'{node_homepage_url}data/boundaries.geojson' - - -# basemap: -params['sources']['osm'] = { - "type": "raster", - "tiles": [BASEMAP_URL], -} - -# boundaries: -params['sources']['boundaries'] = { - "type": "geojson", - "data": params['boundaries_url'] -} - -# # # terrain: -# # params['sources']['terrain'] = { -# # "type": "raster-dem", -# # "url": "https://demotiles.maplibre.org/terrain-tiles/tiles.json", -# # "tileSize": 256 -# # } - -# reading the base html -webmap_html = file_as_string(webmap_base_path) - -# doing other stuff like insertions and nasty things (TODO): - -# finally generate the files: -str_to_file(webmap_html,webmap_path) -dump_json(params,webmap_params_path) - -# if we are in dev mode, also dump the original params: -if in_dev: - dump_json(params,webmap_params_original_path) \ No newline at end of file diff --git a/todo b/todo index 3ef0dbf..9b823ce 100644 --- a/todo +++ b/todo @@ -18,3 +18,6 @@ and routing streamlit demo [ ] change data updating to become the "data" module [ ] Styling stuff: [ ] put a faded color on indoor stuff +[ ] Elevation stuff: + [ ] Add elevation to the map + [ ] Integrate https://portal.opentopography.org/apidocs/#/Public/getGlobalDem diff --git a/webmap/create_webmap_new.py b/webmap/create_webmap_new.py new file mode 100644 index 0000000..5160a71 --- /dev/null +++ b/webmap/create_webmap_new.py @@ -0,0 +1,32 @@ +from webmap_lib import * +import argparse + +# create a --development flag: +parser = argparse.ArgumentParser() +parser.add_argument('--development', action='store_true') +args = parser.parse_args() + +in_dev = args.development + +# first, reading the parameters +params = read_json(webmap_params_original_path) + +# then override: (TODO) + +# # generating the "sources" and layernames: +params.update(get_sources(only_urls=True)) +sources = get_sources()['sources'] + + +# reading the base html +webmap_html = file_as_string(webmap_base_path) + +# doing other stuff like insertions and nasty things (TODO): + +# finally generate the files: +str_to_file(webmap_html,webmap_path) +dump_json(params,webmap_params_path) + +# if we are in dev mode, also dump the original params: +if in_dev: + dump_json(params,webmap_params_original_path) \ No newline at end of file diff --git a/webmap/webmap_base.html b/webmap/webmap_base.html index dce5846..d12dae3 100644 --- a/webmap/webmap_base.html +++ b/webmap/webmap_base.html @@ -18,15 +18,45 @@ margin: 0; } #map { - height:100%; width:100%; - } + position: absolute; + top: 0; + bottom: 0; + width: 100%; + } + + #style-changer { + position: absolute; + top: 10px; + right: 60px; /* Adjusted to avoid collision with the navigation control */ + background: #fff; + border: 1px solid rgba(0, 0, 0, 0.15); + border-radius: 4px; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.10); + z-index: 1; + } + #style-selector { + border: none; + padding: 10px; + border-radius: 4px; + background-color: #fff; + font-size: 14px; + cursor: pointer; + width: 100%; + } + #style-selector:focus { + outline: none; + border: none; + } -
- \ No newline at end of file diff --git a/webmap/webmap_lib.py b/webmap/webmap_lib.py new file mode 100644 index 0000000..f807cec --- /dev/null +++ b/webmap/webmap_lib.py @@ -0,0 +1,56 @@ +import sys +sys.path.append('oswm_codebase') +from functions import * + +# mapping geometry types to maplibre style +map_geom_type_mapping = { + 'Polygon':'fill', + 'LineString':'line', + 'Point':'circle', + 'MultiPolygon':'fill', + 'MultiLineString':'line', + 'MultiPoint':'circle' + } +layertypes_dict = { k: map_geom_type_mapping[v] for k,v in all_layers_geom_types.items() } + +def get_sources(terrain_url=None,only_urls=False): + ret = {} + ret['sources'] = {} + + for layername in paths_dict['map_layers']: + ret[f'{layername}_url'] = f'{node_homepage_url}data/tiles/{layername}.pmtiles' + + ret['sources'][f'oswm_pmtiles_{layername}'] = { + "type": "vector", + "url": f"pmtiles://{ret[f'{layername}_url']}", + "promoteId":"id", + "attribution": '© OpenStreetMap Contributors'} + + ret['boundaries_url'] = f'{node_homepage_url}data/boundaries.geojson' + + + # basemap: + ret['sources']['osm'] = { + "type": "raster", + "tiles": [BASEMAP_URL], + } + + # boundaries: + ret['sources']['boundaries'] = { + "type": "geojson", + "data": ret['boundaries_url'] + } + + if terrain_url: + # # # terrain: + ret['sources']['terrain'] = { + "type": "raster-dem", + "url": terrain_url, + "tileSize": 256 + } + + if only_urls: + del ret['sources'] + return ret + else: + return ret \ No newline at end of file