Skip to content

Commit 93cac52

Browse files
committed
Add neighbourhoods from the auto-splits
1 parent c962b9f commit 93cac52

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

web/src/AutoBoundariesMode.svelte

+40-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,41 @@
55
GeoJSON,
66
LineLayer,
77
hoverStateFilter,
8+
type LayerClickInfo,
89
} from "svelte-maplibre";
910
import { Link, layerId } from "./common";
10-
import { notNull } from "svelte-utils";
1111
import { isLine } from "svelte-utils/map";
1212
import { SplitComponent } from "svelte-utils/top_bar_layout";
13-
import { app, mode } from "./stores";
13+
import { app, mode, autosave } from "./stores";
14+
15+
let gj = JSON.parse($app!.renderAutoBoundaries());
16+
17+
function add(e: CustomEvent<LayerClickInfo>) {
18+
let name = window.prompt("What do you want to name the neighbourhood?");
19+
if (!name) {
20+
return;
21+
}
22+
try {
23+
// TODO Waypoints will be missing; editing will not work
24+
let feature = {
25+
type: "Feature",
26+
properties: {},
27+
// Trust generateId to make IDs in order
28+
geometry: gj.features[e.detail.features[0].id!].geometry,
29+
};
30+
$app!.setNeighbourhoodBoundary(name, feature);
31+
autosave();
32+
$app!.setCurrentNeighbourhood(name);
33+
$mode = {
34+
mode: "neighbourhood",
35+
};
36+
} catch (err) {
37+
console.log(err);
38+
window.alert(
39+
"Known georust bug hit, sorry. You may need to just refresh the page now.",
40+
);
41+
}
42+
}
1443
</script>
1544

1645
<SplitComponent>
@@ -27,24 +56,31 @@
2756
Pick neighbourhood
2857
</Link>
2958
</li>
30-
<li>Generated boundaries (experiment)</li>
59+
<li>Use an auto-generated boundary</li>
3160
</ul>
3261
</nav>
3362
</div>
3463

3564
<div slot="sidebar">
3665
<BackButton on:click={() => ($mode = { mode: "network" })} />
66+
<p>
67+
Click an area to use it as a neighbourhood. These are generated by finding
68+
roads, railways, and water thatform severances. There are many bugs; this
69+
is experimental.
70+
</p>
3771
</div>
3872

3973
<div slot="map">
40-
<GeoJSON data={JSON.parse(notNull($app).renderAutoBoundaries())} generateId>
74+
<GeoJSON data={gj} generateId>
4175
<FillLayer
4276
{...layerId("auto-boundaries-areas")}
4377
manageHoverState
4478
paint={{
4579
"fill-color": hoverStateFilter("cyan", "red"),
4680
"fill-opacity": 0.3,
4781
}}
82+
on:click={add}
83+
hoverCursor="pointer"
4884
/>
4985

5086
<LineLayer

web/src/NetworkMode.svelte

+7-6
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@
8686
Route
8787
</Link>
8888
</li>
89-
<li>
90-
<Link on:click={() => ($mode = { mode: "auto-boundaries" })}>
91-
Auto boundaries
92-
</Link>
93-
</li>
9489
</ul>
9590
</nav>
9691
</div>
@@ -109,7 +104,13 @@
109104
</p>
110105
</details>
111106

112-
<Link on:click={newBoundary}>Draw a new boundary</Link>
107+
<div><Link on:click={newBoundary}>Draw a new boundary</Link></div>
108+
<div>
109+
<Link on:click={() => ($mode = { mode: "auto-boundaries" })}>
110+
Use an auto-generated boundary
111+
</Link>
112+
</div>
113+
113114
<ul>
114115
{#each boundaryNames as name}
115116
<li>

0 commit comments

Comments
 (0)