|
5 | 5 | GeoJSON,
|
6 | 6 | LineLayer,
|
7 | 7 | hoverStateFilter,
|
| 8 | + type LayerClickInfo, |
8 | 9 | } from "svelte-maplibre";
|
9 | 10 | import { Link, layerId } from "./common";
|
10 |
| - import { notNull } from "svelte-utils"; |
11 | 11 | import { isLine } from "svelte-utils/map";
|
12 | 12 | 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 | + } |
14 | 43 | </script>
|
15 | 44 |
|
16 | 45 | <SplitComponent>
|
|
27 | 56 | Pick neighbourhood
|
28 | 57 | </Link>
|
29 | 58 | </li>
|
30 |
| - <li>Generated boundaries (experiment)</li> |
| 59 | + <li>Use an auto-generated boundary</li> |
31 | 60 | </ul>
|
32 | 61 | </nav>
|
33 | 62 | </div>
|
34 | 63 |
|
35 | 64 | <div slot="sidebar">
|
36 | 65 | <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> |
37 | 71 | </div>
|
38 | 72 |
|
39 | 73 | <div slot="map">
|
40 |
| - <GeoJSON data={JSON.parse(notNull($app).renderAutoBoundaries())} generateId> |
| 74 | + <GeoJSON data={gj} generateId> |
41 | 75 | <FillLayer
|
42 | 76 | {...layerId("auto-boundaries-areas")}
|
43 | 77 | manageHoverState
|
44 | 78 | paint={{
|
45 | 79 | "fill-color": hoverStateFilter("cyan", "red"),
|
46 | 80 | "fill-opacity": 0.3,
|
47 | 81 | }}
|
| 82 | + on:click={add} |
| 83 | + hoverCursor="pointer" |
48 | 84 | />
|
49 | 85 |
|
50 | 86 | <LineLayer
|
|
0 commit comments