|
3 | 3 | import { SplitComponent } from "@uatp/components/two_column_layout";
|
4 | 4 | import {
|
5 | 5 | duckdbBackend,
|
6 |
| - map, |
7 | 6 | previewedMetricsList,
|
8 | 7 | previewMetricMap,
|
9 | 8 | rustBackend,
|
|
27 | 26 | CloseButton,
|
28 | 27 | TabItem,
|
29 | 28 | Tabs,
|
| 29 | + Label, |
| 30 | + Input, |
| 31 | + Dropdown, |
| 32 | + DropdownItem, |
| 33 | + ButtonGroup, |
30 | 34 | } from "flowbite-svelte";
|
31 | 35 |
|
32 | 36 | import { sineIn } from "svelte/easing";
|
33 | 37 | import SelectedMetrics from "./SelectedMetrics.svelte";
|
34 | 38 | import PreviewedMetrics from "./PreviewedMetrics.svelte";
|
35 | 39 | import { onMount } from "svelte";
|
36 | 40 | import TilesMap from "./TilesMap.svelte";
|
| 41 | + import { ChevronDownOutline } from "flowbite-svelte-icons"; |
37 | 42 |
|
| 43 | + const outputFormats: string[] = ["geojson", "csv", "geojsonseq"]; |
| 44 | + let selectedOutputFormat: string = "csv"; |
| 45 | + let bboxValue: string = ""; |
38 | 46 | let hidden8 = false;
|
39 | 47 | let transitionParams = {
|
40 | 48 | y: 320,
|
|
125 | 133 | return;
|
126 | 134 | }
|
127 | 135 |
|
| 136 | + function getPopgetterCli(): string { |
| 137 | + let ids = $selectedMetricsList |
| 138 | + .map((record: {}) => `--id ${record.metric_id}`) |
| 139 | + .join(" "); |
| 140 | + let outputFormatStr = "--output-format " + selectedOutputFormat; |
| 141 | + let bboxStr = bboxValue === "" ? "" : "--bbox " + bboxValue; |
| 142 | +
|
| 143 | + return ["popgetter", "data", ids, outputFormatStr, bboxStr].join(" "); |
| 144 | + } |
| 145 | +
|
128 | 146 | // TODO: consider if can be async to enable preview to be generated here
|
129 | 147 | function add(record: {}) {
|
130 | 148 | console.log(record);
|
|
161 | 179 | }
|
162 | 180 | }
|
163 | 181 |
|
164 |
| - // Using bbox |
165 |
| - let bbox = []; |
166 |
| - function updateBoundingBox() { |
167 |
| - const bounds = $map.getBounds(); |
168 |
| - bbox = [ |
169 |
| - bounds.getWest(), |
170 |
| - bounds.getSouth(), |
171 |
| - bounds.getEast(), |
172 |
| - bounds.getNorth(), |
173 |
| - ]; |
| 182 | + // Assign bounding box from map |
| 183 | + // TODO: fix this, currently returns not initialized |
| 184 | + let mapInstance; |
| 185 | + function updateBoundingBox(): string { |
| 186 | + if (mapInstance) { |
| 187 | + const bounds = mapInstance.getBounds().toArray(); |
| 188 | + console.log("Bounding Box:", bounds); |
| 189 | + let bbox = [ |
| 190 | + bounds.getWest(), |
| 191 | + bounds.getSouth(), |
| 192 | + bounds.getEast(), |
| 193 | + bounds.getNorth(), |
| 194 | + ]; |
| 195 | + return bbox.map((el) => Number(el.toFixed(6)).toString()).join(","); |
| 196 | + } else { |
| 197 | + console.error("Map instance is not yet initialized."); |
| 198 | + return ""; |
| 199 | + } |
174 | 200 | }
|
175 | 201 |
|
176 | 202 | async function download(dataRequestSpec: {}): Promise<Array<{}>> {
|
|
356 | 382 | <!-- Map previews downloaded metrics -->
|
357 | 383 |
|
358 | 384 | <div slot="map">
|
359 |
| - <TilesMap></TilesMap> |
| 385 | + <TilesMap bind:mapInstance></TilesMap> |
360 | 386 |
|
361 | 387 | <div>
|
362 | 388 | <Drawer
|
|
391 | 417 | </p>
|
392 | 418 | <PreviewedMetrics></PreviewedMetrics>
|
393 | 419 | </TabItem>
|
| 420 | + <!-- TODO: complete adding interface for advanced search --> |
| 421 | + <TabItem |
| 422 | + title="Advanced Search" |
| 423 | + on:click={() => setPreviewedMetrics()} |
| 424 | + > |
| 425 | + <!-- Search --> |
| 426 | + <section |
| 427 | + id="query-section" |
| 428 | + style="text-align: left; margin-top: 2.5%; margin-bottom: 5%; " |
| 429 | + > |
| 430 | + <Search bind:searchTerm on:input={debouncedHandleInput} /> |
| 431 | + </section> |
| 432 | + |
| 433 | + <!-- TODO: convert table for search results into component --> |
| 434 | + <section id="<results-table"> |
| 435 | + <Table> |
| 436 | + <TableHead> |
| 437 | + <!-- <TableHeadCell>ID</TableHeadCell> --> |
| 438 | + <TableHeadCell>Name</TableHeadCell> |
| 439 | + <TableHeadCell>Year</TableHeadCell> |
| 440 | + <TableHeadCell>Selected metrics</TableHeadCell> |
| 441 | + </TableHead> |
| 442 | + <TableBody tableBodyClass="divide-y"> |
| 443 | + {#each items as item} |
| 444 | + <TableBodyRow> |
| 445 | + <!-- <TableBodyCell>{item.metric_id.slice(0, 8)}</TableBodyCell> --> |
| 446 | + <TableBodyCell |
| 447 | + class="max-w-md whitespace-normal break-words border-b border-gray-200 px-2 py-2" |
| 448 | + >{item.metric_human_readable_name}</TableBodyCell |
| 449 | + > |
| 450 | + <TableBodyCell |
| 451 | + >{item.source_data_release_collection_period_start.slice( |
| 452 | + 0, |
| 453 | + 4, |
| 454 | + )}</TableBodyCell |
| 455 | + > |
| 456 | + <TableBodyCell> |
| 457 | + <Button color="light" on:click={() => add(item)} |
| 458 | + >Add</Button |
| 459 | + > |
| 460 | + </TableBodyCell> |
| 461 | + </TableBodyRow> |
| 462 | + {/each} |
| 463 | + </TableBody> |
| 464 | + </Table> |
| 465 | + </section> |
| 466 | + </TabItem> |
| 467 | + <TabItem title="Download" on:click={() => setPreviewedMetrics()}> |
| 468 | + <div class="pt-8"> |
| 469 | + <div |
| 470 | + style="text-align: left; margin-top: 0.5%; margin-bottom: 0.5%; " |
| 471 | + > |
| 472 | + <Label class="space-y-2" |
| 473 | + ><span>Bounding Box (left, bottom, right, top)</span></Label |
| 474 | + > |
| 475 | + <ButtonGroup class="w-full"> |
| 476 | + <Input |
| 477 | + id="bbox" |
| 478 | + type="text" |
| 479 | + placeholder="" |
| 480 | + bind:value={bboxValue} |
| 481 | + /> |
| 482 | + <Button |
| 483 | + color="light" |
| 484 | + on:click={() => updateBoundingBox()} |
| 485 | + class="w-80">Get from map</Button |
| 486 | + > |
| 487 | + </ButtonGroup> |
| 488 | + </div> |
| 489 | + <div |
| 490 | + style="text-align: left; margin-top: 0.5%; margin-bottom: 0.5%; " |
| 491 | + > |
| 492 | + <Label class="space-y-2"> |
| 493 | + Output format: |
| 494 | + <Button color="light"> |
| 495 | + {selectedOutputFormat} |
| 496 | + <ChevronDownOutline class="ms-2 h-6 w-6" /> |
| 497 | + </Button> |
| 498 | + <Dropdown> |
| 499 | + {#each outputFormats as outputFormat} |
| 500 | + <DropdownItem |
| 501 | + on:click={() => (selectedOutputFormat = outputFormat)} |
| 502 | + >{outputFormat} |
| 503 | + </DropdownItem> |
| 504 | + {/each} |
| 505 | + </Dropdown> |
| 506 | + </Label> |
| 507 | + </div> |
| 508 | + </div> |
| 509 | + <div |
| 510 | + style="text-align: left; margin-top: 0.5%; margin-bottom: 0.5%; " |
| 511 | + > |
| 512 | + <Label class="space-y-2"> |
| 513 | + Popgetter CLI command |
| 514 | + <ButtonGroup class="w-full"> |
| 515 | + <Input |
| 516 | + id="popgetter-data-cli" |
| 517 | + readonly |
| 518 | + value={getPopgetterCli()} |
| 519 | + /> |
| 520 | + <Button |
| 521 | + color="light" |
| 522 | + data-copy-to-clipboard-target="popgetter-data-cli" |
| 523 | + on:click={() => { |
| 524 | + console.log(getPopgetterCli()); |
| 525 | + navigator.clipboard.writeText(getPopgetterCli()); |
| 526 | + }}>Copy</Button |
| 527 | + > |
| 528 | + </ButtonGroup> |
| 529 | + </Label> |
| 530 | + </div> |
| 531 | + <!-- TODO: add download button --> |
| 532 | + </TabItem> |
394 | 533 | </Tabs>
|
395 | 534 | </Drawer>
|
396 | 535 | </div>
|
|
0 commit comments