|
2 | 2 | import { onMount } from "svelte"; |
3 | 3 | import Map from "./lib/Map.svelte"; |
4 | 4 | import SlidingPane from "./lib/SlidingPane.svelte"; |
| 5 | + import { getGeoEntriesInBounds, getUniqueByGeoHash } from "./lib/geodata"; |
| 6 | + import { Mixin } from "leaflet"; |
5 | 7 |
|
6 | 8 | let markers = [ |
7 | 9 | { |
8 | 10 | lat: 51.508056, |
9 | | - lng: -0.076111, |
| 11 | + lon: -0.076111, |
10 | 12 | name: "City with a very very long name", |
11 | 13 | type: "city", |
12 | 14 | pageTitle: "London", |
13 | 15 | sizeClass: "full", |
14 | 16 | }, |
15 | 17 | { |
16 | 18 | lat: 48.8566, |
17 | | - lng: 2.3522, |
| 19 | + lon: 2.3522, |
18 | 20 | name: "Paris", |
19 | 21 | type: "landmark", |
20 | 22 | pageTitle: "Paris", |
|
23 | 25 | }, |
24 | 26 | { |
25 | 27 | lat: 40.7128, |
26 | | - lng: -74.006, |
| 28 | + lon: -74.006, |
27 | 29 | name: "New York", |
28 | 30 | type: "city", |
29 | 31 | pageTitle: "New York City", |
|
33 | 35 |
|
34 | 36 | let dataStatus = "not started"; |
35 | 37 | let mapBounds = { |
36 | | - northEast: { lat: 0, lng: 0 }, |
37 | | - southWest: { lat: 0, lng: 0 }, |
| 38 | + northEast: { lat: 0, lon: 0 }, |
| 39 | + southWest: { lat: 0, lon: 0 }, |
38 | 40 | }; |
39 | 41 |
|
40 | 42 | // State to control the sliding pane |
|
44 | 46 | // State for selected marker |
45 | 47 | let selectedMarker = null; |
46 | 48 | let mapCenter = [51.508056, -0.076111]; |
47 | | - let mapZoom = 13; |
| 49 | + let mapZoom = 1; |
48 | 50 |
|
49 | 51 | // Add a target location state |
50 | 52 | let targetMapLocation = { |
51 | 53 | lat: 51.508056, |
52 | | - lng: -0.076111, |
53 | | - zoom: 13, |
| 54 | + lon: -0.076111, |
| 55 | + zoom: 1, |
54 | 56 | }; |
55 | 57 |
|
56 | 58 | // Function to open the pane with a Wikipedia page |
|
67 | 69 | // Set the target location instead of directly setting center/zoom |
68 | 70 | targetMapLocation = { |
69 | 71 | lat: marker.lat, |
70 | | - lng: marker.lng, |
| 72 | + lon: marker.lon, |
71 | 73 | zoom: Math.max(13, mapZoom), // Ensure zoom is at least 13 |
72 | 74 | }; |
73 | 75 |
|
74 | 76 | openWikiPane(marker.pageTitle); |
75 | 77 | } |
76 | 78 |
|
77 | | - function handleBoundsChange(event) { |
| 79 | + async function handleBoundsChange(event) { |
78 | 80 | const center = event.detail.center; |
79 | | - mapCenter = [center.lat, center.lng]; |
80 | 81 | mapZoom = event.detail.zoom; |
81 | | - mapBounds = { |
82 | | - northEast: event.detail.bounds._northEast, |
83 | | - southWest: event.detail.bounds._southWest, |
| 82 | + console.log("mapZoom", mapZoom); |
| 83 | + mapCenter = [center.lat, center.lon]; |
| 84 | + const bounds = { |
| 85 | + minLat: event.detail.bounds._southWest.lat, |
| 86 | + maxLat: event.detail.bounds._northEast.lat, |
| 87 | + minLon: event.detail.bounds._southWest.lng, |
| 88 | + maxLon: event.detail.bounds._northEast.lng, |
84 | 89 | }; |
85 | | - console.log("Map bounds updated:", mapBounds); |
| 90 | + const entries = await getGeoEntriesInBounds(bounds); |
| 91 | + const uniqueEntries = getUniqueByGeoHash({ |
| 92 | + entries, |
| 93 | + hashLength: Math.min(8, mapZoom / 2), |
| 94 | + scoreField: "page_len", |
| 95 | + }); |
| 96 | + console.log("Unique entries:", uniqueEntries); |
86 | 97 | } |
87 | 98 | onMount(async () => { |
88 | 99 | console.log("App starting"); |
|
94 | 105 | <span>Status: {dataStatus}</span> |
95 | 106 | <span> |
96 | 107 | Bounds: NE({mapBounds.northEast.lat.toFixed(4)}, |
97 | | - {mapBounds.northEast.lng.toFixed(4)}) - SE({mapBounds.southWest.lat.toFixed( |
| 108 | + {mapBounds.northEast.lon.toFixed(4)}) - SE({mapBounds.southWest.lat.toFixed( |
98 | 109 | 4 |
99 | 110 | )}, |
100 | | - {mapBounds.southWest.lng.toFixed(4)})</span |
| 111 | + {mapBounds.southWest.lon.toFixed(4)})</span |
101 | 112 | > |
102 | 113 | <button on:click={() => openWikiPane("London")}>Open Wikipedia</button> |
103 | 114 | </div> |
|
0 commit comments