Skip to content

Commit 8ee4c93

Browse files
committed
so far so good
1 parent b64464d commit 8ee4c93

File tree

6 files changed

+289
-180
lines changed

6 files changed

+289
-180
lines changed

package-lock.json

Lines changed: 26 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
"vite": "^6.2.0"
1515
},
1616
"dependencies": {
17-
"arquero": "^8.0.1",
1817
"latlon-geohash": "^2.0.0",
19-
"leaflet": "^1.9.4"
18+
"leaflet": "^1.9.4",
19+
"lokijs": "^1.5.12",
20+
"ngeohash": "^0.6.3",
21+
"pako": "^2.1.0"
2022
}
2123
}

src/App.svelte

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
import { onMount } from "svelte";
33
import Map from "./lib/Map.svelte";
44
import SlidingPane from "./lib/SlidingPane.svelte";
5+
import { getGeoEntriesInBounds, getUniqueByGeoHash } from "./lib/geodata";
6+
import { Mixin } from "leaflet";
57
68
let markers = [
79
{
810
lat: 51.508056,
9-
lng: -0.076111,
11+
lon: -0.076111,
1012
name: "City with a very very long name",
1113
type: "city",
1214
pageTitle: "London",
1315
sizeClass: "full",
1416
},
1517
{
1618
lat: 48.8566,
17-
lng: 2.3522,
19+
lon: 2.3522,
1820
name: "Paris",
1921
type: "landmark",
2022
pageTitle: "Paris",
@@ -23,7 +25,7 @@
2325
},
2426
{
2527
lat: 40.7128,
26-
lng: -74.006,
28+
lon: -74.006,
2729
name: "New York",
2830
type: "city",
2931
pageTitle: "New York City",
@@ -33,8 +35,8 @@
3335
3436
let dataStatus = "not started";
3537
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 },
3840
};
3941
4042
// State to control the sliding pane
@@ -44,13 +46,13 @@
4446
// State for selected marker
4547
let selectedMarker = null;
4648
let mapCenter = [51.508056, -0.076111];
47-
let mapZoom = 13;
49+
let mapZoom = 1;
4850
4951
// Add a target location state
5052
let targetMapLocation = {
5153
lat: 51.508056,
52-
lng: -0.076111,
53-
zoom: 13,
54+
lon: -0.076111,
55+
zoom: 1,
5456
};
5557
5658
// Function to open the pane with a Wikipedia page
@@ -67,22 +69,31 @@
6769
// Set the target location instead of directly setting center/zoom
6870
targetMapLocation = {
6971
lat: marker.lat,
70-
lng: marker.lng,
72+
lon: marker.lon,
7173
zoom: Math.max(13, mapZoom), // Ensure zoom is at least 13
7274
};
7375
7476
openWikiPane(marker.pageTitle);
7577
}
7678
77-
function handleBoundsChange(event) {
79+
async function handleBoundsChange(event) {
7880
const center = event.detail.center;
79-
mapCenter = [center.lat, center.lng];
8081
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,
8489
};
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);
8697
}
8798
onMount(async () => {
8899
console.log("App starting");
@@ -94,10 +105,10 @@
94105
<span>Status: {dataStatus}</span>
95106
<span>
96107
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(
98109
4
99110
)},
100-
{mapBounds.southWest.lng.toFixed(4)})</span
111+
{mapBounds.southWest.lon.toFixed(4)})</span
101112
>
102113
<button on:click={() => openWikiPane("London")}>Open Wikipedia</button>
103114
</div>

src/lib/Map.svelte

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import L from "leaflet";
44
import "leaflet/dist/leaflet.css";
55
import { createEventDispatcher } from "svelte";
6-
import { getGeoTable } from "./geodata";
76
87
// Props
98
export let markers = [];
@@ -12,7 +11,7 @@
1211
export let onMarkerClick = null; // Function to call when marker is clicked
1312
1413
// New props for controlled centering
15-
export let targetLocation = null; // Format: { lat, lng, zoom }
14+
export let targetLocation = null; // Format: { lat, lon, zoom }
1615
1716
let mapElement;
1817
let map;
@@ -115,9 +114,9 @@
115114
});
116115
117116
function flyTo(targetLocation) {
118-
const { lat, lng, zoom: targetZoom } = targetLocation;
117+
const { lat, lon, zoom: targetZoom } = targetLocation;
119118
isFlying = true;
120-
map.flyTo([lat, lng], targetZoom, {
119+
map.flyTo([lat, lon], targetZoom, {
121120
animate: true,
122121
duration: 1, // Duration in seconds
123122
});
@@ -164,7 +163,7 @@
164163
html: markerHtml,
165164
iconSize: [128, 32],
166165
});
167-
const mapMarker = L.marker([marker.lat, marker.lng], {
166+
const mapMarker = L.marker([marker.lat, marker.lon], {
168167
icon: icon,
169168
}).addTo(markerLayer);
170169
@@ -186,33 +185,6 @@
186185
map.invalidateSize();
187186
}
188187
}
189-
190-
function addMarkers() {
191-
// Clear existing markers
192-
markers.forEach((marker) => map.removeLayer(marker));
193-
markers = [];
194-
195-
// Get data and add markers
196-
const geoTable = getGeoTable(); // Assuming this function exists and returns your data
197-
if (geoTable) {
198-
geoTable.objects().forEach((point) => {
199-
if (point.lat && point.lon) {
200-
const marker = L.marker([point.lat, point.lon]).addTo(map);
201-
202-
// Add click handler
203-
if (onMarkerClick) {
204-
marker.on("click", () => {
205-
onMarkerClick(point);
206-
});
207-
}
208-
209-
// You can add popups or other features here
210-
211-
markers.push(marker);
212-
}
213-
});
214-
}
215-
}
216188
</script>
217189

218190
<div

0 commit comments

Comments
 (0)