Skip to content

Commit 2218d95

Browse files
committed
Switch to Stadia geocoding.
1 parent 0325295 commit 2218d95

8 files changed

Lines changed: 86 additions & 27 deletions

File tree

.github/workflows/deploy-site.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
- name: Build
4141
run: npm run build
4242
working-directory: site
43+
env:
44+
VITE_STADIA_API_KEY: ${{ secrets.VITE_STADIA_API_KEY }}
4345

4446
- uses: actions/upload-pages-artifact@v3
4547
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ venv.bak/
120120
# Site build output
121121
site/dist
122122
site/node_modules
123+
site/.env
123124

124125
# mypy
125126
.mypy_cache/

site/src/assets/styles.css

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,24 @@ body,
175175

176176
.confidence-legend .legend-ticks {
177177
display: flex;
178-
justify-content: space-between;
179178
font-size: 10px;
180179
color: #777;
181180
margin-top: 2px;
182181
}
183182

183+
.confidence-legend .legend-ticks span {
184+
flex: 1;
185+
text-align: center;
186+
}
187+
188+
.confidence-legend .legend-ticks span:first-child {
189+
text-align: left;
190+
}
191+
192+
.confidence-legend .legend-ticks span:last-child {
193+
text-align: right;
194+
}
195+
184196
/* Geolocation button */
185197
.geolocation-btn {
186198
position: absolute;
@@ -414,6 +426,29 @@ body,
414426
}
415427
}
416428

429+
/* Geocode marker (X) */
430+
.geocode-marker {
431+
width: 20px;
432+
height: 20px;
433+
position: relative;
434+
pointer-events: none;
435+
}
436+
437+
.geocode-marker::before,
438+
.geocode-marker::after {
439+
content: '';
440+
position: absolute;
441+
left: 50%;
442+
top: 0;
443+
width: 2.5px;
444+
height: 100%;
445+
background: #444;
446+
margin-left: -1.25px;
447+
}
448+
449+
.geocode-marker::before { transform: rotate(45deg); }
450+
.geocode-marker::after { transform: rotate(-45deg); }
451+
417452
/* Geolocation dot */
418453
.geolocation-dot {
419454
width: 16px;

site/src/components/MapContainer.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="map-container">
33
<div ref="mapEl" style="width: 100%; height: 100%"></div>
44

5-
<div v-if="loading" class="loading-indicator">
5+
<div v-show="loading" class="loading-indicator">
66
<div class="spinner"></div>
77
Loading POIs...
88
</div>
@@ -103,6 +103,7 @@ const { locate } = useGeolocation()
103103
const debouncer = createQueryDebouncer(300)
104104
105105
let geoOverlay = null
106+
let geocodeMarker = null
106107
107108
// Helper: get all data layers
108109
function getDataLayers() {
@@ -381,6 +382,21 @@ function flyToBbox(bbox) {
381382
maxZoom: 17,
382383
padding: [50, 50, 50, 50],
383384
})
385+
386+
if (bbox.lng != null && bbox.lat != null) {
387+
const coord = fromLonLat([bbox.lng, bbox.lat])
388+
if (!geocodeMarker) {
389+
const el = document.createElement('div')
390+
el.className = 'geocode-marker'
391+
geocodeMarker = new Overlay({
392+
element: el,
393+
positioning: 'center-center',
394+
stopEvent: false,
395+
})
396+
map.value.addOverlay(geocodeMarker)
397+
}
398+
geocodeMarker.setPosition(coord)
399+
}
384400
}
385401
386402
defineExpose({ flyToBbox })

site/src/components/SearchBar.vue

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<ul v-if="results.length" class="search-results">
1111
<li
1212
v-for="r in results"
13-
:key="r.place_id"
13+
:key="r.properties.id"
1414
@click="selectResult(r)"
1515
>
16-
{{ r.display_name }}
16+
{{ r.properties.label }}
1717
</li>
1818
</ul>
1919
</div>
@@ -32,10 +32,21 @@ function onInput() {
3232
}
3333
3434
function selectResult(r) {
35-
// Nominatim returns boundingbox as [south, north, west, east]
36-
const [south, north, west, east] = r.boundingbox.map(Number)
37-
emit('fly-to', { south, north, west, east })
38-
query.value = r.display_name
35+
// Stadia/Pelias GeoJSON bbox: [west, south, east, north]
36+
// Fall back to a small box around the point if bbox is absent.
37+
const [lng, lat] = r.geometry.coordinates
38+
let west, south, east, north
39+
if (r.bbox) {
40+
;[west, south, east, north] = r.bbox
41+
} else {
42+
const delta = 0.01
43+
west = lng - delta
44+
east = lng + delta
45+
south = lat - delta
46+
north = lat + delta
47+
}
48+
emit('fly-to', { west, south, east, north, lng, lat })
49+
query.value = r.properties.label
3950
clearResults()
4051
}
4152

site/src/composables/useDuckDB.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function _init() {
2222
const wasmUrl = `${baseUrl}duckdb-eh.wasm`
2323

2424
const worker = new Worker(workerUrl)
25-
const logger = new duckdb.ConsoleLogger()
25+
const logger = new duckdb.VoidLogger()
2626
const instance = new duckdb.AsyncDuckDB(logger, worker)
2727
await instance.instantiate(wasmUrl)
2828

site/src/composables/useGeocoder.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ref } from 'vue'
2-
import { NOMINATIM_URL } from '../constants.js'
2+
import { STADIA_GEOCODING_URL } from '../constants.js'
33

44
const results = ref([])
55
const loading = ref(false)
@@ -17,28 +17,22 @@ async function search(query) {
1717
loading.value = true
1818
try {
1919
const params = new URLSearchParams({
20-
format: 'json',
21-
q: query,
22-
countrycodes: 'us',
23-
limit: '5',
20+
api_key: import.meta.env.VITE_STADIA_API_KEY,
21+
text: query,
22+
'boundary.country': 'US',
23+
size: '5',
2424
})
25-
const resp = await fetch(
26-
`${NOMINATIM_URL}?${params}`,
27-
{
28-
headers: {
29-
'User-Agent': 'openpois-viewer/1.0',
30-
},
31-
}
32-
)
33-
results.value = await resp.json()
25+
const resp = await fetch(`${STADIA_GEOCODING_URL}?${params}`)
26+
const data = await resp.json()
27+
results.value = data.features ?? []
3428
} catch (err) {
3529
console.error('Geocoding error:', err)
3630
results.value = []
3731
} finally {
3832
loading.value = false
3933
resolve()
4034
}
41-
}, 1000) // 1s debounce for Nominatim rate limit
35+
}, 300)
4236
})
4337
}
4438

site/src/constants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ export const MAX_GEOHASH_CELLS = 50
163163
export const MIN_ZOOM_FOR_DATA = 14
164164
export const CLUSTER_MAX_ZOOM = 12
165165

166-
// Nominatim
167-
export const NOMINATIM_URL =
168-
'https://nominatim.openstreetmap.org/search'
166+
// Stadia Maps Geocoding
167+
export const STADIA_GEOCODING_URL =
168+
'https://api.stadiamaps.com/geocoding/v1/search'
169169

170170
// Initial map view — New York City (fallback if geolocation is denied)
171171
export const INITIAL_CENTER = [-74.006, 40.7128]

0 commit comments

Comments
 (0)