fix: make city static layer optional

This commit is contained in:
Matthieu Bessat 2024-07-04 19:27:24 +02:00
parent c54c4c4319
commit bb016884a3
4 changed files with 17 additions and 5 deletions

3
.env.example Normal file
View file

@ -0,0 +1,3 @@
OAUTH2_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OAUTH2_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

View file

@ -9,5 +9,8 @@ oauth2c \
--callback-tls-key "$(pwd)/tmp/domain.key" \
--auth-method "client_secret_basic" \
--response-types "code" --response-mode "query" \
"https://master.apis.dev.openstreetmap.org" \
"https://api.openstreetmap.org" \
| jq '{ osm_session: . }' > session.json
# at the end
# cp session.json ~/.local/share/bobosm/session.json

View file

@ -180,7 +180,7 @@ struct StaticLayers {
#[derive(Deserialize)]
struct Config {
static_layers: StaticLayers,
static_layers: Option<StaticLayers>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@ -191,7 +191,7 @@ struct OSMSession {
}
#[derive(Debug, Serialize, Deserialize)]
struct Session {
pub struct Session {
osm_session: Option<OSMSession>
}
@ -324,6 +324,7 @@ fn main() -> Result<()> {
write_session(&xdg_dirs, &(Session {
osm_session: None
})).context("Writing initial session")?;
println!("Wrote initial session");
}
let session = read_session(&xdg_dirs)
.context("Read user session")?;
@ -345,7 +346,6 @@ fn main() -> Result<()> {
}));
let layers: Arc<Mutex<Vec<Layer>>> = Arc::new(Mutex::new(vec![
load_static_cities_layer(&config.static_layers.base_data_path).context("Loading static cities layer")?,
// load_static_osm_layer("./data/centre_vernon.json").context("Loading static osm data")?,
// load_static_osm_layer("./data/ouest_aubevoye.json").context("Loading static osm data")?,
Layer {
@ -360,6 +360,12 @@ fn main() -> Result<()> {
name: "Dynamic data".to_string(),
}
]));
if let Some(static_layers) = config.static_layers {
println!("Loading static layers defined in config: {}", &static_layers.base_data_path);
let static_city_layer = load_static_cities_layer(&static_layers.base_data_path).context("Loading static cities layer")?;
let mut layers_mut_ref = layers.lock().unwrap();
layers_mut_ref.push(static_city_layer);
}
let _ = load_osm_data(
layers.clone(),
serde_json::from_str(

View file

@ -91,7 +91,7 @@ impl OSMApiClient {
pub fn from_session(session: Session) -> OSMApiClient {
OSMApiClient {
session: session.osm_session.unwrap(),
session: session.osm_session.expect("Did not found valid OSM Sesssion"),
agent: get_base_agent().build()
}
}