MapView container property intermittently null, width and height 0

478
3
03-24-2021 12:17 PM
JoeSaltenberger
New Contributor II

I'm having an issue where the map is not rendering in my web app the first time I use it each day. Looking in the debug tools, I can see the MapView container property is null, and the width and height properties are 0. There are no errors in the console. Once I refresh the page, everything renders fine and the properties are set properly. I'm currently using 4.15.

I'm thinking this may be related to either the dom not being fully loaded when the view is created, or some type of caching issue. I know with 3.x there were domReady modules that needed to be included in certain situations. Is the necessary in 4.x?

Any ideas of what would be helpful. Thanks.

0 Kudos
3 Replies
AndyGup
Esri Regular Contributor

That sure sounds like an application lifecycle issue. Are you using a JavaScript framework?  If so, then you'll need to use the framework's hooks to wait until the application component has initialized before initializing the map. 

0 Kudos
JoeSaltenberger
New Contributor II

It's a .NET webforms page with some Telerik controls for AJAX requests. Other than that, just vanilla JavaScript.

Do you know if it would help to load the script that initializes the map at the end of the body, instead of in the header? Other than that I'll just try listening for dom loaded events and initialize the map from there. Thanks.

 

 

0 Kudos
AndyGup
Esri Regular Contributor

Do you know if it would help to load the script that initializes the map at the end of the body, instead of in the header?

My hunch is that using onLoad or one of the webform's lifecycle steps will be the trick to get the DOM timing right. 

0 Kudos