Select to view content in your preferred language

Is there something similar to the District Lookup Widget for JavaScript Maps SDK?

545
3
10-19-2023 07:21 AM
JaredPilbeam2
MVP Regular Contributor

Is there something similar to the District Lookup Widget you can use with the JavaScript SDK?

I'd like to search an address and display the features of a hosted feature layer.  Using the Search widget with multiple sources example , it allows me to search by features of a feature layer, however this requires the user to know what to look for. I'm looking enter an address to get the feature and its attributes--something similar to the District Lookup Widget.

This is what I currently have using the search widget.

 

<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Access Will County</title>

    <style>
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>

    <link rel="stylesheet" href="https://js.arcgis.com/4.27/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.27/"></script>

    <script>
        require(["esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/widgets/Search"], (
            Map,
            MapView,
            FeatureLayer,
            Search
        ) => {
            const map = new Map({
                basemap: "dark-gray-vector"
            });

            const view = new MapView({
                container: "viewDiv",
                map: map,
                center: [-88, 41.5], // lon, lat
                scale: 1000000
            });

            const featureLayerService = new FeatureLayer({
                url:
                    "https://services.arcgis.com/fGsbyIOAuxHnF97m/arcgis/rest/services/DialARide_Service_Areas/FeatureServer",
                popupTemplate: {
                    // autocasts as new PopupTemplate()
                    title: "Service Area: {Service}",
                    overwriteActions: true
                }
            });

            const searchWidget = new Search({
                view: view,
                //   allPlaceholder: "Search",
                searchAllEnabled: false,
                includeDefaultSources: false,
                sources: [
                    {
                        name: "Search by address",
                        placeholder: "search by address",
                        apiKey: "Your API Key Here",
                        singleLineFieldName: "SingleLine",
                        url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer"
                    },
                    {
                        layer: featureLayerService,
                        searchFields: ["Service"],
                        displayField: "Service",
                        exactMatch: false,
                        outFields: ["Service"],
                        name: "Search by Service Area",
                        placeholder: "example: Will Ride"
                    }
                ]
            });

            // Add the search widget to the top left corner of the view
            view.ui.add(searchWidget, {
                position: "top-right"
            });
        });
    </script>
</head>

<body>
    <div id="viewDiv"></div>
</body>

</html>

 

 

 

0 Kudos
3 Replies
vmvargas
Occasional Contributor

Try this one code

const searchWidget = new Search({
view: view,
includeDefaultSources: false,
sources: [{
url: "https://__________/arcgis/rest/services/GeocodeServer",
name: "LocatorSearchSource",
singleLineFieldName: "street",
autoComplete: true,
zoomScale: 2000,
placeholder: "***************",
locationEnabled: false,
exactMatch: false,
maxResults: 3,
maxSuggestions: 10,
suggestionsEnabled: true,
minSuggestCharacters: 0,
displayField: "Street",
outFields: ["Street", "Score"],
//prefix: '%',
//suffix: '',
resultSymbol: {
type: "picture-marker",
url: "https:/PIN.png",
height: 20
}
}]
});

0 Kudos
NataliyaLys
Frequent Contributor

@JaredPilbeam2 were you able to accomplish this? I'm trying to do the something, and cannot figure out how to do that. I'm very new to SDK, and coding in general. 

I would appreciate if you can share your script, if you have it working. Thank you!

0 Kudos
JaredPilbeam2
MVP Regular Contributor

Hi @NataliyaLys 

No, i put it on the back burner while I unknowningly wait for it to be added to ExB. The app that uses that widget is still in WAB, which is set to be retired at the end of 2025. I'm subscribed to the Idea page.

0 Kudos