-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wires up e2e, exposing a problem with the route snapper geometry
- Loading branch information
1 parent
4959b86
commit 9a3fd90
Showing
4 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::collections::HashSet; | ||
|
||
use anyhow::Result; | ||
use geo::{Contains, Polygon}; | ||
use geojson::GeoJson; | ||
|
||
use crate::{MapModel, RoadID}; | ||
|
||
pub struct Neighbourhood { | ||
interior_roads: HashSet<RoadID>, | ||
} | ||
|
||
impl Neighbourhood { | ||
pub fn new(map: &MapModel, boundary: Polygon) -> Result<Self> { | ||
let mut interior_roads = HashSet::new(); | ||
for r in &map.roads { | ||
if boundary.contains(&r.linestring) { | ||
interior_roads.insert(r.id); | ||
} | ||
} | ||
|
||
if interior_roads.is_empty() { | ||
bail!("No roads inside the boundary"); | ||
} | ||
|
||
Ok(Self { interior_roads }) | ||
} | ||
|
||
pub fn to_gj(&self, map: &MapModel) -> GeoJson { | ||
let mut features = Vec::new(); | ||
|
||
for r in &self.interior_roads { | ||
let mut f = map.roads[r.0].to_gj(&map.mercator); | ||
f.set_property("kind", "interior_road"); | ||
features.push(f); | ||
} | ||
|
||
GeoJson::from(features) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
<script lang="ts"> | ||
import { MapModel } from "backend"; | ||
import type { Feature, Polygon } from "geojson"; | ||
import { FillLayer, GeoJSON } from "svelte-maplibre"; | ||
import { FillLayer, GeoJSON, LineLayer, Popup } from "svelte-maplibre"; | ||
import { constructMatchExpression, PropertiesTable } from "./common"; | ||
export let model: MapModel; | ||
export let boundary: Feature<Polygon>; | ||
let details = JSON.parse(model.analyzeNeighbourhood(boundary)); | ||
</script> | ||
|
||
<GeoJSON data={boundary}> | ||
<FillLayer | ||
paint={{ | ||
"fill-color": "black", | ||
"fill-opacity": 0.5, | ||
"fill-opacity": 0.2, | ||
}} | ||
/> | ||
</GeoJSON> | ||
|
||
<GeoJSON data={details}> | ||
<LineLayer | ||
paint={{ | ||
"line-width": 5, | ||
"line-color": constructMatchExpression( | ||
["get", "kind"], | ||
{ | ||
interior_road: "black", | ||
}, | ||
"red" | ||
), | ||
}} | ||
on:click={(e) => window.open(e.detail.features[0].properties.way, "_blank")} | ||
hoverCursor="pointer" | ||
> | ||
<Popup openOn="hover" let:data> | ||
<PropertiesTable properties={data.properties} /> | ||
</Popup> | ||
</LineLayer> | ||
</GeoJSON> |