|
7 | 7 | } from "geojson";
|
8 | 8 | import type { MapMouseEvent } from "maplibre-gl";
|
9 | 9 | import { onDestroy } from "svelte";
|
10 |
| - import { Popup } from "svelte-maplibre"; |
| 10 | + import { CircleLayer, GeoJSON, Popup } from "svelte-maplibre"; |
11 | 11 | import { notNull } from "../common";
|
12 | 12 | import ManageSavefiles from "../ManageSavefiles.svelte";
|
13 | 13 | import RenderNeighbourhood from "../RenderNeighbourhood.svelte";
|
14 | 14 | import SplitComponent from "../SplitComponent.svelte";
|
15 |
| - import { app, map, mode } from "../stores"; |
| 15 | + import { app, map, mode, mutationCounter } from "../stores"; |
16 | 16 | import ChangeModalFilter from "./ChangeModalFilter.svelte";
|
17 | 17 | import FreehandLine from "./FreehandLine.svelte";
|
18 | 18 |
|
|
27 | 27 | let boundary: Feature<Polygon> | null;
|
28 | 28 |
|
29 | 29 | let gjInput: FeatureCollection;
|
30 |
| - rerender(); |
| 30 | + let modalFilterGj: FeatureCollection; |
| 31 | + $: rerender($mutationCounter); |
31 | 32 |
|
32 |
| - function rerender() { |
| 33 | + function rerender(_x: number) { |
33 | 34 | gjInput = JSON.parse($app!.renderNeighbourhood());
|
34 | 35 | boundary = gjInput.features.find(
|
35 | 36 | (f) => f.properties!.kind == "boundary"
|
|
39 | 40 | undoLength = gjInput.undo_length;
|
40 | 41 | // @ts-ignore These foreign members exist
|
41 | 42 | redoLength = gjInput.redo_length;
|
| 43 | +
|
| 44 | + modalFilterGj = JSON.parse($app!.renderModalFilters()); |
42 | 45 | }
|
43 | 46 |
|
44 | 47 | $: if (addingFilter) {
|
|
51 | 54 | });
|
52 | 55 | function onClick(e: MapMouseEvent) {
|
53 | 56 | $app!.addModalFilter(e.lngLat, filterType);
|
54 |
| - rerender(); |
| 57 | + $mutationCounter++; |
55 | 58 | stopAddingFilter();
|
56 | 59 | }
|
57 | 60 | function stopAddingFilter() {
|
|
60 | 63 | $map!.getCanvas().style.cursor = "inherit";
|
61 | 64 | }
|
62 | 65 |
|
63 |
| - function deleteFilter(f: Feature) { |
| 66 | + function deleteFilter(e) { |
| 67 | + let f = e.detail.features[0]; |
64 | 68 | if (f.properties!.kind == "modal_filter") {
|
65 | 69 | $app!.deleteModalFilter(f.properties!.road);
|
66 |
| - rerender(); |
| 70 | + $mutationCounter++; |
67 | 71 | }
|
68 | 72 | }
|
69 | 73 |
|
|
80 | 84 | }
|
81 | 85 | function undo() {
|
82 | 86 | $app!.undo();
|
83 |
| - rerender(); |
| 87 | + $mutationCounter++; |
84 | 88 | }
|
85 | 89 | function redo() {
|
86 | 90 | $app!.redo();
|
87 |
| - rerender(); |
| 91 | + $mutationCounter++; |
88 | 92 | }
|
89 | 93 |
|
90 | 94 | function pickNewNeighbourhood() {
|
|
97 | 101 | let f = e.detail;
|
98 | 102 | if (f) {
|
99 | 103 | $app!.addManyModalFilters(f, filterType);
|
100 |
| - rerender(); |
| 104 | + $mutationCounter++; |
101 | 105 | }
|
102 | 106 |
|
103 | 107 | addingMultipleFilters = false;
|
|
210 | 214 | <RenderNeighbourhood
|
211 | 215 | {gjInput}
|
212 | 216 | interactive={!addingFilter && !addingMultipleFilters}
|
213 |
| - onClickCircle={deleteFilter} |
214 | 217 | >
|
215 | 218 | <div slot="line-popup">
|
216 | 219 | <Popup openOn="hover" let:data
|
217 | 220 | ><p>{notNull(data).properties.shortcuts} shortcuts</p></Popup
|
218 | 221 | >
|
219 | 222 | </div>
|
220 | 223 | </RenderNeighbourhood>
|
| 224 | + <GeoJSON data={modalFilterGj} generateId> |
| 225 | + <CircleLayer |
| 226 | + paint={{ |
| 227 | + "circle-radius": 15, |
| 228 | + "circle-color": "black", |
| 229 | + }} |
| 230 | + on:click={deleteFilter} |
| 231 | + > |
| 232 | + <Popup openOn="hover">Click to delete</Popup> |
| 233 | + </CircleLayer> |
| 234 | + </GeoJSON> |
221 | 235 | {#if addingMultipleFilters}
|
222 | 236 | <FreehandLine map={notNull($map)} on:done={gotFreehandLine} />
|
223 | 237 | {/if}
|
|
0 commit comments