Search widget locator filter

633
4
Jump to solution
09-11-2018 01:04 PM
AlexGole4
Occasional Contributor

Hi all,

I am using the ArcGIS Javascript 4.x and try to apply the filter in the documentation but I am not getting it to work. I want the suggested results to be only "California".

Code is here. 

//Search widget here
            var searchWidget = new Search({
                view: view,
                popupEnabled: false,
                popupOpen: false,
                resultGraphicEnabled: false,
                includeDefaultSources: false,
               
                sources: // Default sources[] when sources is not specified
                [
                    {
                        locator: new Locator({ url: "//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer" }),
                        singleLineFieldName: "SingleLine",
                        outFields: ["Addr_type"],
                        name: "ArcGIS World Geocoding Service",
                        placeholder: "Enter an address",
                        resultSymbol: {
                            type: "picture-marker",  // autocasts as new PictureMarkerSymbol()
                            url: this.basePath + "/images/search/search-symbol-32.png",
                            size: 24,
                            width: 24,
                            height: 24,
                            xoffset: 0,
                            yoffset: 0
                        },
                        filter: "State =" + "'" + "California" + "'",
                    }
                ]
            }, "search");

Any idea?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Alex,

   The filter property is expecting an object with a property of where.

            //Search widget here
            var searchWidget = new Search({
                view: view,
                popupEnabled: false,
                popupOpen: false,
                resultGraphicEnabled: false,
                includeDefaultSources: false,
               
                sources: // Default sources[] when sources is not specified
                [
                    {
                        locator: new Locator({ url: "//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer" }),
                        singleLineFieldName: "SingleLine",
                        outFields: ["Addr_type"],
                        name: "ArcGIS World Geocoding Service",
                        placeholder: "Enter an address",
                        resultSymbol: {
                            type: "picture-marker",  // autocasts as new PictureMarkerSymbol()
                            url: this.basePath + "/images/search/search-symbol-32.png",
                            size: 24,
                            width: 24,
                            height: 24,
                            xoffset: 0,
                            yoffset: 0
                        },
                        filter: {where: "State = 'California'"},
                    }
                ]
            }, "search");

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Alex,

   The filter property is expecting an object with a property of where.

            //Search widget here
            var searchWidget = new Search({
                view: view,
                popupEnabled: false,
                popupOpen: false,
                resultGraphicEnabled: false,
                includeDefaultSources: false,
               
                sources: // Default sources[] when sources is not specified
                [
                    {
                        locator: new Locator({ url: "//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer" }),
                        singleLineFieldName: "SingleLine",
                        outFields: ["Addr_type"],
                        name: "ArcGIS World Geocoding Service",
                        placeholder: "Enter an address",
                        resultSymbol: {
                            type: "picture-marker",  // autocasts as new PictureMarkerSymbol()
                            url: this.basePath + "/images/search/search-symbol-32.png",
                            size: 24,
                            width: 24,
                            height: 24,
                            xoffset: 0,
                            yoffset: 0
                        },
                        filter: {where: "State = 'California'"},
                    }
                ]
            }, "search");

View solution in original post

AlexGole4
Occasional Contributor

I am not not too sure what field to query to get only california (World geocoder from ESRI)  related suggested results so I went ahead and used a geometry retrieved from a MapImageservice and input it in the search widget and it does not seem to  return only california addresses. Am I missing something here?

 var query = new Query();
            query.where = "NAME = 'California'";
            query.returnGeometry = true;
            var geomcalifornia;

            queryTask.execute(query).then(function (results) {
                console.log(results.features[0].geometry);
                geomcalifornia = results.features[0].geometry;

            });


//Search widget here
            var searchWidget = new Search({
                view: view,
                popupEnabled: false,
                popupOpenOnSelect: false,
                resultGraphicEnabled: false,
                includeDefaultSources: false,
               
                sources: // Default sources[] when sources is not specified
                [
                    {
                        locator: new Locator({ url: "//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer" }),
                        singleLineFieldName: "SingleLine",
                        outFields: ["Addr_type"],
                        name: "ArcGIS World Geocoding Service",
                        placeholder: "Enter an address",
                        resultSymbol: {
                            type: "picture-marker",  // autocasts as new PictureMarkerSymbol()
                            url: this.basePath + "/images/search/search-symbol-32.png",
                            size: 24,
                            width: 24,
                            height: 24,
                            xoffset: 0,
                            yoffset: 0
                        },
                        filter: { geomcalifornia }
                    }
                ]
            }, "search");‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Alex,

   Again the filter is expecting an object with certain properties.

filter: { geometry: geomcalifornia }
0 Kudos
AlexGole4
Occasional Contributor

That did the trick. Thank you Robert!

0 Kudos