Skip to content

Commit

Permalink
Try to animate line color changes, #46. I don't think it's possible,
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Apr 20, 2024
1 parent 2581a08 commit a4a63c6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ impl LTN {
)
}

#[wasm_bindgen(js_name = getShortcutList)]
pub fn get_shortcut_list(&self) -> Vec<usize> {
self.neighbourhood.as_ref().unwrap().get_shortcut_list()
}

/// Takes a name and boundary GJ polygon
#[wasm_bindgen(js_name = setNeighbourhoodBoundary)]
pub fn set_neighbourhood_boundary(
Expand Down
16 changes: 16 additions & 0 deletions backend/src/neighbourhood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,29 @@ impl Neighbourhood {
serde_json::json!({
"undo_length": map.undo_stack.len(),
"redo_length": map.redo_queue.len(),
// TODO why not max shortcuts here?
})
.as_object()
.unwrap()
.clone(),
),
}
}

pub fn get_shortcut_list(&self) -> Vec<usize> {
let derived = self.derived.as_ref().unwrap();
self.interior_roads
.iter()
.map(|r| {
derived
.shortcuts
.count_per_road
.get(r)
.cloned()
.unwrap_or(0)
})
.collect()
}
}

enum LineInPolygon {
Expand Down
7 changes: 5 additions & 2 deletions web/src/RenderNeighbourhood.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
[
"interpolate-hcl",
["linear"],
["get", "shortcuts"],
["feature-state", "cuts"],
0,
"white",
1,
Expand Down Expand Up @@ -67,7 +67,7 @@
}
</script>

<GeoJSON data={gj} generateId>
<GeoJSON data={gj} generateId id="render-nhood">
<GeoJSON data={invertBoundary(gj)}>
<FillLayer
{...layerId("neighbourhood-boundary")}
Expand All @@ -90,6 +90,9 @@
paint={{
"line-width": 10,
"line-color": lineColor,
"line-color-transition": {
delay: 600,
},
"line-opacity": hoverStateFilter(1.0, 0.5),
}}
on:click={(e) =>
Expand Down
17 changes: 17 additions & 0 deletions web/src/edit/NeighbourhoodMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@
undoLength = gjInput.undo_length;
redoLength = gjInput.redo_length;
if ($map.getSource("render-nhood")) {
console.log("changing feature state");
let shortcuts = $app!.getShortcutList();
for (let [idx, value] of shortcuts.entries()) {
//console.log(`confirming ${idx} is ${value}... ${gjInput.features[idx + 1].properties.shortcuts}`);
$map.setFeatureState(
{
id: idx + 1,
source: "render-nhood",
},
{ cuts: value },
);
}
} else {
console.log("source not there yet, hang on");
}
autosave();
}
Expand Down

0 comments on commit a4a63c6

Please sign in to comment.