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?
Solved! Go to Solution.
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");
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");
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");
Alex,
Again the filter is expecting an object with certain properties.
filter: { geometry: geomcalifornia }
That did the trick. Thank you Robert!