Skip to content

Commit

Permalink
Merge pull request #1365 from dpc-sdp/feature/SD-457-kyc-updates
Browse files Browse the repository at this point in the history
[SD-457] Added ability to override default map zoom behaviour
  • Loading branch information
jeffdowdle authored Nov 7, 2024
2 parents 7780b8f + 6c59ffa commit 1f04ef3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/nuxt-ripple/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface Props {
function: string
args: Record<string, any>
}
onLocationSelectOverrideFn?: string | null
}
const props = withDefaults(defineProps<Props>(), {
Expand All @@ -95,7 +96,8 @@ const props = withDefaults(defineProps<Props>(), {
tagsComponent: undefined,
mapResultsFnName: '',
isGettingLocation: false,
userGeolocation: null
userGeolocation: null,
onLocationSelectOverrideFn: null
})
const results = ref([])
Expand All @@ -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)
Expand Down Expand Up @@ -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: <function>
// }
// }
// }
//
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1f04ef3

Please sign in to comment.