Hide Table of Contents
View Search with customization sample in sandbox
Search with customization

Description

This sample demonstrates how it is possible to customize the look of the default Search widget. In this case, different colors were applied in addition to a different zoom icon. The search result's popup is also customized to display different colors. The widget is set to work with ahosted ArcGIS Online feature service layer and is configured to only work with this feature layer, excluding the default geocoding service.

The data was taken from the Global Footprint Network. More information on the feature service layer used in this sample can be foundhere.

The search icon image icon was made bySimpleicon. FreepikfromFlaticonis licensed byCreative Commons BY 3.0.

Code

<!DOCTYPE html>
<html dir="ltr">

<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
   <title>ArcGIS API for JavaScript | Customize Search widget</title>
   <link rel="stylesheet" href="https://js.arcgis.com/3.29/dijit/themes/claro/claro.css">
   <link rel="stylesheet" href="https://js.arcgis.com/3.29/esri/css/esri.css">
   <style>
      html,
      body,
      #map,
      .map.container {
         padding: 0;
         margin: 0;
         height: 100%;
         width: 100%;
      }
      #info {
         top: 2px;
         color: #444;
         height: auto;
         font-family: arial;
         font-weight: bold;
         left: 69px;
         margin: 5px;
         padding: 10px;
         position: absolute;
         width: 260px;
         z-index: 40;
         border: solid 1px #003300;
         border-radius: 4px;
         background-color: #E5E5E5;
      }
      #search {
         display: block;
         position: absolute;
         z-index: 2;
         top: 70px;
         left: 74px;
      }
      /*Beginning of search box modifications*/
      .arcgisSearch .searchClear {
         background-color: #E5E5E5;
      }
      .arcgisSearch .esri-icon-search {
         background-image: url("finding.png");
         background-size: 20px 20px;
      }
      .esri-icon-search:before {
         content: "";
      }
      .arcgisSearch .searchGroup .searchInput,
      .arcgisSearch .searchBtn,
      .arcgisSearch .noResultsMenu,
      .arcgisSearch .suggestionsMenu {
         border: 1px solid #003300;
         background-color: #E5E5E5;
      }
      .arcgisSearch .noValueText {
         color: red;
         font-size: 14px;
      }
      /*Beginning of popup modifications*/
      .esriPopup .titlePane {
         background-color: #003300;
         border-bottom: 1px solid #121310;
         font-weight: bold;
      }
      .esriPopup a {
         color: #DAE896;
      }
      .esriPopup .contentPane,
      .esriPopup .actionsPane,
      .esriPopup .pointer,
      .esriPopup .outerPointer {
         background-color: #B3B3B3;
      }
   </style>

   <script>
      var dojoConfig = {
         parseOnLoad: true
      };
   </script>
   <script src="https://js.arcgis.com/3.29/"></script>

   <script>
      var map;

      require([
      "esri/map",
      "esri/layers/FeatureLayer",
      "esri/dijit/Search",
      "esri/InfoTemplate",
      "dojo/domReady!"
      ], function (Map, FeatureLayer, Search, InfoTemplate) {

         map = new Map("map", {
            basemap: "gray",
            center: [0, 51], // lon, lat
            zoom: 4
         });

         //ArcGIS Online feature service showing ecological footprints taken from Global FootPrint Network,
         //more information on this can be found http://jsapi.maps.arcgis.com/home/item.html?id=0f4c89208dce44b583d9219d843591c3
         var layer = new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Ecological_Footprint/FeatureServer/0", {
            outFields: ["*"]
         });
         map.addLayer(layer);

         //Create search widget
         var search = new Search({
            map: map,
            //passing in empty source array to clear defaults such as
            //"All" and the ArcGIS Online World Geocoding service
            sources: [],
            zoomScale: 5000000
         }, "search");

         //listen for the load event and set the source properties
         search.on("load", function () {

            var sources = search.sources;
            sources.push({
               featureLayer: layer,
               placeholder: "Spain",
               enableLabel: false,
               searchFields: ["Country"],
               displayField: "Country",
               exactMatch: false,
               outFields: ["*"],

               //Create an InfoTemplate and include three fields
               infoTemplate: new InfoTemplate("Ecological Footprint", "Country: ${Country}</br>Rating: ${Rating}")

            });
            //Set the sources above to the search widget
            search.set("sources", sources);
         });
         search.startup();
      });
   </script>
</head>

<body>
   <div id="search"></div>
   <div id="info">
      <div>Search a country to find its ecological footprint and rating.</div>
   </div>
   <div id="map"></div>
</body>

</html>
 
          
Show Modal