Constrain Behavior feature in WAB

2702
6
Jump to solution
06-07-2016 02:51 PM
Ravichandran_M_Kaushika
Occasional Contributor

In Silverlight, there was a feature:

<esriBehaviors: ConstrainExtentBehavior ConstrainedExtent= "minx, miny, maxx, maxy" />

is there an equivalent in the JS or WAB version of the same feature.

any help would be greatly appreciated.

regards

ravi Kaushika.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ravi,

  You will find that there was not a great deal of consistency across the web API back in the day. No there is no such method or component in the JS API. I do not have any code examples but the best you could do is watch the maps extent change event and if it would extend beyond the desired extent then you would reset the extent to one that is desired.

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Ravi,

  You will find that there was not a great deal of consistency across the web API back in the day. No there is no such method or component in the JS API. I do not have any code examples but the best you could do is watch the maps extent change event and if it would extend beyond the desired extent then you would reset the extent to one that is desired.

Ravichandran_M_Kaushika
Occasional Contributor

Robert,

thanks a bunch for your prompt reply.  you are very helpful.

regards

ravi.

0 Kudos
Ravichandran_M_Kaushika
Occasional Contributor

Robert,

good afternoon.  when I got time I went back to the code and put check points to see whether the person assigned was a state user (only for state users the extent needs to be locked like Silverlight app), I used to code to zoom to a state.

In this case, there is a user who can access only MS - your neighboring state.  I was able to check and zoom to MS.

Locking the extent or preventing the zoom out  became a problem:

onExtentChange: function()
{
if  (ZR_STATE_EXENT_OBJ) 
{
var deltaXmin = this.map.extent.xmin - ZR_STATE_EXTENT+OBJ.xmin ; //should b positive - otherwise restrict or don't zoom out
var deltaYmin = ... ; //should be positive;

var deltaXmax = .... ; // should be negative or otherwise prevent extent change 
var deltaYmax = ...;

if(deltaXmin < 0 || deltaYmin <0 || deltaXmax > 0 || deltaYmax >0)
{
this.map.setExtent(ZR_STATE_EXTENT_OBJ);
}

}



}

The if condition gets triggered even if I zoom in by clicking the plus sign to zoom in... which should not be the case.case.

regards

0 Kudos
Ravichandran_M_Kaushika
Occasional Contributor

Robert,

sorry forgot to tell you: I checked the permissions and set the extent in MapManager.js file at the highest level of /widgets folder and /widgets/homebutton/widgets.js onExtentChange and setting the initialExtent using the state level extent obj set in the MapManager.js file.

thanks for your support n regards

ravi.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ravi,

  In you extent change function check for the extents center (point) an if it has not changed from the last extent center (that you will need to store) then it is a zoom in or out and not a pan or a zoom and re-center and if this is the case then you can bail out of your function.

Ravichandran_M_Kaushika
Occasional Contributor

Thanks for the info; sorry for the delay in replying. I was out of office.

regards

ravi.

0 Kudos