ramp4-pcar4 / ramp4-pcar4

RAMP 4 - The Reusable Accessible Mapping Platform, fourth major version
https://ramp4-pcar4.github.io/ramp4-pcar4/main/docs/
Other
17 stars 22 forks source link

Merge Grid to Details bug #1917

Closed james-rae closed 1 year ago

james-rae commented 1 year ago

To reproduce:

  1. Visit Sample 38 Merge Grid.
  2. In the legend, click one of the CESI layers contained in "Homogeneous Merge Grid with Map Filtering".
  3. In the grid, click the details button on a row.
  4. 💥

This grid has field mapping to align stuff. E.g. each layer has a unique field for the Symbol and Concentration, and the config contains a fieldMap to align those fields to a common field names (search for sources: ['NO2', 'Ozone', 'PM2_5'] in the code base to see the mapping).

What I believe is happening is the data bundle being sent on the Details Open event is not reverse mapping the values. It has attributes named Symbol and Concentration but the actual attribute names would be something like NO2_Symbol and NO2.

james-rae commented 1 year ago

While I'm framing this as a mapping problem, the solution might be really easy. In the grid method const openDetails, instead of stripping data from the rows, doing reverse mapping, and removing custom grid fields, we could simplify to something like

// similar to the sql lookup, the details panel must use the original OID field to render symbols
const layer: LayerInstance | undefined = iApi.geo.layer.getLayer(
    data['rvUid']
)!;
const oidPair = props.params.layerCols[layer.id].find(
    (pair: AttributeMapPair) => pair.origAttr === layer.oidField
);

if (oidPair.mappedAttr) {
    const oid = data[oidPair.mappedAttr];

    layer.getGraphic(oid, {getAttribs: true}).then(g => {
        iApi.event.emit(GlobalEvents.DETAILS_TOGGLE, {
            data: g.attributes,
            uid: props.params.data.rvUid,
            format: IdentifyResultFormat.ESRI
        });
    });
}

It's a bit inefficient in that we are doing a local lookup for attributes when they likely exist in the row we're already on. But the result is a pristine attribute, the grid manipulations are avoided. This only happens on a user click so no big deal. Since grid is open, all attributes are already cached so just an object key lookup.

Anyway something to consider if un-mapping the grid stuff is difficult. Also, does our 'linkification' also change the attribute value in the grid? If so, there might be another lurking bug if we don't change the code to use getGraphic. If details has a template, it will be getting data in one fromat from an identify and another from the grid.