Zoom to polygon on load

445
2
Jump to solution
02-12-2019 10:47 AM
MarkJones7
Occasional Contributor

Boss: "Can filter the feature layer and then have it zoom in to that filtered section?"

Me: "For sure, shouldn't be a problem"

And so, here I am. For the life of me, I cannot get what seems like it should be a simple task to work.

The filtering of the feature layer is accomplished using the defintionExpression. So with that the map loads and the only polygon visible is what matches the defintionExpression. However, what I have failed to figure out, is how I can get the map to zoom into and center on that visible polygon.

Here is a link to the codepen for some understanding of what I am trying to accomplish. You will notice in the pen that the visible polygon is not centered.

temp_div_map 

Any and all help is immensely appreciated.

Mark

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Mark,

   It is pretty easy. Just query the layer views extent.

        map.add(DivFeatureLayer);
        view.whenLayerView(DivFeatureLayer).then(function(layerView){
          layerView.watch("updating", function(val){
            if(!val){  // wait for the layer view to finish updating
              layerView.queryExtent().then(function(results){
                view.goTo(results.extent);  // go to the extent of all the graphics in the layer view
              });
            }
          });
        });‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Mark,

   It is pretty easy. Just query the layer views extent.

        map.add(DivFeatureLayer);
        view.whenLayerView(DivFeatureLayer).then(function(layerView){
          layerView.watch("updating", function(val){
            if(!val){  // wait for the layer view to finish updating
              layerView.queryExtent().then(function(results){
                view.goTo(results.extent);  // go to the extent of all the graphics in the layer view
              });
            }
          });
        });‍‍‍‍‍‍‍‍‍‍
MarkJones7
Occasional Contributor

Aw man, I feel like a complete tool. You responded so fast!

Thank you my friend. Keep being awesome!

Mark

0 Kudos