Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): EsriDynamic does not have right icon after no fetch of ge… #2590

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1271,30 +1271,6 @@ export abstract class AbstractGeoViewLayer {
try {
if (!features.length) return [];

// Will hold the generic icon to use in formatting
let genericLegendInfo: string | null | undefined;
// We only want 1 task to fetch the generic legend (when we have to)
const semaphore = new AsyncSemaphore(1);

// Will be executed when we have to use a default canvas for a particular feature
const callbackToFetchDataUrl = (): Promise<string | null> => {
// TODO: Fix - Don't take 'iconImage' below, it's always the same image...
// TO.DOCONT: Use this.style.fields and this.style.[Geom].fields and this.style.[Geom].uniqueValueStyleInfo with a combination of the 'featureNeedingItsCanvas' to determine the style image
// TO.DOCONT: Also, get rid of 'genericLegendInfo' and 'semaphore' variables once code is rewritten to use the 'featureNeedingItsCanvas'

// Make sure one task at a time in this
return semaphore.withLock(async () => {
// Only execute this once in the callback. After this, once the semaphore is unlocked, it's either a string or null for as long as we're formatting
if (genericLegendInfo === undefined) {
genericLegendInfo = null; // Turn it to null, we are actively trying to find something (not undefined anymore)
const legend = await this.queryLegend(layerConfig.layerPath);
const legendIcons = LegendEventProcessor.getLayerIconImage(legend);
if (legendIcons) genericLegendInfo = legendIcons![0].iconImage || null;
}
return genericLegendInfo;
});
};

const featureInfo = layerConfig?.source?.featureInfo;

// Loop on the features to build the array holding the promises for their canvas
Expand All @@ -1307,8 +1283,8 @@ export abstract class AbstractGeoViewLayer {
this.getStyle(layerConfig.layerPath)!,
layerConfig.filterEquation,
layerConfig.legendFilterIsOff,
true,
callbackToFetchDataUrl
true
// callbackToFetchDataUrl
)
.then((canvas) => {
resolveCanvas({ feature: featureNeedingItsCanvas, canvas });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,17 @@ export class EsriDynamic extends AbstractGeoViewRaster {
const layerConfig = this.getLayerConfig(layerPath)! as EsriDynamicLayerEntryConfig;

// Guess the geometry type by taking the first style key
// TODO: Refactor - Layers migration. Johann: This will be modified with new schema, there is no more geometry on style
const [geometryType] = layerConfig.getTypeGeometries();

// Fetch the features
let urlRoot = layerConfig.geoviewLayerConfig.metadataAccessPath!;
if (!urlRoot.endsWith('/')) urlRoot += '/';
// TODO: we put false so on heavy geometry, dynamic layer can load datatable. If not the fetch fails.
// GV: we put false so on heavy geometry, dynamic layer can load datatable. If not the fetch fails.
// TODO: Because we do not query the geometry anymore, the section below to create geometry is useless
// TODO.CONT: This also have an effect on the style as it use the geometry to define wich one to use
// TODO.CONT: The formatFeatureInfoResult (abstact-geoview-layer) / getFeatureCanvas (geoview-renderer)
// TODO.CONT: needs to be modified to use default style pass to the function....
// TODO.CONT: We need a refactor to this in background, maybe with workers
const url = `${urlRoot}${layerConfig.layerId}/query?where=1=1&outFields=*&f=json&returnGeometry=false`;

const response = await fetch(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,26 +516,6 @@ export abstract class AbstractGVLayer extends AbstractBaseLayer {
try {
if (!features.length) return [];

// Will hold the generic icon to use in formatting
let genericLegendInfo: string | null | undefined;
// We only want 1 task to fetch the generic legend (when we have to)
const semaphore = new AsyncSemaphore(1);

// Will be executed when we have to use a default canvas for a particular feature
const callbackToFetchDataUrl = (): Promise<string | null> => {
// Make sure one task at a time in this
return semaphore.withLock(async () => {
// Only execute this once in the callback. After this, once the semaphore is unlocked, it's either a string or null for as long as we're formatting
if (genericLegendInfo === undefined) {
genericLegendInfo = null; // Turn it to null, we are actively trying to find something (not undefined anymore)
const legend = await this.queryLegend();
const legendIcons = LegendEventProcessor.getLayerIconImage(legend);
if (legendIcons) genericLegendInfo = legendIcons![0].iconImage || null;
}
return genericLegendInfo;
});
};

const outfields = layerConfig?.source?.featureInfo?.outfields;

// Loop on the features to build the array holding the promises for their canvas
Expand All @@ -548,8 +528,7 @@ export abstract class AbstractGVLayer extends AbstractBaseLayer {
this.getStyle(layerConfig.layerPath)!,
layerConfig.filterEquation,
layerConfig.legendFilterIsOff,
true,
callbackToFetchDataUrl
true
)
.then((canvas) => {
resolveCanvas({ feature: featureNeedingItsCanvas, canvas });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ export class GVEsriDynamic extends AbstractGVRaster {
const layerConfig = this.getLayerConfig();

// Guess the geometry type by taking the first style key
// TODO: Refactor - Layers migration. Johann: This will be modified with new schema, there is no more geometry on style
const [geometryType] = layerConfig.getTypeGeometries();

// Fetch the features
let urlRoot = layerConfig.geoviewLayerConfig.metadataAccessPath!;
if (!urlRoot.endsWith('/')) urlRoot += '/';
// TODO: we put false so on heavy geometry, dynamic layer can load datatable. If not the featch fails.
// GV: we put false so on heavy geometry, dynamic layer can load datatable. If not the fetch fails.
// TODO: Because we do not query the geometry anymore, the section below to create geometry is useless
// TODO.CONT: This also have an effect on the style as it use the geometry to define wich one to use
// TODO.CONT: The formatFeatureInfoResult (abstact-geoview-layer) / getFeatureCanvas (geoview-renderer)
// TODO.CONT: needs to be modified to use default style pass to the function....
// TODO.CONT: We need a refactor to this in background, maybe with workers
const url = `${urlRoot}${layerConfig.layerId}/query?where=1=1&outFields=*&f=json&returnGeometry=false`;

const response = await fetch(url);
Expand Down
2 changes: 1 addition & 1 deletion packages/geoview-core/src/geo/layer/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class LayerApi {
// ************************************************************
// INDICATES IF USING HYBRID MODE WITH THE NEW GVLAYERS CLASSES
// ************************************************************
static LAYERS_HYBRID_MODE = false;
static LAYERS_HYBRID_MODE = true;

/**
* Initializes layer types and listen to add/remove layer events from outside
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1598,9 +1598,11 @@ export async function getFeatureCanvas(
// The canvas that will be returned (if calculated successfully)
let canvas: HTMLCanvasElement | undefined;

// If the feature has a geometry
if (feature.getGeometry()) {
const geometryType = getGeometryType(feature);
// GV: Some time, the feature will have no geometry e.g. esriDynamic has we fetch geometry only when needed
// GV: We need to extract geometry from style instead. For esriDynamic there is only one geometry at a time
// If the feature has a geometry or Style has a geometry
if (feature.getGeometry() || Object.keys(style)[0]) {
const geometryType = feature.getGeometry() ? getGeometryType(feature) : (Object.keys(style)[0] as TypeStyleGeometry);

// Get the style accordingly to its type and geometry.
if (style[geometryType]) {
Expand Down
Loading