Skip to content

Commit b7e7b68

Browse files
committed
OWC-194 add search by street place or zipcode
1 parent 39f926a commit b7e7b68

5 files changed

Lines changed: 61 additions & 123 deletions

File tree

build/blocks/owc-openkaarten/streetmap/client.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/blocks/owc-openkaarten/streetmap/client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/blocks/owc-openkaarten/streetmap/client.js": "/blocks/owc-openkaarten/streetmap/client.js?id=3c8f46a7300885cb005671988f825e18",
2+
"/blocks/owc-openkaarten/streetmap/client.js": "/blocks/owc-openkaarten/streetmap/client.js?id=88c98856b9bbb7c789d8082375e21b9d",
33
"/blocks/owc-openkaarten/streetmap/style.css": "/blocks/owc-openkaarten/streetmap/style.css?id=0c70cc29722d11466724176fc03cdd58",
44
"/blocks/owc-openkaarten/streetmap/editor.css": "/blocks/owc-openkaarten/streetmap/editor.css?id=f4316f0723fb86e3b028a9b448b1f3ae"
55
}

src/blocks/owc-openkaarten/streetmap/assets/scripts/vue/BaseSearchInput.vue

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,23 @@ const props = defineProps({
1414
1515
const emit = defineEmits(['search']);
1616
const searchQuery = ref('');
17-
const resultsCount = ref(0);
1817
1918
const handleSubmit = (e) => {
2019
e.preventDefault();
2120
emit('search', searchQuery.value);
2221
};
2322
24-
const handleInput = () => {
25-
emit('search', searchQuery.value);
26-
};
27-
2823
const clearSearch = () => {
2924
searchQuery.value = '';
3025
emit('search', '');
3126
};
3227
33-
const searchStatus = computed(() => {
34-
if (!searchQuery.value) return '';
35-
return `${resultsCount.value} resultaten gevonden voor "${searchQuery.value}"`;
36-
});
3728
</script>
3829

3930
<template>
4031
<search class="search-container">
41-
<form
42-
@submit="handleSubmit"
32+
<form
33+
@submit="handleSubmit"
4334
class="search-form"
4435
:style="{ '--search-primary-color': primaryColor }"
4536
>
@@ -51,41 +42,38 @@ const searchStatus = computed(() => {
5142
aria-atomic="true"
5243
class="sr-only"
5344
>
54-
<span>{{ searchStatus }}</span>
5545
</div>
5646

5747
<input
5848
id="location-search"
5949
type="search"
6050
v-model="searchQuery"
6151
:placeholder="placeholder"
62-
@input="handleInput"
63-
autocomplete="off"
6452
class="search-input"
65-
/>
53+
/>
6654

67-
<button
55+
<button
6856
v-if="searchQuery"
6957
type="button"
7058
class="search-clear"
7159
@click="clearSearch"
7260
aria-label="Zoekopdracht wissen"
73-
>
74-
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
75-
<path d="M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166 4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166 19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289 17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z" />
76-
</svg>
77-
</button>
78-
79-
<button
80-
type="submit"
61+
>
62+
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
63+
<path d="M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166 4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166 19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289 17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z" />
64+
</svg>
65+
</button>
66+
67+
<button
68+
type="submit"
8169
class="search-submit"
8270
:disabled="!searchQuery"
8371
aria-label="Zoeken"
84-
>
85-
<svg aria-hidden="true" focusable="false" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
86-
<path d="M15.5 14H14.71L14.43 13.73C15.41 12.59 16 11.11 16 9.5C16 5.91 13.09 3 9.5 3C5.91 3 3 5.91 3 9.5C3 13.09 5.91 16 9.5 16C11.11 16 12.59 15.41 13.73 14.43L14 14.71V15.5L19 20.49L20.49 19L15.5 14ZM9.5 14C7.01 14 5 11.99 5 9.5C5 7.01 7.01 5 9.5 5C11.99 5 14 7.01 14 9.5C14 11.99 11.99 14 9.5 14Z" fill="currentColor"/>
87-
</svg>
88-
</button>
72+
>
73+
<svg aria-hidden="true" focusable="false" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
74+
<path d="M15.5 14H14.71L14.43 13.73C15.41 12.59 16 11.11 16 9.5C16 5.91 13.09 3 9.5 3C5.91 3 3 5.91 3 9.5C3 13.09 5.91 16 9.5 16C11.11 16 12.59 15.41 13.73 14.43L14 14.71V15.5L19 20.49L20.49 19L15.5 14ZM9.5 14C7.01 14 5 11.99 5 9.5C5 7.01 7.01 5 9.5 5C11.99 5 14 7.01 14 9.5C14 11.99 11.99 14 9.5 14Z" fill="currentColor"/>
75+
</svg>
76+
</button>
8977
</div>
9078
</form>
9179
</search>
@@ -167,4 +155,4 @@ const searchStatus = computed(() => {
167155
opacity: 0.8;
168156
}
169157
}
170-
</style>
158+
</style>

src/blocks/owc-openkaarten/streetmap/assets/scripts/vue/TheMap.vue

Lines changed: 40 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ const initializeMap = (datasets) => {
174174
centerX: lat,
175175
centerY: long,
176176
minimumZoom: 4,
177-
maximumZoom: 16,
178-
defaultZoom: 13,
177+
maximumZoom: 18,
178+
defaultZoom: 10,
179179
enableHomeControl: true,
180180
enableZoomControl: true,
181181
enableBoxZoomControl: true,
@@ -329,97 +329,46 @@ const filteredLocations = computed(() => {
329329
});
330330
331331
// Add search handler
332-
const handleSearch = (query) => {
333-
searchQuery.value = query;
334-
const map = mapRef.value;
335-
336-
if (!map) return;
337-
338-
// Clear existing search markers
339-
searchMarkers.value.forEach(marker => {
340-
if (marker && map.hasLayer(marker)) {
341-
map.removeLayer(marker);
342-
}
343-
});
344-
searchMarkers.value = [];
345-
346-
if (!query) {
347-
// Show all markers again when search is cleared
348-
clusters.value.forEach(({ cluster }) => {
349-
if (cluster && !map.hasLayer(cluster)) {
350-
map.addLayer(cluster);
351-
}
352-
});
353-
return;
354-
}
355-
356-
// Hide all regular markers
357-
clusters.value.forEach(({ cluster }) => {
358-
if (cluster && map.hasLayer(cluster)) {
359-
map.removeLayer(cluster);
360-
}
361-
});
362-
363-
// Create markers for search results and zoom to bounds
364-
const searchBounds = L.latLngBounds();
365-
let hasValidResults = false;
366-
367-
filteredLocations.value.forEach(location => {
368-
if (location?.geometry?.coordinates) {
369-
if (location.geometry.type === 'MultiPoint') {
370-
location.geometry.coordinates.forEach(coord => {
371-
if (Array.isArray(coord) && coord.length >= 2) {
372-
const latlng = L.latLng(coord[1], coord[0]);
373-
addSearchMarker(latlng, location);
374-
searchBounds.extend(latlng);
375-
hasValidResults = true;
376-
}
377-
});
378-
} else {
379-
const coords = location.geometry.coordinates;
380-
if (Array.isArray(coords) && coords.length >= 2) {
381-
const latlng = L.latLng(coords[1], coords[0]);
382-
addSearchMarker(latlng, location);
383-
searchBounds.extend(latlng);
384-
hasValidResults = true;
385-
}
386-
}
387-
}
388-
});
332+
const handleSearch = async (query) => {
333+
searchQuery.value = query;
334+
const map = mapRef.value;
335+
336+
if (!map || !query) return;
337+
338+
try {
339+
const response = await fetch(
340+
`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(query)}`
341+
);
342+
const results = await response.json();
343+
344+
if (results.length > 0) {
345+
const { lat, lon } = results[0]; // Take the first (most relevant) match.
346+
const latLng = L.latLng(parseFloat(lat), parseFloat(lon));
347+
const targetIcon = L.icon({
348+
iconUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAApCAYAAADAk4LOAAAFgUlEQVR4Aa1XA5BjWRTN2oW17d3YaZtr2962HUzbDNpjszW24mRt28p47v7zq/bXZtrp/lWnXr337j3nPCe85NcypgSFdugCpW5YoDAMRaIMqRi6aKq5E3YqDQO3qAwjVWrD8Ncq/RBpykd8oZUb/kaJutow8r1aP9II0WmLKLIsJyv1w/kqw9Ch2MYdB++12Onxee/QMwvf4/Dk/Lfp/i4nxTXtOoQ4pW5Aj7wpici1A9erdAN2OH64x8OSP9j3Ft3b7aWkTg/Fm91siTra0f9on5sQr9INejH6CUUUpavjFNq1B+Oadhxmnfa8RfEmN8VNAsQhPqF55xHkMzz3jSmChWU6f7/XZKNH+9+hBLOHYozuKQPxyMPUKkrX/K0uWnfFaJGS1QPRtZsOPtr3NsW0uyh6NNCOkU3Yz+bXbT3I8G3xE5EXLXtCXbbqwCO9zPQYPRTZ5vIDXD7U+w7rFDEoUUf7ibHIR4y6bLVPXrz8JVZEql13trxwue/uDivd3fkWRbS6/IA2bID4uk0UpF1N8qLlbBlXs4Ee7HLTfV1j54APvODnSfOWBqtKVvjgLKzF5YdEk5ewRkGlK0i33Eofffc7HT56jD7/6U+qH3Cx7SBLNntH5YIPvODnyfIXZYRVDPqgHtLs5ABHD3YzLuespb7t79FY34DjMwrVrcTuwlT55YMPvOBnRrJ4VXTdNnYug5ucHLBjEpt30701A3Ts+HEa73u6dT3FNWwflY86eMHPk+Yu+i6pzUpRrW7SNDg5JHR4KapmM5Wv2E8Tf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dfNbM+GgIwYdwAAAAASUVORK5CYII=',
349+
iconSize: ['auto', 24],
350+
iconAnchor: [0, 24],
351+
popupAnchor: [8, -7]
352+
});
389353
390-
if (hasValidResults) {
391-
// Zoom to results with padding
392-
map.fitBounds(searchBounds, {
393-
padding: [50, 50],
394-
maxZoom: 15
395-
});
396-
}
397-
};
354+
const targetMarker = L.marker(latLng, {icon:targetIcon})
398355
399-
// Helper function to add search result markers
400-
const addSearchMarker = (latlng, location) => {
401-
const map = mapRef.value;
402-
if (!map || !latlng || !location) return;
356+
if (map && map._loaded) {
357+
map.setView(latLng, 15);
358+
} // Zoom in on the found location.
403359
404-
try {
405-
const icon = makeMarkerIcon(L, {
406-
marker: location.properties?.marker,
407-
defaultColor: props.primaryColor,
408-
});
360+
// remove old targetMarker if present.
361+
if (targetMarker) {
362+
targetMarker.remove();
363+
}
409364
410-
const marker = new L.Marker(latlng, {
411-
icon,
412-
zIndexOffset: 1000 // Ensure search results appear above other markers
413-
});
414-
415-
if (marker) {
416-
attachEvents(marker, location, { id: location.datasetId });
417-
marker.addTo(map);
418-
searchMarkers.value.push(marker);
419-
}
420-
} catch (error) {
421-
console.error('Error adding search marker:', error);
422-
}
365+
// Add new targetMarker.
366+
targetMarker.addTo(map);
367+
targetMarker.bindPopup("Gevonden locatie");
368+
}
369+
} catch (error) {
370+
console.error("Error in retrieving location:", error);
371+
}
423372
};
424373
</script>
425374
@@ -432,7 +381,8 @@ const addSearchMarker = (latlng, location) => {
432381
}"
433382
>
434383
<div class="owc-openkaarten-streetmap__controls">
435-
<BaseSearchInput
384+
<BaseSearchInput
385+
:placeholder="'Zoek op straat en/of plaats of postcode'"
436386
:primary-color="primaryColor"
437387
@search="handleSearch"
438388
:results-count="filteredLocations.length"

0 commit comments

Comments
 (0)