Skip to content

Commit 6e704bd

Browse files
Add marker for place search
1 parent bbcc9db commit 6e704bd

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

client/src/components/MapSearch.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
<script setup>
112112
import { getPlaceByNameSearch, getWatershedBySearch, getWatershedLicenceBySearch } from '@/utils/api.js';
113113
import { ref, onMounted } from 'vue';
114-
import { env } from '@/env';
115114
116115
const emit = defineEmits(['go-to-location', 'select-point', 'select-watershed', 'place-marker']);
117116
@@ -135,12 +134,11 @@ const allSearchOptions = ref([
135134
{ label: 'Place Name', value: 'place' },
136135
{ label: 'Lng/Lat', value: 'coord' }
137136
]);
138-
const searchType = ref(allSearchOptions[0]);
137+
const searchType = ref(allSearchOptions.value[0].value);
139138
const searchTerm = ref('');
140139
const loadingResults = ref(false);
141140
const searchResults = ref(null);
142-
const placeholderText = ref('Search');
143-
const marker = ref(null);
141+
const placeholderText = ref('Search Term');
144142
145143
onMounted(() => {
146144
// append the page-specific search options to the default search options
@@ -278,6 +276,7 @@ const selectSearchResult = (result) => {
278276
center: [ result.longitude, result.latitude],
279277
zoom: 9
280278
});
279+
emit('place-marker', [result.longitude, result.latitude])
281280
} else if (searchType.value === 'coord') {
282281
props.map.flyTo({
283282
center: [ parseFloat(result[1]), parseFloat(result[0]) ],

client/src/utils/api.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import cache from './cache';
55
const requestWithErrorCatch = async (url, fetchType) => {
66
try{
77
const response = await fetch(url);
8-
if(response.status === 404){
8+
if (response.status === 404) {
99
if(fetchType === 'report') throw { message: 'No report data for the selected point. Try selecting another point.' };
1010
else if (fetchType === 'watershedLookup') throw { message: 'No watershed data for selected point, please ensure you are selecting a point within highlighted region'};
11-
throw { message: 'No data found.' }
12-
}
13-
if(response.status === 500){
11+
else if (fetchType !== 'search') throw { message: 'No data found.' };
12+
} else if (response.status === 500) {
1413
if(fetchType === 'report') throw { message: 'There was a problem getting report data. Please try again later. ' };
1514
throw { message: 'There was a problem fetching data. Please try again later.' };
1615
}
@@ -33,19 +32,19 @@ export const getAllWatershedLicences = async () => {
3332
}
3433

3534
export const getWatershedBySearch = async (wfi) => {
36-
return await requestWithErrorCatch(`${env.VITE_BASE_API_URL}/watershed/search?wfi=${wfi}`)
35+
return await requestWithErrorCatch(`${env.VITE_BASE_API_URL}/watershed/search?wfi=${wfi}`, 'search')
3736
}
3837

3938
export const getWatershedByWFI = async (wfi) => {
4039
return await requestWithErrorCatch(`${env.VITE_BASE_API_URL}/watershed/${wfi}`)
4140
}
4241

4342
export const getWatershedLicenceBySearch = async (licence_no) => {
44-
return await requestWithErrorCatch(`${env.VITE_BASE_API_URL}/watershed/licences/search?licence_no=${licence_no}`)
43+
return await requestWithErrorCatch(`${env.VITE_BASE_API_URL}/watershed/licences/search?licence_no=${licence_no}`, 'search')
4544
}
4645

4746
export const getPlaceByNameSearch = async (location_name) => {
48-
return await requestWithErrorCatch(`${env.VITE_BASE_API_URL}/watershed/location/search?location_name=${location_name}`)
47+
return await requestWithErrorCatch(`${env.VITE_BASE_API_URL}/watershed/location/search?location_name=${location_name}`, 'search')
4948
}
5049

5150
export const getWatershedByLatLng = async (lngLat) => {
@@ -67,7 +66,7 @@ export const getWaterPortalStations = async (viewType) => {
6766
else if(viewType === 'surface') response = await getSurfaceWaterStations();
6867
else if(viewType === 'ground') response = await getGroundWaterQualityStations();
6968
else if(viewType === 'climate') response = await getClimateStations();
70-
return response;
69+
return response;
7170
}
7271

7372
export const getWaterPortalReportDataByIdAndType = async (id, viewType) => {
@@ -77,7 +76,7 @@ export const getWaterPortalReportDataByIdAndType = async (id, viewType) => {
7776
else if(viewType === 'surface') response = await getSurfaceWaterReportDataById(id);
7877
else if(viewType === 'ground') response = await getGroundWaterQualityReportById(id);
7978
else if(viewType === 'climate') response = await getClimateReportById(id);
80-
return response;
79+
return response;
8180
}
8281

8382
export const getStreamflowStations = async () => {

client/src/utils/mapHelpers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,17 @@ export const createMarker = (marker = null, mapObj, coords) => {
117117
marker = new mapboxgl.Marker()
118118
.setLngLat({ lng: coords[0], lat: coords[1]})
119119
.addTo(mapObj)
120-
120+
121121
return marker
122-
}
122+
};
123123

124124
export const goToLocation = (polygon, mapObj) => {
125125
const boundingBox = bbox(polygon);
126126
mapObj.fitBounds(boundingBox, { padding: 50 });
127127
};
128128

129129
/**
130-
*
130+
*
131131
* @param viewType the current water portal view type
132132
* @param points list of points to generate filters from
133133
* @returns {Object} filterable properties object
@@ -203,7 +203,7 @@ export const getFilterablePropertiesByViewType = (viewType, points) => {
203203
min: Math.min(...min),
204204
max: Math.max(...max)
205205
}
206-
206+
207207
if(viewType === 'streams') {
208208
defaultFilters.uniqueFilters.hasArea = true;
209209
}

0 commit comments

Comments
 (0)