diff --git a/src/components/search-wizard/filters/StreetAddress.jsx b/src/components/search-wizard/filters/StreetAddress.jsx index c48a207b..7bf7c910 100644 --- a/src/components/search-wizard/filters/StreetAddress.jsx +++ b/src/components/search-wizard/filters/StreetAddress.jsx @@ -31,7 +31,7 @@ export default function StreetAddress({ send }) { 3857, ); setSherlockConfig({ - placeHolder: 'search by street address...', + placeHolder: 'street address, city or zip', onSherlockMatch: (features) => setAddress(features[0]), provider, maxResultsToDisplay: 10, @@ -41,7 +41,7 @@ export default function StreetAddress({ send }) { return ( <> - {sherlockConfig && } + {sherlockConfig && } {/* buffer to make sure user can scroll far enough to see the entire select filter type dropdown */}
diff --git a/src/utah-design-system/Sherlock.jsx b/src/utah-design-system/Sherlock.jsx index 0de60af9..e3f9a239 100644 --- a/src/utah-design-system/Sherlock.jsx +++ b/src/utah-design-system/Sherlock.jsx @@ -75,14 +75,19 @@ export default function Sherlock({ const searchValue = getSearchValue(selectedItem); - let contextValue; - if (provider.contextField) { - contextValue = selectedItem.attributes[provider.contextField]; - } + let results; + if (searchValue) { + let contextValue; + if (provider.contextField) { + contextValue = selectedItem.attributes[provider.contextField]; + } - const response = await provider.getFeature(searchValue, contextValue); + const response = await provider.getFeature(searchValue, contextValue); - const results = response.items; + results = response.items; + } else { + results = [selectedItem]; + } const graphics = results.map( (result) => @@ -213,7 +218,7 @@ export default function Sherlock({ const getMenuItems = () => { const commonClasses = - 'rounded-md border border-slate-400 rounded-md px-2 py-1'; + 'rounded-md border border-slate-400 rounded-md px-2 py-1 cursor-pointer'; if (state.short) { return ( // primary @@ -254,7 +259,7 @@ export default function Sherlock({ })} > @@ -646,6 +651,31 @@ export class LocatorSuggestProvider extends ProviderBase { } async search(searchString, maxResults) { + if (searchString.match(',')) { + const findCandidatesUrl = `${this.url}/findAddressCandidates`; + const responseJson = await ky(findCandidatesUrl, { + searchParams: { + 'Single Line Input': searchString, + outSR: `{"wkid":${this.outSRID}}`, + }, + }).json(); + + if (responseJson.candidates.length === 0) { + return { items: [] }; + } + + const candidate = responseJson.candidates[0]; + candidate.geometry = { + ...candidate.location, + type: 'point', + spatialReference: { + wkid: this.outSRID, + }, + }; + + return { items: [candidate] }; + } + const suggestUrl = `${ this.url }/suggest?text=${searchString}&maxSuggestions=${maxResults || 10}`;