layer.load === false when it should be true?

3868
10
Jump to solution
06-26-2015 11:48 AM
LauraMiles1
Occasional Contributor III

Hi, I have one secured layer in my map. Every time I run the map from NetBeans, there is a 401 (Unauthorized) error logging in the console for this secured service. Despite this, the layer is visible and useable on the map (identify, query work fine, geometry shows up fine).

I'm not sure what's causing the 401 error - I have myself set up to have access to this service, so that shouldn't be an issue.

For those users who should not have access, I need to gray out the item in the layer menu where they would turn the layer on and off, and deactivate its checkbox. This works fine, and I have it set to do this if layer.loaded === false. Problem is, it always === false, even though it loads and is viewable. Anybody have an idea why this might be?

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Regular Contributor

I think the map.load event where you are checking for the layerCadastal.loaded === false is being called before the layer has been loaded check for the value in the event "layers-add-result" and see if it is still not loaded.

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

Laura,

  Can you share some code and the error you are receiving?

0 Kudos
LauraMiles1
Occasional Contributor III

Hi Robert, I posted to jsfiddle but it's not functional - I got errors adding my external resources because some of them are http and not https? You wouldn't be able to see my map layers anyways as they are on our intranet.

The test for layer.loaded is in the function mapLoad, near the bottom of the js code. Switching out for our non-secured layer (layerCadastral) this works as intended - so if I put an error in the path for layerCadastral, loaded = false and if I leave the correct url, loaded = true.

I just can't figure out why I would be getting a security error, while the layer seems to load fine and is totally accessible.

Specifically, this is what comes up in the NetBeans console:

Failed to load resource: the server responded with a status of 401 (Unauthorized) (13:05:43:872 | error, network)

  at http://[private server]/arcgis/rest/info?f=json

XMLHttpRequest cannot load http://[private server]/arcgis/rest/info?f=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8383' is therefore not allowed access. The response had HTTP status code 401. (13:05:43:873 | error, javascript)

  at public_html/MOR.html

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Laura,

   Actually getting an error on this url specifically the info portion is totally normal.

"http://[private server]/arcgis/rest/info?f=json" this is how the API tests if the server supports CORS or not.

LauraMiles1
Occasional Contributor III

I'm not really very familiar with CORS...you are saying this is a more generic error that doesn't relate to my secured layer? Sounds like something I can disregard then?

Do you see any reason layerEnviroSIDRelate.loaded is always false, even though the layer appears on the map? I may ask ESRI tech support about that.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Laura,

   Yes you can ignore the CORS check error. I will look at your fiddle and see if anything stands out.

LauraMiles1
Occasional Contributor III

Much appreciated, thank you

0 Kudos
LauraMiles1
Occasional Contributor III

I should also add, I was told I would have to use a proxy to avoid users having a sign-in dialog pop up for the secured layer. However we found that users are not getting the sign-in dialog - they are able to view this secured layer based on their permissions configured in Server Manager. From what I understand, this should not be possible, but it is working.

0 Kudos
thejuskambi
Regular Contributor

I think the map.load event where you are checking for the layerCadastal.loaded === false is being called before the layer has been loaded check for the value in the event "layers-add-result" and see if it is still not loaded.

LauraMiles1
Occasional Contributor III

Thejus, thank you that seems to be correct. Changed it to run on the "layers-add-result" event and it works perfectly!

0 Kudos