Hi
I have made a basic app portraying a single feature hosted Feature layer(points) on top of esri basemaps. The basemaps covers the whole world, but my app should only focus on Oslo city. To do this I've tried to restrict the panning possibilities to the city, throwing the user back if he pans to far out, this works fine now. Using a script with Web AppBuilder for developers. However I have a challenge that I havn't been able to solve.
1. When my app loads, it sets the specified extent from a script for the basemap, but it doesn't seem to affect my feature layer, resulting in the features beeing placed with a certain offset from their correct place. (I suspect the script is forcing the basemap to a certain extent, while the features are still using the default extent set by the map layer). The moment I zoom in or out, the problem corrects itself and will work fine until you reload the application.

Left pic, nr1 shows the initial extent, whil right pic,nr2, shows how it should be.
This is the script I've tried, placed in the file "LayoutManager.js"
_doPostLoad<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//load somethings that may be used later.</SPAN>
<SPAN class="comment token">//let it load behind the stage.</SPAN>
<SPAN class="token function">require</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'dynamic-modules/postload'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> osloExtent<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">!</SPAN>osloExtent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>
osloExtent <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">;</SPAN>
osloExtent<SPAN class="punctuation token">.</SPAN>xmin <SPAN class="operator token">=</SPAN> <SPAN class="number token">1164244.8971553196</SPAN><SPAN class="punctuation token">;</SPAN>
osloExtent<SPAN class="punctuation token">.</SPAN>xmax<SPAN class="operator token">=</SPAN> <SPAN class="number token">1218767.932529483</SPAN><SPAN class="punctuation token">;</SPAN>
osloExtent<SPAN class="punctuation token">.</SPAN>ymin<SPAN class="operator token">=</SPAN> <SPAN class="number token">8360539.398234147</SPAN><SPAN class="punctuation token">;</SPAN>
osloExtent<SPAN class="punctuation token">.</SPAN>ymax<SPAN class="operator token">=</SPAN> <SPAN class="number token">8390138.410556029</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'extent-change'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>event<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//If the map has moved to the point where it's center is outside the initial boundaries,</SPAN>
<SPAN class="comment token">//then move it back to the edge where it moved out</SPAN>
<SPAN class="keyword token">var</SPAN> currentCenter <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCenter</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>osloExtent <SPAN class="operator token">&&</SPAN> <SPAN class="operator token">!</SPAN>osloExtent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">contains</SPAN><SPAN class="punctuation token">(</SPAN>currentCenter<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">&&</SPAN> event<SPAN class="punctuation token">.</SPAN>delta <SPAN class="operator token">&&</SPAN> event<SPAN class="punctuation token">.</SPAN>delta<SPAN class="punctuation token">.</SPAN>x <SPAN class="operator token">!==</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="operator token">&&</SPAN> event<SPAN class="punctuation token">.</SPAN>delta<SPAN class="punctuation token">.</SPAN>y <SPAN class="operator token">!==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> newCenter <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCenter</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//check each side of the initial extent and if the current center is outside that extent, </SPAN>
<SPAN class="comment token">//set the new center to be on the edge that it went out on</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>currentCenter<SPAN class="punctuation token">.</SPAN>x <SPAN class="operator token"><</SPAN> osloExtent<SPAN class="punctuation token">.</SPAN>xmin<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
newCenter<SPAN class="punctuation token">.</SPAN>x <SPAN class="operator token">=</SPAN> osloExtent<SPAN class="punctuation token">.</SPAN>xmin<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>currentCenter<SPAN class="punctuation token">.</SPAN>x <SPAN class="operator token">></SPAN> osloExtent<SPAN class="punctuation token">.</SPAN>xmax<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
newCenter<SPAN class="punctuation token">.</SPAN>x <SPAN class="operator token">=</SPAN> osloExtent<SPAN class="punctuation token">.</SPAN>xmax<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>currentCenter<SPAN class="punctuation token">.</SPAN>y <SPAN class="operator token"><</SPAN> osloExtent<SPAN class="punctuation token">.</SPAN>ymin<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
newCenter<SPAN class="punctuation token">.</SPAN>y <SPAN class="operator token">=</SPAN> osloExtent<SPAN class="punctuation token">.</SPAN>ymin<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>currentCenter<SPAN class="punctuation token">.</SPAN>y <SPAN class="operator token">></SPAN> osloExtent<SPAN class="punctuation token">.</SPAN>ymax<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
newCenter<SPAN class="punctuation token">.</SPAN>y <SPAN class="operator token">=</SPAN> osloExtent<SPAN class="punctuation token">.</SPAN>ymax<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">centerAt</SPAN><SPAN class="punctuation token">(</SPAN>newCenter<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
_onOpenWidgetRequest<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>widgetId<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>layoutManager<SPAN class="punctuation token">.</SPAN><SPAN class="token function">openWidget</SPAN><SPAN class="punctuation token">(</SPAN>widgetId<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>If i remove the script, allowing end users to pan all over the world, the features will be at their correct place when reloading the application - so there's nothing wrong with the layer.
Ps: I'm new to scripting java, had a lot of help coming up with this one.
Have noticed that there are some similiar questions out there, but their quite old, and not linked to Web AppBuilder as far as I can tell.