Search component with multiple sources

Search-component-with-multisource

This sample demonstrates how to use the Search component to search multiple Layer Sources based on given fields. The search component provides the capability to search features in Layers or geocode locations with a locator. By default, the Search component will focus the map on the SearchResult. The level of detail (LOD) at the center of the map depends on the data source, with higher quality data sources returning extents closer to the feature obtained from the search.

To use multiple sources with the Search component, you must set the component's sources property.

The geocoding service requires a token for authentication. This sample uses an API Key to authenticate. You can either replace it with your own API Key, or remove it and log in once prompted. Alternatively, you can use another authentication method to access the geocoding service.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
      const search = document.querySelector("arcgis-search");
      await search.componentOnReady();
      // set the search sources once the component is ready
      search.sources = [
        {
          layer: featureLayerDistricts,
          searchFields: ["DISTRICTID"],
          displayField: "DISTRICTID",
          exactMatch: false,
          outFields: ["DISTRICTID", "NAME", "PARTY"],
          name: "Congressional Districts",
          placeholder: "example: 3708",
        },
        {
          layer: featureLayerSenators,
          searchFields: ["Name", "Party"],
          suggestionTemplate: "{Name}, Party: {Party}",
          exactMatch: false,
          outFields: ["*"],
          placeholder: "example: Casey",
          name: "Senators",
          zoomScale: 500000,
          resultSymbol: {
            type: "picture-marker", // autocasts as new PictureMarkerSymbol()
            url: "/javascript/latest//sample-code/search-component-multisource/live/images/senate.png",
            height: 36,
            width: 36,
          },
        },
        {
          name: "ArcGIS World Geocoding Service",
          placeholder: "example: Nuuk, GRL",
          singleLineFieldName: "SingleLine",
          apiKey: "YOUR_ACCESS_TOKEN",
          url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer",
        },
      ];

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.