Hi,
,I need to search items in my GraphicsLayer
one thing came to mind is to create feature layer from my graphics layer, and add it to the the search widget...
my problem is that I have no results
I used the following code for the transformation: (testing code)
function CreateFeatureGraphics(graphics) {
var x = [];
graphics.forEach(function (g) {
var item =
{
geometry: g.geometry,
attributes:
{
ObjectID: g.id,
Name: g.attributes.Name
}
};
x.push(item);
});
return x;
}
function CreateLayer(graphics) {
var g = CreateFeatureGraphics(graphics.items);
var fields = [
{
name: "ObjectID",
alias: "ObjectID",
type: "oid"
}, {
name: "Name",
alias: "Name",
type: "string"
}];
lyr = new FeatureLayer({
source: g,
fields: fields,
objectIdField: "ObjectID",
spatialReference: {
wkid: 4326
},
geometryType: "point",
popupTemplate: template
});
return lyr;
}
function UpdateSearch() {
var src =
[{
featureLayer: CreateLayer(dataLayer.graphics),
searchFields: ["ObjectID"],
displayField: "NAME",
exactMatch: false,
outFields: ["*"],
name: "Local Items",
suggestionsEnabled: true,
placeholder: "Pole 1522"
},
{
locator: new Locator("
singleLineFieldName: "SingleLine",
outFields: ["Addr_type"],
name: "Adress"
}
];
app.searchWidget.sources = src;
console.log(app.searchWidget);
app.searchWidget.startup();
}