zoom to feature

09-14-2020 11:40 AM
New Contributor III

Javascript API v4.16
Building a page that opens up a map and zooms to the extent of the feature ID passed to it from the previous page.

So far:

1.  the feature ID is set in the "localStorage" of page 1

2.  in Page 2 I retrieve that value and attempt to zoom to that feature.

3.  I have a function that will do the zooming but I can't get it to work.

4.  Here is the function:


 function zoomToPassedFeature(strLocationCode){
   // Create a QUERY for a feature layer in the map
   const layQLayer = new FeatureLayer({
     url: strMapServiceURL + "/FeatureServer/3" // Yards layer
   const query = new Query();
   query.where = "LocationCode = '" + strLocationCode + "'";
     view.goTo(results.extent);  // go to the extent of the results satisfying the query

   a.  if I put that function within the REQUIRE code block I get:  ReferenceError: Query is not defined

   b.  if I put that function outside the REQUIRE code block I get:  "zoomToFeatureExtent()" no defined.

How am I supposed to be doing this?


Tags (1)
0 Kudos
2 Replies
MVP Esteemed Contributor

What does your require section look like? Are the function arguments in the same order as the modules?

0 Kudos
New Contributor III

I finally figured it out.  The KEY being the first line in the section at the bottom:


The "whenLayerView" listener on the "view".

So now when I pass that FeatureID value and this layer is loaded it begins the process of querying and zooming.

Require Statement:

  ) {
// and the end of the JS file looks like:
  // Zoom to the feature ID passed from the AnL Site
      var query = layYards.createQuery();
      query.where = "LocationCode = '" + strLocationCode + "'";
        view.goTo(results.extent);  // go to the extent of all the graphics in the layer view

}); // End of REQUIRE
0 Kudos