Hi
I migrated from arcgis java script 4.9 to 4.11, after migration the "Search Widget" don't work!!
Solved! Go to Solution.
Anjelina,
In 4.11 the search widgets layer property takes a Layer class and not specifically a FeatureLayer class so you can not autocast as FeatureLayer as you use to in 4.9 when it was Only expecting a FeatureLayer. So your code would need to look like:
var searchWidget = new Search({
view: view,
allPlaceholder: "search...",
sources: [{
layer: new FeatureLayer({ //Notice the property is called layer Not featureLayer
url: "localhost:6080/arcgis/rest/services/city/FeatureServer/0",
popupTemplate: { // autocasts as new PopupTemplate()
title: "name: {name2} </br>{name_new}",
overwriteActions: true
}
}),
searchFields: ["name2"],
displayField: "name2",
exactMatch: false,
outFields: ["name2", "name2"],
name: "name2",
placeholder: "name2",
maxResults:10,
maxSuggestions:50,
autoNavigate: true,
//enableSuggestions: true //This is not a property of a layerSearchSource
}, {
...
Hi anjelina ponkerat,
Your issue is most probably caused by differences between the two versions of the ArcGIS API for JavaScript, version 4.9 and 4.11. So, just migrating to the new version apparently is not enough - because this breaks your application.
The best way forward is to keep the 4.9 app in production until you have rewritten and fully tested the new 4.11 app.
Here you can find a 4.11 sample for the Search Widget | ArcGIS API for JavaScript 4.11
HTH,
Egge-Jan
But what's the reason of this problem? I searched release note of 4.11 and didn't find any changes in new version(4.11)
Anjelina,
There have been several changes to the search widget and new classes added that the widget now uses. So it is hard to say without seeing your code what the issue is. If you go to the release notes https://developers.arcgis.com/javascript/latest/guide/release-notes/ and search for the word "search" you will find that there are new classes and new methods added in 4.11 and other change in 4.10. https://developers.arcgis.com/javascript/latest/guide/4.10/index.html
var searchWidget = new Search({
view: view,
allPlaceholder: "search...",
sources: [{
featureLayer: {
url: "localhost:6080/arcgis/rest/services/city/FeatureServer/0",
popupTemplate: { // autocasts as new PopupTemplate()
title: "name: {name2} </br>{name_new}",
overwriteActions: true
}
},
searchFields: ["name2"],
displayField: "name2",
exactMatch: false,
outFields: ["name2", "name2"],
name: "name2",
placeholder: "name2",
maxResults:10,
maxSuggestions:50,
autoNavigate: true,
enableSuggestions: true
}, {
featureLayer: {
url: "localhost:6080/arcgis/rest/services/city/FeatureServer/1",
popupTemplate: { // autocasts as new PopupTemplate()
title: "name: {cc} </br>{c1cc}",
overwriteActions: true
}
},
searchFields: ["cc"],
displayField: "cc",
exactMatch: false,
outFields: ["cc", "c1cc"],
name: "search1",
placeholder: "search1",
exactMatch: true,
zoomScale:13000,
maxResults:10,
maxSuggestions:50,
autoNavigate: true,
enableSuggestions: true
}]
});
view.ui.add(searchWidget, {
position: "top-left",
index: 2
});
Anjelina,
In 4.11 the search widgets layer property takes a Layer class and not specifically a FeatureLayer class so you can not autocast as FeatureLayer as you use to in 4.9 when it was Only expecting a FeatureLayer. So your code would need to look like:
var searchWidget = new Search({
view: view,
allPlaceholder: "search...",
sources: [{
layer: new FeatureLayer({ //Notice the property is called layer Not featureLayer
url: "localhost:6080/arcgis/rest/services/city/FeatureServer/0",
popupTemplate: { // autocasts as new PopupTemplate()
title: "name: {name2} </br>{name_new}",
overwriteActions: true
}
}),
searchFields: ["name2"],
displayField: "name2",
exactMatch: false,
outFields: ["name2", "name2"],
name: "name2",
placeholder: "name2",
maxResults:10,
maxSuggestions:50,
autoNavigate: true,
//enableSuggestions: true //This is not a property of a layerSearchSource
}, {
...