Select to view content in your preferred language

zoomToLayer - Javascript API for ArcGIS

2812
12
Jump to solution
03-02-2020 11:41 AM
AprilSummers
Emerging Contributor

I am new to JS and I don't quite know how to integrate the Zoom to Layer functionality in my code snippet. I have tried several ways and have failed. Any pointers would be very much appreciated.

I assume the zoomToLayer function must be added when the query geometry is returned by the queryForWellGeometries() function.

The complete code can be found here -> https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=featurelayer-q... and zoomToLayer() code can be found here -> https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=featurelayer-q...

When the option is selected from the dropdown menu, it would be useful to zoom to the extent of the queried feature. Right now, the code works but it does not zoom to the feature.

I have tried all sorts of permutations but because my knowledge is basic, I feel I am missing a link.

Tags (1)
0 Kudos
12 Replies
AprilSummers
Emerging Contributor

Hi Robert Scheitlin, GISP

I am not sure if I can share my layer and its information  

The code is exactly the same. I double checked it. I am just using my feature layer instead of the well. I have also separated my code into html, css and js separately and linked the sheets. All functionalities work except this zoomToExtent.

When I use your code in the sandbox, it works but when I run it from my own local machine it doesn't work. I tried different browsers. I am really confused here!

0 Kudos
AprilSummers
Emerging Contributor

Hi Robert Scheitlin, GISP‌,

Thank you so much! The basemap was indeed changed to a different projection and I was not aware of it. I added the spatial reference part of the code and it works! Phew!!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

April,

   Great that is exactly what I was going to reply to you about next. That is has to be a Spatialreference issue.

0 Kudos