Select to view content in your preferred language

Highlight geometry is not working in feature query

133
0
04-09-2025 12:04 AM
Labels (1)
ikmkerala
New Contributor

// 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;
  }
}
0 Kudos
0 Replies