map.setExtent(extent, fit?) in 4.x

892
3
Jump to solution
11-07-2018 01:28 PM
MakikoShukunobe1
Occasional Contributor

How to set "fit" in 4.x?

fit - "When true, for maps that contain tiled map service layers, you are guaranteed to have the input extent shown completely on the map. The default value is false. (As of v1.3)"

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Makiko,

   In the 4.x api the option is to use view.goTo(extent); There is no fit option, it will just choose the closest LOD. You can use view.extent.contains to check if the views new extent contains the whole extent you are going to after the fact and then set the views.zoom as one greater if it does not.

view.goTo(extent).then(function(evt){
  if(!view.extent.contains(yourExtent){
    view.zoom -= 1;
  }
}).‍‍‍‍‍‍‍‍‍‍

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Makiko,

   In the 4.x api the option is to use view.goTo(extent); There is no fit option, it will just choose the closest LOD. You can use view.extent.contains to check if the views new extent contains the whole extent you are going to after the fact and then set the views.zoom as one greater if it does not.

view.goTo(extent).then(function(evt){
  if(!view.extent.contains(yourExtent){
    view.zoom -= 1;
  }
}).‍‍‍‍‍‍‍‍‍‍
MakikoShukunobe1
Occasional Contributor

Hi Robert,

Perfect!!  Thank you!!  I got this but ")" need to be added before ".then".

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

OK I have updated the code block.

0 Kudos