home widget extent - how to set?

626
8
01-03-2018 10:55 AM
yangwen
New Contributor III

So for my mapview, I'm doing runtime calculation of extent and setting it to view.extent property.

Our requirement calls for the home button to restore the default view which is equal to the derived extent.

Our map also needs to be responsive, so once a browser dimension changes, the home button needs to re-calculate the extent that is applicable to the current browser viewport dimension.

Looking at the 4.6 Doc, it appears we can define a Viewpoint that augments how the home behaves.  However it's not obvious how viewpoint relates to extent. 

I've custom logic that calculates the new extent upon a widthBreakpoint and heightBreakpoint change. However, I don't see how that new extent can be used to derive a new viewpoint, which the home button requires.  Thanks

Home | API Reference | ArcGIS API for JavaScript 4.6 

0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Yang,

   A ViewPoint is based off a point and a scale, not an extent. You can get the views scale and center and create a ViewPoint from that.

0 Kudos
yangwen
New Contributor III

Robert,

So that sounds like I would need to update the view extent upon a browser resize via view.extent.  Then I can have the updated scale and center values to instantiate the new viewpoint.

The issue with this approach is each browser resize will reposition the map per the new extent.  The desired behavior is to not to change the extent upon browser resize - Only update the viewpoint for the home button so that when the user clicks home, the view he sees is equivalent to the extent for the current browser size.  Does this make sense?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Yang,

   The method you are using currently to calculate the extent needs to be updated to calculate the center and scale then is the only advice I have.

0 Kudos
yangwen
New Contributor III

So I've been searching for some 101 articles that articulates the concepts of scale, zoom, extent, viewpoint, especially how they relate.  Haven't had any luck. Do you know of any such articles? Thanks.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

None that I know of.  By what means are you calculating the extent now?

0 Kudos
yangwen
New Contributor III

I'm looping through the features in all my layers to find the xmin, ymin  & xmax, ymax values in that collection. 

The notion of and extent replacing the centerpoint + zoom makes total sense to me.  I'm struggling to understand how the concept of viewpoint replaces replaces extent.

These seem like fundamental mapping concepts that I need a better understanding of.

0 Kudos
yangwen
New Contributor III

I see why you are asking about my extent algorithm.  Upon further reading, it looks like I can derive the extent via setting the combination of centerpoint and zoom value.  Does the latter provide a more seamless pattern to deriving the Viewpoint? I believe the viewpoint needs the scale value.  I still need to understand how does zoom map to scale.

With this approach, the new challenge I see if being able set a zoom level that provides sufficient buffer/padding around my map features.  With my current extent algorithm, I can expand the extent by a ratio amount like 20%.    By using the zoom value to control the size of the bounding box, I don't see a programmatic way to control the amount of padding around my features.

0 Kudos
StefanUseldinger
Occasional Contributor

The target extent of the Home widget can be set using

homeWidget.viewpoint = new Viewpoint({
   targetGeometry: extent
});

0 Kudos