Zoom to extent - Graphics Layer

1362
1
05-11-2020 12:59 AM
by Anonymous User
Not applicable

I am using JS 4x and have developed a functionality that draws a graphic point layer on the map when it satisfies a query for a feature layer. When the functionality runs, it would be ideal if the map can zoom to the extent of the graphic layer. 

However, using the code

graphicLayer.when(function(){
  view.extent = graphicLayer.fullExtent;
});‍‍‍‍‍‍‍‍‍

I still could not achieve the zooming to extent functionality. In some cases it zooms to the entire extent of the basemap and in some cases not. Even that was a bit bizarre. 

Would someone please point out how to achieve this functionality?

Some additional information:

I also read online that a mismatch in spatial reference could be a cause of the queryExtent() feature not working and I assumed it might be the same reason for the fullExtent. 

Originally,

Basemap - 3857 Web Mercator Projection (topo-vector from ESRI)

Queried feature Layer - 28992 RD-New

Graphic Layer - 4326 (for container) but 28992 for features returned

I also changed the basemap to RD-New but I am unable to set the graphic layer container projection using the following line of code. 

this.graphicLayer.outSpatialReference = this.view.spatialReference;
‍‍‍

I also checked online that it is not possible to set it. If this has been updated, it would be nice to know.  

However, I am performing another function to zoomToExtent of a feature layer using the queryExtent() function and despite the mismatch between the basemap projection and the feature layer projection, that works!

Any pointers to achieve this would be very helpful! 

Thank you.

Tags (1)
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Sravanthi,

   When you query a layer from ArcGIS Server or AGOL you can specify the outSpatialRefernce of the results. When trying to zoom to a graphic it needs to be in the same spatial reference as the view. I see in your post above you tried 

this.graphicLayer.outSpatialReference = this.view.spatialReference;

The graphicslayer class does Not have an outSpatialReference property. The Query class does though.

0 Kudos