Select to view content in your preferred language

Zoom to feature collection in Flutter

250
1
12-23-2024 08:38 AM
vijaybadugu
Frequent Contributor

I've been trying to zoom to features after definition expression is applied. is there a way to direct zoom to all features which satisfies the definition expression? I already checked all examples, Could you please suggest something to do that?

 

queryParameters.whereClause = featureLayer.definitionExpression;
    //var feaureTable = FeatureLayer.withFeatureTable(featureTable);
    final queryResult = await featureTable.queryExtent(queryParameters);

    // Query the extent of features that match the definition expression
    // final QueryResult result =
    //  await _featureLayer.queryExtent(queryParams: queryParams);

    // Get the map controller
    // final controller = await _mapControllerCompleter.future;

    // Zoom to the filtered extent
    await _mapViewController.setViewpointGeometry(queryResult.extent);

 

0 Kudos
1 Reply
HarishK
Esri Contributor

Instead of calling FeatureLayer.queryExtent, you can call FeatureTable.queryExtent:

// Create a uri to a feature service.
final uri = Uri.parse(
'https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0',
);

// Create a service feature table with the uri.
final serviceFeatureTable = ServiceFeatureTable.withUri(uri);

// Apply a definition expression to filter features
serviceFeatureTable.definitionExpression = "firstname like '%a%'";

// Create query parameters with the definition expression
final
queryParameters = QueryParameters();
queryParameters.whereClause = serviceFeatureTable.definitionExpression;

// Query the extent of features that match the definition expression
final
queryResult = await serviceFeatureTable.queryExtent(queryParameters);

// Create a feature layer with the service feature table
final serviceFeatureLayer =
FeatureLayer.withFeatureTable(serviceFeatureTable);

// Add the feature layer to the map's operational layers
map.operationalLayers.add(serviceFeatureLayer);

// Load the map to ensure all layers are ready
await
map.load();

// Set the map view to the extent of the queried features
_mapViewController.setViewpointGeometry(queryResult.extent);

 

0 Kudos