diff --git a/packages/nuxt-ripple/app.config.ts b/packages/nuxt-ripple/app.config.ts index ce7f3ff82e..7b78ba329b 100644 --- a/packages/nuxt-ripple/app.config.ts +++ b/packages/nuxt-ripple/app.config.ts @@ -48,6 +48,17 @@ declare module '@nuxt/schema' { string, (map: any, results: any, location: any, mapDeadSpace: any) => void > + onLocationSelectOverrideFns: Record< + string, + // Return true if behaviour was overridden, or false to use the default behaviour + ( + map: any, + popup: any, + location: any, + userGeolocation: any, + mapDeadSpace: any + ) => boolean | void + > } customInputs?: { [key: string]: { diff --git a/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue b/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue index bb1b310ac3..e4dcc66568 100644 --- a/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue +++ b/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue @@ -82,6 +82,7 @@ interface Props { function: string args: Record } + onLocationSelectOverrideFn?: string | null } const props = withDefaults(defineProps(), { @@ -95,7 +96,8 @@ const props = withDefaults(defineProps(), { tagsComponent: undefined, mapResultsFnName: '', isGettingLocation: false, - userGeolocation: null + userGeolocation: null, + onLocationSelectOverrideFn: null }) const results = ref([]) @@ -104,7 +106,7 @@ const emit = defineEmits<{ (e: 'update', payload: addressResultType): void }>() -const { rplMapRef, deadSpace, defaultExtent } = inject('rplMapInstance') +const { rplMapRef, popup, deadSpace, defaultExtent } = inject('rplMapInstance') const pendingZoomAnimation = ref(false) @@ -217,6 +219,42 @@ async function centerMapOnLocation( location: addressResultType, animate: boolean ) { + // There is the option of overriding the default zoom behavior by passing in an app config function + // + // In app.config.ts: + // { + // ripple: { + // search: { + // onLocationSelectOverrideFns: + // } + // } + // } + // + if (props.onLocationSelectOverrideFn) { + const overrideFn = useAppConfigFunction( + props.onLocationSelectOverrideFn, + 'onLocationSelectOverrideFns' + ) + + const didOverride = overrideFn( + map, + popup, + location, + props.userGeolocation, + deadSpace + ) + + // Sometimes you only want to override the behavior for a specific behavior, and it would be + // annoying to have to reimplement everything else. For this reason, the function can return a + // boolean indicating whether the behavior was overridden. If false, the default behavior will + // still run. + // + // If the function doesn't return anything (i.e. undefined), the default behavior won't run + if (didOverride || typeof didOverride === undefined) { + return + } + } + if (!props.controlMapZooming) { return } diff --git a/packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts b/packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts index 2cfd35424b..70db975181 100644 --- a/packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts +++ b/packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts @@ -57,6 +57,7 @@ const getLGASuggestions = async (query, args) => { return { id: itm._id, name, + lgaOfficialName: itm._source.lga_official_name, bbox: itm._source.lga_bbox, tag }