This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aaa52f
commit 93dcc30
Showing
3 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
define([ | ||
"esri/widgets/Search", | ||
"esri/widgets/Search/SearchSource", | ||
"esri/Graphic", | ||
"esri/geometry/Point", | ||
"esri/request", | ||
"esri/geometry/geometryEngine", | ||
], (Search, SearchSource, Graphic, Point, esriRequest, geometryEngine) => ({ | ||
setupCustomSearchSource: (url) => | ||
new SearchSource({ | ||
placeholder: "Find address with IN-ADS API", | ||
// Provide a getSuggestions method | ||
// to provide suggestions to the Search widget | ||
getSuggestions: (params) => { | ||
const keyword = params.suggestTerm; // keyword input by user | ||
const suggestUrl = `${url}?address=${encodeURIComponent(keyword)}`; | ||
return esriRequest(suggestUrl, { responseType: "json" }).then( | ||
(results) => { | ||
// Return Suggestion results to display | ||
// in the Search widget | ||
return results.data.addresses.map((address) => { | ||
return { | ||
text: address.pikkaadress, | ||
magicKey: address.unik, | ||
}; | ||
}); | ||
} | ||
); | ||
}, | ||
|
||
//Provide a getResults method to find | ||
//results from the suggestions | ||
getResults: (params) => { | ||
const key = params.suggestResult.text; // keyword input by user | ||
const newUrl = `${url}?address=${encodeURIComponent(key)}`; | ||
return esriRequest(newUrl, { | ||
responseType: "json", | ||
}).then((results) => { | ||
// Parse the results of your custom search | ||
|
||
const searchResults = results.data.addresses.map((address) => { | ||
const graphic = new Graphic({ | ||
geometry: new Point({ | ||
x: address.viitepunkt_l, | ||
y: address.viitepunkt_b, | ||
}), | ||
}); | ||
//Optionally,provide an extent for a point result, so the view can zoom to it | ||
const buffer = geometryEngine.geodesicBuffer( | ||
graphic.geometry, | ||
30, | ||
"meters" | ||
); | ||
// Return a Search Result | ||
const searchResult = { | ||
extent: buffer.extent, | ||
feature: graphic, | ||
//name: address.pikkaadress, | ||
name: `${address.pikkaadress}\n(ads_oid=${address.ads_oid})`, | ||
}; | ||
|
||
return searchResult; | ||
}); | ||
|
||
// Return an array of Search Results | ||
return searchResults; | ||
}); | ||
}, | ||
}), | ||
|
||
setupSearchWidget: (view, sources) => | ||
new Search({ | ||
view: view, | ||
sources: [sources], | ||
includeDefaultSources: false, | ||
}), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters