Select to view content in your preferred language

Secured webmap layers are not loaded when FeatureLayer is added

387
3
Jump to solution
02-25-2025 07:57 AM
EgorFedorov
Occasional Contributor

I have created a map by loading webmap containing secured traffic layer (item id: 'e5039444ef3c48b8a8fdc9227f9be7c1', same as in samples). Then, I've added simple feature layer created via url to 'map.oprationalLayers' list. This feature layer comes from samples also.

I have OAuth set up (I can verify that it works correctly). Also, I don't set 'ArcGISEnvironment.apiKey' variable.

I expect that auth challenge is raised, webmap is fully loaded, and feature layer is loaded also . Nevertheless, auth challenge is not triggered, I see only basemap (without traffic layer) and correctly loaded feature layer:

simulator_screenshot_3C2E0D98-9579-496E-9360-F74055F816D1.png

This can be reproduced using Authenticate with OAuth sample. Just remove apiKey in 'main.dart' and change 'onMapViewReady()' function to the following:

void onMapViewReady() {
// Create a map from a web map that has a secure layer (traffic).
final portalItem = PortalItem.withPortalAndItemId(
portal: Portal.arcGISOnline(connection: PortalConnection.authenticated),
itemId: 'e5039444ef3c48b8a8fdc9227f9be7c1',
);
final map = ArcGISMap.withItem(portalItem);

// Create a uri to a feature service.
final uri = Uri.parse(
'https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0',
);
// Create a service feature table with the uri.
final serviceFeatureTables = ServiceFeatureTable.withUri(uri);
// Create a feature layer with the service feature table.
final serviceFeatureLayer = FeatureLayer.withFeatureTable(serviceFeatureTables);
// Add the feature layer to the map.
map.operationalLayers.add(serviceFeatureLayer);

// Set the map to map view controller.
_mapViewController.arcGISMap = map;
}

 

Could you please clarify how can I combine using webmap, feature layers and OAuth?

 

I am checking via iPhone 15 simulator w/ iOS 17.5. Haven't tried on Android ones.

ArcGIS Flutter SDK version is 200.6.

 

0 Kudos
1 Solution

Accepted Solutions
PaulSturm
Esri Contributor

I was able to figure out how to make this work. Basically, wait for the map to load before adding the operational layer. You can do this many different ways. One way is to call "await map.load()" before adding the operational layer. Another way is to use ".then()" like this:

map.load().then((_) => map.operationalLayers.add(serviceFeatureLayer));

We either approach, the important thing is that the OAuth login is completed before adding the feature layers.

View solution in original post

0 Kudos
3 Replies
PaulSturm
Esri Contributor

I was able to figure out how to make this work. Basically, wait for the map to load before adding the operational layer. You can do this many different ways. One way is to call "await map.load()" before adding the operational layer. Another way is to use ".then()" like this:

map.load().then((_) => map.operationalLayers.add(serviceFeatureLayer));

We either approach, the important thing is that the OAuth login is completed before adding the feature layers.

0 Kudos
EgorFedorov
Occasional Contributor

Thanks, awaiting map loading fixed an issue.

 

We either approach, the important thing is that the OAuth login is completed before adding the feature layers.


Not sure I understand this correctly. I assume, that any auth server error (namely, 498 or 499 error codes) will trigger credentials request in SDK. Am I correct?

I did the following for checking.

1. Created simple webmap available without authentication ('8b3b470883a744aeb60e5fff0a319ce7', it is loaded correctly, no OAuth window shown)

2. Await while it is loaded

3. Add secured feature layer (not the same as in samples)

4. OAuth window is shows, layer is loaded correctly after entering credentials

 

It works as I expect, but I'm not sure what your comment mean in this case.

 

0 Kudos
PaulSturm
Esri Contributor

I wrote up an issue internally to investigate this further. I don't think it should matter if you mix secured content with unsecured content, but that does seem to be a problem. It looks like it doesn't matter if you do the secured content before the unsecured content or the other way around, but it seems to matter if you try to mix them in the same "load". So I think the safest thing to do is to load the secured content together in one "load", and do the unsecured content either before or after.