Skip to content

Commit

Permalink
preparation for bigger changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kauevestena committed Jun 17, 2024
1 parent 3e4bddc commit e83b909
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 65 deletions.
6 changes: 6 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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'
Expand Down
60 changes: 0 additions & 60 deletions create_webmap_new.py

This file was deleted.

3 changes: 3 additions & 0 deletions todo
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 32 additions & 0 deletions webmap/create_webmap_new.py
Original file line number Diff line number Diff line change
@@ -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)
59 changes: 54 additions & 5 deletions webmap/webmap_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
</style>

<link rel="icon" type="image/x-icon" href="https://kauevestena.github.io/opensidewalkmap/assets/favicon_homepage.png">
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
<div id="style-changer">
<select id="style-selector"></select>
</div>
<div id="map"></div>
<script type="text/javascript">

// Global Control Variables
var hoveredStateId_OSWMProject = null;
Expand Down Expand Up @@ -104,7 +134,8 @@
},
trackUserLocation: true
}));






Expand Down Expand Up @@ -213,10 +244,28 @@
// // })
// // );


// // // // Dynamically populate the dropdown options
// // // const styleSelector = document.getElementById('style-selector');
// // // Object.keys(styles).forEach(styleKey => {
// // // const option = document.createElement('option');
// // // option.value = styleKey;
// // // option.textContent = styleKey;
// // // styleSelector.appendChild(option);
// // // });

// // // // Listen for style changes
// // // styleSelector.addEventListener('change', function (e) {
// // // const style = e.target.value;
// // // map.setStyle(styles[style]);
// // // });

// END of the big "then" statement:
});




</script>
</body>
</html>
56 changes: 56 additions & 0 deletions webmap/webmap_lib.py
Original file line number Diff line number Diff line change
@@ -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": '© <a href="https://openstreetmap.org">OpenStreetMap Contributors</a>'}

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

0 comments on commit e83b909

Please sign in to comment.