<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: search widget with custom source: swiss search service in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193379#M77963</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7384"&gt;@ReneRubalcava&lt;/a&gt;&amp;nbsp;! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;I think, step 1 has to be, to match the search url to one of the examples of the swiss API. So, I tried to create the url to match this:&lt;/P&gt;&lt;P data-unlink="true"&gt;https://api3.geo.admin.ch/rest/services/api/SearchServer?searchText=wabern&amp;amp;type=locations&amp;nbsp;&lt;/P&gt;&lt;P&gt;Somehow I get some additional characters in my url:&lt;/P&gt;&lt;P data-unlink="true"&gt;https://api3.geo.admin.ch/rest/services/api/SearchServer?searchText&amp;nbsp;&lt;STRONG&gt;%2F=&amp;amp;q&lt;/STRONG&gt;=wabern&amp;amp;type=locations&lt;/P&gt;&lt;P&gt;I prepared a Codepen:&amp;nbsp;&lt;A href="https://codepen.io/nwp_nadja_bernhard/pen/KKoWqWW?editors=0011" target="_blank" rel="noopener"&gt;https://codepen.io/nwp_nadja_bernhard/pen/KKoWqWW?editors=0011&lt;/A&gt;&lt;/P&gt;&lt;P&gt;So my questions are:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Where does "&amp;amp;q=" come from?&lt;/LI&gt;&lt;LI&gt;Where does "%2F" come from?&lt;/LI&gt;&lt;LI&gt;What does&amp;nbsp;&amp;nbsp;"q: params.suggestTerm.replace(/ /g, "+")," do exactly? (line 74)&lt;/LI&gt;&lt;LI&gt;Why would I need&amp;nbsp;&amp;nbsp;"lat: view.center.latitude," in the getSuggestions method? (line 77)&lt;/LI&gt;&lt;LI&gt;What is a sourceIndex? the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html#getResults" target="_self"&gt;documentation&lt;/A&gt; is a bit ambiguous... (line87)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html#RequestResponse" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html#RequestResponse&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jul 2022 13:42:35 GMT</pubDate>
    <dc:creator>nadja</dc:creator>
    <dc:date>2022-07-19T13:42:35Z</dc:date>
    <item>
      <title>search widget with custom source: swiss search service</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193027#M77953</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;We're updating vom 3.x to 4.x. In the 3.x version we used the swiss search service for the search widget. Now we'd like to use a search widget in 4.x with the swiss search service as it is a bit more accurate. Therefore, I tried to modify this&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/widgets-search-customsource/" target="_self"&gt;sample code&lt;/A&gt;&amp;nbsp;and to use the &lt;A href="https://api3.geo.admin.ch/services/sdiservices.html#search" target="_self"&gt;swiss Search API&lt;/A&gt; instead of the french one. I didn't manage.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I searched these documentations:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#sources" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#sources&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-LocatorSearchSource.html#apiKey" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-LocatorSearchSource.html#apiKey&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://groups.google.com/g/geoadmin-api" target="_blank"&gt;https://groups.google.com/g/geoadmin-api&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Are there any tutorials which explain the use of a custom search source generally? What do I need to put where? (for dummies)&lt;/P&gt;&lt;P&gt;or even better: has anyone already managed to use the swiss search service with the search widget of the arcgis API for javascript 4.x?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 17:29:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193027#M77953</guid>
      <dc:creator>nadja</dc:creator>
      <dc:date>2022-07-18T17:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: search widget with custom source: swiss search service</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193165#M77955</link>
      <description>&lt;P&gt;The main things you need to write are a getSuggestions and getResults method.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That API looks like it takes a searchText and limit, so you can use that for the suggestions. You need to transform those into a SuggestResult, with key, text, and sourceIndex.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#SuggestResult" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#SuggestResult&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The getResults should return an array of SearchResults&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#SearchResult" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#SearchResult&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 20:33:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193165#M77955</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-07-18T20:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: search widget with custom source: swiss search service</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193379#M77963</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7384"&gt;@ReneRubalcava&lt;/a&gt;&amp;nbsp;! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;I think, step 1 has to be, to match the search url to one of the examples of the swiss API. So, I tried to create the url to match this:&lt;/P&gt;&lt;P data-unlink="true"&gt;https://api3.geo.admin.ch/rest/services/api/SearchServer?searchText=wabern&amp;amp;type=locations&amp;nbsp;&lt;/P&gt;&lt;P&gt;Somehow I get some additional characters in my url:&lt;/P&gt;&lt;P data-unlink="true"&gt;https://api3.geo.admin.ch/rest/services/api/SearchServer?searchText&amp;nbsp;&lt;STRONG&gt;%2F=&amp;amp;q&lt;/STRONG&gt;=wabern&amp;amp;type=locations&lt;/P&gt;&lt;P&gt;I prepared a Codepen:&amp;nbsp;&lt;A href="https://codepen.io/nwp_nadja_bernhard/pen/KKoWqWW?editors=0011" target="_blank" rel="noopener"&gt;https://codepen.io/nwp_nadja_bernhard/pen/KKoWqWW?editors=0011&lt;/A&gt;&lt;/P&gt;&lt;P&gt;So my questions are:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Where does "&amp;amp;q=" come from?&lt;/LI&gt;&lt;LI&gt;Where does "%2F" come from?&lt;/LI&gt;&lt;LI&gt;What does&amp;nbsp;&amp;nbsp;"q: params.suggestTerm.replace(/ /g, "+")," do exactly? (line 74)&lt;/LI&gt;&lt;LI&gt;Why would I need&amp;nbsp;&amp;nbsp;"lat: view.center.latitude," in the getSuggestions method? (line 77)&lt;/LI&gt;&lt;LI&gt;What is a sourceIndex? the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html#getResults" target="_self"&gt;documentation&lt;/A&gt; is a bit ambiguous... (line87)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html#RequestResponse" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html#RequestResponse&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 13:42:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193379#M77963</guid>
      <dc:creator>nadja</dc:creator>
      <dc:date>2022-07-19T13:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: search widget with custom source: swiss search service</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193533#M77969</link>
      <description>&lt;P&gt;Custom Search sources are going to vary based on what third-party API you are using. So you need to be familiar with the parameters that API needs.&lt;/P&gt;&lt;P&gt;The samples are using the esriRequest to make the queries, but you don't have to. You can use native fetch, or axios, or any other request style library you are comfortable with.&lt;BR /&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html&lt;/A&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The ?q= is created by esriRequest, because that is how the sample API needs to be parsed. Your API is different.&lt;/LI&gt;&lt;LI&gt;The %2F comes from url encoding. Without going into detail, this is how URL requests get encoded to escape special characters. This is standard.&lt;/LI&gt;&lt;LI&gt;This was specific to the sample API being used, your API will require different parameters.&lt;/LI&gt;&lt;LI&gt;Your API doesn't need the lat/lon parameters, so you can omit them.&lt;/LI&gt;&lt;LI&gt;The sourceIndex is the index of the search source being referenced. This is given to you in the parameters of the getSuggestions method.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html#GetSuggestionsParameters" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html#GetSuggestionsParameters&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The power of using custom search sources is that you can transform any searchable third-party API into something that be used by the Search widget, meaning each API will need to handled on a case by case basis. The API parameters will differ, the results will differ, but as long as you transform those results into something the ArcGIS JSAPI expects, you can make it work.&lt;/P&gt;&lt;P&gt;This Swiss search API can return GeoJSON results, so that makes it a little easier to work with, but you need to specify the spatial reference as well.&lt;/P&gt;&lt;P&gt;Here is an update to your app that uses the parameters as described in that search API doc and seems to work correctly.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/odoe/pen/QWmpVdQ?editors=0011" target="_blank"&gt;https://codepen.io/odoe/pen/QWmpVdQ?editors=0011&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 17:03:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-widget-with-custom-source-swiss-search/m-p/1193533#M77969</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-07-19T17:03:13Z</dc:date>
    </item>
  </channel>
</rss>

