Select to view content in your preferred language

query highlight and zoom to graphics JS API 4.4?

5423
7
Jump to solution
07-27-2017 02:59 PM
by Anonymous User
Not applicable

Hi all,

Is there a way to highlight and zoom to graphics in 4.4 ? In 3.21 i used graphicsUtils.

var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([0, 0, 0, 0.65]), 2),new Color([24, 24, 199, 0.5]));
            var test = new Graphic(AOI, symbol);
            var extent = graphicsUtils.graphicsExtent(GraphicsParceliden.graphics);
            map.setExtent(extent, true);
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

Try making the following changes in your code and see if that helps. Basically I used then to execute the zoomparcel function once the query parcel task is done. And then in zoomparcel switch from result.feature to result.features. 

   queryparcelTask.execute(query).then(zoomparcel);



     function zoomparcel(result){
              var AOI = result.features;
              view.goTo(AOI);
        }

View solution in original post

7 Replies
KellyHutchins
Esri Frequent Contributor

You can use the goTo method on the MapView to navigate to a graphic or an array of graphics.

MapView | API Reference | ArcGIS API for JavaScript 4.4 

To test this functionality you can add a view.goTo(results.features) at line 258 of this sample.  

ArcGIS API for JavaScript Sandbox 

0 Kudos
by Anonymous User
Not applicable

Thanks Kelly! I see it in action in the sandbox you sent me but cannot replicate it with my code:

        $("#execute").click(function (){
            var value = $( "#searchtext" ).val();
            console.log(value);

            var queryparcelTask  = new QueryTask({url: "http://gem.edcgov.us/arcgis/rest/services/Sheriff/Parcels/MapServer/0"});
            var query = new Query();
            query.returnGeometry = true;
            query.where = "PRCL_ID = '" +   value + "'";
            queryparcelTask.execute(query, zoomparcel);
            
            
        });
....
        function zoomparcel(result){
              var AOI = result.feature;
              view.goTo(AOI);
        }

here is my jsbin

I used to capture result geometries in 3.21 "feature.geometry". Not too sure if  its needed or not in 4.4?

Thanks for all your help.

0 Kudos
KellyHutchins
Esri Frequent Contributor

Try making the following changes in your code and see if that helps. Basically I used then to execute the zoomparcel function once the query parcel task is done. And then in zoomparcel switch from result.feature to result.features. 

   queryparcelTask.execute(query).then(zoomparcel);



     function zoomparcel(result){
              var AOI = result.features;
              view.goTo(AOI);
        }
by Anonymous User
Not applicable

That was it! Thank you. I need to get more familiar with the "then"

0 Kudos
by Anonymous User
Not applicable

Last question, is there a way to zoom a little less, not that close to the feature?

0 Kudos
KellyHutchins
Esri Frequent Contributor

You should be able to modify the zoom level using the scale or zoom options available on goTo.  The doc for goTo has a few examples showing how this works. 

MapView | API Reference | ArcGIS API for JavaScript 4.4 

BlakeTerhune
MVP Regular Contributor

What are you using to highlight the feature/graphic? I don't see that in your code.