I'm having the darnedest time creating a basemap based on a ArcGISTiledLayer that is coming from a Uri that requires credentials...
So here's what I'm doing:
CurrentBasemapUrl = "https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Street_Map/MapServer"
var server = CurrentBasemapUrl; // "https://maps.gvs.nga.mil/arcgis/rest/services/Basemap/NGA_World_Imagery_2D/MapServer";
Esri.ArcGISRuntime.Security.AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(myChallengeHandler);
myMap.Basemap = new Basemap(new ArcGISTiledLayer(new Uri(server)));
for myChallengeHandler, I have this:
static async Task<Credential> myChallengeHandler(CredentialRequestInfo cri)
{
switch(cri.AuthenticationType)
{
case AuthenticationType.Token:
var options = new Esri.ArcGISRuntime.Security.GenerateTokenOptions() { Referer = new Uri(CurrentBasemapUrl)};
var user = "myusernameishere";
var pass = "mypasswordishere";
var cred = await AuthenticationManager.Current.GenerateCredentialAsync(
new Uri("https://www.arcgis.com/sharing/rest/generatetoken"),user, pass, options);
return cred;
}
return null;
}
when I do this, all I get is a grid, no maps. But I'm not getting any errors. Any ideas?
Using the same URL, I was able to successfully download a tile package.
If I change the URL to "http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer" (which doesn't require any creditials, it works fine.
Any help?
Solved! Go to Solution.
A long shot but just in case could you also make sure that the MapView has the same spatial reference than the layer you are using after the map is loaded?
Does the layer have a load error? If not, also check the layer's LayerViewState that's being reported by the MapView
Morten,
I don't get any error at all.
if I call _mapView.GetLayerViewState with my layer, i get:
If I look at the layer, it says:
The layer contains information (such as the Attribution) that MUST have loaded from the internet, so I'm sure it's getting there.
That is very odd. Are you seeing web requests for tiles being made? (you can use Fiddler (www.fiddlertool.com) to monitor that)
Morten,
Interesting note, if I add the token credential to the AuthenticationManager rather than use the challenge method, the map data loads.
From using Fiddler, it appears that when using the challenge method that the subsequent requests are returned with a 499 error (which implies the token hasn't been passed).
But, this doesn't really solve my problem, as what I'm really trying to do is hit a server that requires X509 (Smart Card) to access, and it doesn't seem to help to generate the creditial before hand.
Really, what I need is better debugging into what is happening. I'm probably send the wrong cert or something, but I'm not seeing any error or exceptions.
Ok, things are odder...to me anyway...Hitting my server that's X509 protected, I now see that I am getting map tiles back in fiddler, but they are not displaying.
I'm not sure if Antti's comment below (about the spatial reference) is valid or not, but the tiled later is coming in with an SR of 4326 (WGS84), and my map is 3857 (WebMercator)
Well, I guess Antti said it was a long shot, but it appears, at least for the map side, that it was the problem. I changed my map so that it was new Map(SpatialReference.Wgs84) and now my map loads.
Now, to try to get the Scene to work.
A long shot but just in case could you also make sure that the MapView has the same spatial reference than the layer you are using after the map is loaded?
This seems to be the case...nice catch.
The basemap in this case was Wgs84 (4326) and I was originating my Map as WebMercator. I found that I need to create a new Map with this as a basemap and then it loads.
Thanks