Select to view content in your preferred language

Zoom Out from a Queried Feature

530
2
Jump to solution
01-10-2024 04:50 AM
JeffHanson2
Occasional Contributor

I have a simple problem I can't seem to solve.   I query a feature and zoom to it:

      feaFarms.queryFeatures(query).then(function(results){
        const features = results.features;
        //view.goTo(features[0].geometry, 1000);
        var geometry = features[0].geometry;
        view.goTo(features[0].geometry);
 
After I "goTo" the queried feature geometry I want to zoom out a percentage so I can show some of the area surrounding the feature of interest.   I've tried getting and setting the scale but that doesn't work real well.
 
0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

Hi @JeffHanson2, thanks for posting your question here. You can clone the geometry of the extent, and then expand by a value greater than 1 to zoom out a bit, like this:

feaFarms.queryFeatures(query).then(function(results){
        const features = results.features;
        var geometry = features[0].geometry.extent.clone().expand(1.5);
        view.goTo(geometry);

}

View solution in original post

0 Kudos
2 Replies
Noah-Sager
Esri Regular Contributor

Hi @JeffHanson2, thanks for posting your question here. You can clone the geometry of the extent, and then expand by a value greater than 1 to zoom out a bit, like this:

feaFarms.queryFeatures(query).then(function(results){
        const features = results.features;
        var geometry = features[0].geometry.extent.clone().expand(1.5);
        view.goTo(geometry);

}

0 Kudos
JeffHanson2
Occasional Contributor

I also got this code to work:

      var geometry = features[0].geometry;
        var buffer = geometryEngine.buffer(geometry, 10, 'feet');
        view.extent = buffer.extent.expand(2);