// Function to fetch features by a specific field
async function fetchFeaturesByField(fieldName, fieldValue, view) {
const query = featureLayer.createQuery();
// Set the query parameters
query.where = `${fieldName} = '${fieldValue}'`; // Field-based filtering
query.outFields = ['*']; // Fetch all fields (or specify required ones)
query.returnGeometry = true; // Set to true if geometry is needed
try {
const response = await featureLayer.queryFeatures(query);
const feature = response.features[0];
const latLong = getLattitudeAndLongitude(feature);
view.goTo(feature.geometry);
// Remove existing highlights (optional)
view.graphics.removeAll();
// Add highlight graphic
const highlightGraphic = new Graphic({
geometry: feature.geometry,
symbol: highlightSymbol,
attributes: feature.attributes
});
view.graphics.add(highlightGraphic);
return response.features.length > 0 ? { attributes: response.features[0].attributes, latLong } : null; // Return the fetched features
} catch (error) {
return null;
}
}