Skip to content

Commit af51138

Browse files
committed
Store study area boundary and name in savefiles also
1 parent cd2f784 commit af51138

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

backend/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ pub struct LTN {
4242
impl LTN {
4343
/// Call with bytes of an osm.pbf or osm.xml string
4444
#[wasm_bindgen(constructor)]
45-
pub fn new(input_bytes: &[u8]) -> Result<LTN, JsValue> {
45+
pub fn new(input_bytes: &[u8], study_area_name: Option<String>) -> Result<LTN, JsValue> {
4646
// Panics shouldn't happen, but if they do, console.log them.
4747
console_error_panic_hook::set_once();
4848
START.call_once(|| {
4949
console_log::init_with_level(log::Level::Info).unwrap();
5050
});
5151

52-
let map = MapModel::new(input_bytes).map_err(err_to_js)?;
52+
let map = MapModel::new(input_bytes, study_area_name).map_err(err_to_js)?;
5353
Ok(LTN {
5454
map,
5555
neighbourhood: None,

backend/src/map_model.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct MapModel {
1616
pub intersections: Vec<Intersection>,
1717
// All geometry stored in worldspace, including rtrees
1818
pub mercator: Mercator,
19+
pub study_area_name: Option<String>,
1920
pub boundary_polygon: Polygon,
2021

2122
// TODO Wasteful, can share some
@@ -67,8 +68,8 @@ pub struct Intersection {
6768

6869
impl MapModel {
6970
/// Call with bytes of an osm.pbf or osm.xml string
70-
pub fn new(input_bytes: &[u8]) -> Result<MapModel> {
71-
crate::scrape::scrape_osm(input_bytes)
71+
pub fn new(input_bytes: &[u8], study_area_name: Option<String>) -> Result<MapModel> {
72+
crate::scrape::scrape_osm(input_bytes, study_area_name)
7273
}
7374

7475
pub fn get_r(&self, r: RoadID) -> &Road {
@@ -241,6 +242,22 @@ impl MapModel {
241242
f.remove_property("road");
242243
}
243244
gj.features.extend(self.boundaries.values().cloned());
245+
246+
let mut f = Feature::from(Geometry::from(
247+
&self.mercator.to_wgs84(&self.boundary_polygon),
248+
));
249+
f.set_property("kind", "study_area_boundary");
250+
gj.features.push(f);
251+
252+
gj.foreign_members = Some(
253+
serde_json::json!({
254+
"study_area_name": self.study_area_name,
255+
})
256+
.as_object()
257+
.unwrap()
258+
.clone(),
259+
);
260+
244261
gj
245262
}
246263

backend/src/scrape.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct Way {
1212
tags: Tags,
1313
}
1414

15-
pub fn scrape_osm(input_bytes: &[u8]) -> Result<MapModel> {
15+
pub fn scrape_osm(input_bytes: &[u8], study_area_name: Option<String>) -> Result<MapModel> {
1616
let mut node_mapping = HashMap::new();
1717
let mut highways = Vec::new();
1818
osm_reader::parse(input_bytes, |elem| match elem {
@@ -62,6 +62,7 @@ pub fn scrape_osm(input_bytes: &[u8]) -> Result<MapModel> {
6262
intersections,
6363
mercator,
6464
boundary_polygon,
65+
study_area_name,
6566

6667
router_original,
6768
router_current,

web/src/NetworkMode.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import type { Feature } from "geojson";
33
import { FillLayer, GeoJSON, hoverStateFilter, Popup } from "svelte-maplibre";
4-
import { isPolygon, notNull } from "./common";
4+
import { notNull } from "./common";
55
import ManageSavefiles from "./ManageSavefiles.svelte";
66
import ModalFilterLayer from "./ModalFilterLayer.svelte";
77
import SplitComponent from "./SplitComponent.svelte";
@@ -76,7 +76,7 @@
7676
<div slot="map">
7777
<GeoJSON data={gj} generateId>
7878
<FillLayer
79-
filter={isPolygon}
79+
filter={["==", ["get", "kind"], "boundary"]}
8080
paint={{
8181
"fill-color": "red",
8282
"fill-opacity": hoverStateFilter(0.3, 0.5),

web/src/title/MapLoader.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
function loadMap(buffer: ArrayBuffer) {
3535
msg = "Building map model from OSM input";
3636
console.time("load");
37-
$app = new LTN(new Uint8Array(buffer));
37+
$app = new LTN(new Uint8Array(buffer), $example == "" ? undefined : $example);
3838
console.timeEnd("load");
3939
4040
// Autoload from local storage

0 commit comments

Comments
 (0)