wmbeers / cmv-app

CMV - The Configurable Map Viewer - A community supported open source mapping framework built with the Esri JavaScript API and the Dojo Toolkit
https://demo.cmv.io/
MIT License
1 stars 2 forks source link

Attributes Table widget needs to work with single-layer map services #77

Open wmbeers opened 3 years ago

wmbeers commented 3 years ago

Description:

When a map service that contains just a single layer is loaded, CMV does some tinkering of the layer properties so that it looks like a feature layer (no root checkbox in layer control). https://repo.fla-etat.org/bugzilla/show_bug.cgi?id=6096

Reported by Lex, see email 3/30/21

Steps to reproduce:

  1. Load the NWI map service (not as a feature layer, but the whole service, use Browse > Natural > Wetlands and Surface Waters > National Wetlands Inventory Areas V2 > Add All to Map )
  2. Select the Open Attribute Table menu option

Expected results:

Attribute table opens as expected.

Actual results:

A tab labeled "undefined" appears, with no data.

The key appears to be a difference in the structure of the layerControlItem object passed into openAttributeTable. It lacks the following properties, which are needed in the table options:

We can get the information those properties should contain:

Right now the short-hand way of figuring out if the layer is a map service with subLayer we need to work with depends on the sublayer property being created. There is probably another way we can determine whether map service or feature layer, and branch out that code accordingly. e.g. layerControlItem.layer.layerDef.type == 'dynamic'.

Perhaps this:

//is this a dynamic map service layer or feature layer?
if (layerControlItem.subLayer) {
    url += '/' + layerControlItem.subLayer.id;
    title = layerControlItem.subLayer.name;
    topicId += '_' + layerControlItem.subLayer.id;
    //todo pick up subLayer definitionExpression. Not sure how this is done or if it can be done...
//new: single-layer service
} else if (layerControlItem.layer.layerDef && layerControlItem.layer.layerDef.type === 'dynamic') {
    url += '/0';
    title = layerControlItem.layer.arcgisProps.title; (note too that this would work for all types of layers, I think, and we could replace the initial declaration of the title var with this call and remove from here)
} else if (layerControlItem.layer.getDefinitionExpression && layerControlItem.layer.getDefinitionExpression()) {
     definitionExpression = layerControlItem.layer.getDefinitionExpression();
}

The "todo" in the above is something being adressed under #78.