Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jolevesq committed May 16, 2024
1 parent e622686 commit fa06832
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,26 @@ export class MapEventProcessor extends AbstractEventProcessor {

// #endregion FEATURE SELECTION

// const unsubOrderedLayerInfo = store.subscribe(
// (state) => state.mapState.orderedLayerInfo,
// (cur) => {
// // Log
// logger.logTraceCoreStoreSubscription('MAP EVENT PROCESSOR - orderedLaterInfo', mapId, cur);

// const curVisibleLayers = cur
// .map((layerInfo) => {
// if (layerInfo.visible) return layerInfo.layerPath;
// return undefined;
// })
// .filter((layerPath) => layerPath);
// const prevVisibleLayers = [...store.getState().mapState.visibleLayers];
// if (JSON.stringify(prevVisibleLayers) !== JSON.stringify(curVisibleLayers))
// store.getState().mapState.setterActions.setVisibleLayers(curVisibleLayers as string[]);
// }
// );
const unsubOrderedLayerInfo = store.subscribe(
(state) => state.mapState.orderedLayerInfo,
(cur) => {
// Log
logger.logTraceCoreStoreSubscription('MAP EVENT PROCESSOR - orderedLaterInfo', mapId, cur);

const curVisibleLayers = cur
.map((layerInfo) => {
if (layerInfo.visible) return layerInfo.layerPath;
return undefined;
})
.filter((layerPath) => layerPath);
const prevVisibleLayers = [...store.getState().mapState.visibleLayers];
if (JSON.stringify(prevVisibleLayers) !== JSON.stringify(curVisibleLayers))
store.getState().mapState.setterActions.setVisibleLayers(curVisibleLayers as string[]);
}
);

// Return the array of subscriptions so they can be destroyed later
return [unsubMapHighlightedFeatures]; // , unsubOrderedLayerInfo];
return [unsubMapHighlightedFeatures, unsubOrderedLayerInfo];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,25 +625,15 @@ export function initializeMapState(set: TypeSetStore, get: TypeGetStore): IMapSt
* @param {TypeOrderedLayerInfo[]} orderedLayerInfo - The ordered layer information.
*/
setOrderedLayerInfo: (orderedLayerInfo: TypeOrderedLayerInfo[]): void => {
// We need to explicitly define ... for the array. If not subscribe does not fired
// TODO: refactor - setterActions in setState will recreate array if needed. We need to implement the pattern in all setterActions
// TD.CONT: We should have a deep equality function to compare previous / current
set({
mapState: {
...get().mapState,
orderedLayerInfo,
orderedLayerInfo: [...orderedLayerInfo],
},
});

// GV subscrite from map-eent-processor is unstable for layer coming from PyGeoApiProcess, even if layer is added
// GV to the orderedLayerInfo array, the subscribe does not fired the callback. By copying here, we enforce it...
// update array of visible layer from modification to the orderedLayerInfo who holds layers states and order
const curVisibleLayers = orderedLayerInfo
.map((layerInfo) => {
if (layerInfo.visible) return layerInfo.layerPath;
return undefined;
})
.filter((layerPath) => layerPath);
const prevVisibleLayers = [get().mapState.visibleLayers];
if (JSON.stringify(prevVisibleLayers) !== JSON.stringify(curVisibleLayers))
get().mapState.setterActions.setVisibleLayers(curVisibleLayers as string[]);
},

/**
Expand All @@ -658,7 +648,7 @@ export function initializeMapState(set: TypeSetStore, get: TypeGetStore): IMapSt
layerInfo.hoverable = hoverable;

// Redirect
get().mapState.setterActions.setOrderedLayerInfo([...curLayerInfo]);
get().mapState.setterActions.setOrderedLayerInfo(curLayerInfo);
}
},

Expand All @@ -675,7 +665,7 @@ export function initializeMapState(set: TypeSetStore, get: TypeGetStore): IMapSt
if (queryable) layerInfo.hoverable = queryable;

// Redirect
get().mapState.setterActions.setOrderedLayerInfo([...curLayerInfo]);
get().mapState.setterActions.setOrderedLayerInfo(curLayerInfo);
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { CsvLayerEntryConfig } from '@/core/utils/config/validation-classes/vect
import { VectorLayerEntryConfig } from '@/core/utils/config/validation-classes/vector-layer-entry-config';
import { AbstractBaseLayerEntryConfig } from '@/core/utils/config/validation-classes/abstract-base-layer-entry-config';
import { AppEventProcessor } from '@/api/event-processors/event-processor-children/app-event-processor';
import { TypeJsonObject } from '@/api/config/types/config-types';
import { Cast, TypeJsonObject } from '@/api/config/types/config-types';

// GV: CONFIG EXTRACTION
// GV: This section of code was extracted and copied to the geoview-config package
Expand Down Expand Up @@ -158,6 +158,8 @@ export class CSV extends AbstractGeoViewVector {
* @returns {Promise<TypeLayerEntryConfig>} A promise that the vector layer configuration has its metadata processed.
*/
protected override processLayerMetadata(layerConfig: VectorLayerEntryConfig): Promise<TypeLayerEntryConfig> {
// process the feature info configuration and attach the config to the instance for access by parent class
this.layerMetadata[layerConfig.layerPath] = Cast<TypeJsonObject>(layerConfig);
return Promise.resolve(layerConfig);
}

Expand Down Expand Up @@ -272,9 +274,7 @@ export class CSV extends AbstractGeoViewVector {
return null;
}

// process the feature info configuration and attach the config to the instance for access by parent class
CSV.#processFeatureInfoConfig(headers, csvRows[1], [latIndex, lonIndex], layerConfig);
this.layerMetadata[layerConfig.layerPath] = layerConfig as unknown as TypeJsonObject;

for (let i = 1; i < csvRows.length; i++) {
const currentRow = csvRows[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ConfigBaseClass } from '@/core/utils/config/validation-classes/config-b
import { TypeHoverLayerData } from './hover-feature-info-layer-set';
import { LayerApi } from '@/geo/layer/layer';
import { AppEventProcessor } from '@/api/event-processors/event-processor-children/app-event-processor';
import { Cast, TypeJsonObject } from '@/core/types/global-types';

/**
* A class to hold a set of layers associated with a value of any type.
Expand Down Expand Up @@ -88,6 +89,10 @@ export abstract class AbstractLayerSet {

// Synchronize the layer name property in the config and the layer set object when the geoview instance is ready.
if (!layerConfig.layerName) layerConfig.layerName = createLocalizedString(this.resultSet[layerPath].layerName!);

// There is a synch issue when layerName is not set on the layerConfig when layer is registered, it wil not appear in UI
if (this.resultSet[layerPath].data)
(Cast<TypeJsonObject>(this.resultSet[layerPath].data).layerName as string) = this.resultSet[layerPath].layerName!;
}

// Inform that the layer set has been updated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataTableEventProcessor } from '@/api/event-processors/event-processor-children/data-table-event-processor';
import { logger } from '@/core/utils/logger';
import { ConfigBaseClass } from '@/core/utils/config/validation-classes/config-base-class';
import { getLocalizedValue, whenThisThen } from '@/core/utils/utilities';
import { getLocalizedValue } from '@/core/utils/utilities';
import { TypeLayerEntryConfig, TypeLayerStatus } from '@/geo/map/map-schema-types';
import { AbstractGeoViewLayer, CONST_LAYER_TYPES } from '@/geo/layer/geoview-layers/abstract-geoview-layers';

Expand Down Expand Up @@ -41,7 +41,7 @@ export class AllFeatureInfoLayerSet extends AbstractLayerSet {
)
return false;

// TODO: there is a synching issue with CSV were source is undefined when layer is registered. To overcome this,
// TODO: there is a synching issue, sometimes source is undefined when layer is registered. To overcome this,
// TD.CONT: if not specified to false by default, we will set it to true
const queryable = layerConfig?.source?.featureInfo?.queryable;
return !!(queryable || queryable === undefined);
Expand All @@ -52,29 +52,13 @@ export class AllFeatureInfoLayerSet extends AbstractLayerSet {
* @param {AbstractGeoViewLayer} geoviewLayer - The geoview layer being registered
* @param {TypeLayerEntryConfig} layerConfig - The layer config
*/
protected override async onRegisterLayer(geoviewLayer: AbstractGeoViewLayer, layerConfig: TypeLayerEntryConfig): Promise<void> {
protected override onRegisterLayer(geoviewLayer: AbstractGeoViewLayer, layerConfig: TypeLayerEntryConfig): void {
// Log
logger.logTraceCore('ALL-FEATURE-INFO-LAYER-SET - onRegisterLayer', layerConfig.layerPath, Object.keys(this.resultSet));

// Call parent
super.onRegisterLayer(geoviewLayer, layerConfig);

// TODO: there is bug when layerName is not set on the layerConfig when layer is registered, it wil not appear in UI
// TD.CONT: The layerName on resultSet gets updated later but not the one in data.
// TD.CONT: With this await, we wait until name is define
// TODO: refactor - when we use new config, layerName will be set by default - no more await
try {
// Check if the layer name is define in configuration, wait for it
await whenThisThen(
() =>
getLocalizedValue(layerConfig.layerName, AppEventProcessor.getDisplayLanguage(this.mapId)) !== undefined &&
getLocalizedValue(layerConfig.layerName, AppEventProcessor.getDisplayLanguage(this.mapId)) !== ''
);
} catch (error) {
// Log
logger.logError(`Couldn't retrieve the layer name`, error);
}

this.resultSet[layerConfig.layerPath] = {
layerName: getLocalizedValue(layerConfig.layerName, AppEventProcessor.getDisplayLanguage(this.mapId)) ?? '',
layerStatus: layerConfig.layerStatus!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Coordinate } from 'ol/coordinate';
import { FeatureInfoEventProcessor } from '@/api/event-processors/event-processor-children/feature-info-event-processor';
import EventHelper, { EventDelegateBase } from '@/api/events/event-helper';
import { logger } from '@/core/utils/logger';
import { getLocalizedValue, whenThisThen } from '@/core/utils/utilities';
import { getLocalizedValue } from '@/core/utils/utilities';
import { ConfigBaseClass } from '@/core/utils/config/validation-classes/config-base-class';
import { TypeLayerEntryConfig, TypeLayerStatus } from '@/geo/map/map-schema-types';
import { AbstractGeoViewLayer, CONST_LAYER_TYPES } from '@/geo/layer/geoview-layers/abstract-geoview-layers';
Expand Down Expand Up @@ -71,7 +71,7 @@ export class FeatureInfoLayerSet extends AbstractLayerSet {
)
return false;

// TODO: there is a synching issue with CSV were source is undefined when layer is registered. To overcome this,
// TODO: there is a synching issue, sometimes source is undefined when layer is registered. To overcome this,
// TD.CONT: if not specified to false by default, we will set it to true
const queryable = layerConfig?.source?.featureInfo?.queryable;
return !!(queryable || queryable === undefined);
Expand All @@ -82,29 +82,13 @@ export class FeatureInfoLayerSet extends AbstractLayerSet {
* @param {AbstractGeoViewLayer} geoviewLayer - The geoview layer being registered
* @param {string} layerPath - The layer path
*/
protected override async onRegisterLayer(geoviewLayer: AbstractGeoViewLayer, layerConfig: TypeLayerEntryConfig): Promise<void> {
protected override onRegisterLayer(geoviewLayer: AbstractGeoViewLayer, layerConfig: TypeLayerEntryConfig): void {
// Log
logger.logTraceCore('FEATURE-INFO-LAYER-SET - onRegisterLayer', layerConfig.layerPath, Object.keys(this.resultSet));

// Call parent
super.onRegisterLayer(geoviewLayer, layerConfig);

// TODO: there is bug when layerName is not set on the layerConfig when layer is registered, it wil not appear in UI
// TD.CONT: The layerName on resultSet gets updated later but not the one in data.
// TD.CONT: With this await, we wait until name is define
// TODO: refactor - when we use new config, layerName will be set by default - no more await
try {
// Check if the layer name is define in configuration, wait for it
await whenThisThen(
() =>
getLocalizedValue(layerConfig.layerName, AppEventProcessor.getDisplayLanguage(this.mapId)) !== undefined &&
getLocalizedValue(layerConfig.layerName, AppEventProcessor.getDisplayLanguage(this.mapId)) !== ''
);
} catch (error) {
// Log
logger.logError(`Couldn't retrieve the layer name`, error);
}

this.resultSet[layerConfig.layerPath] = {
layerName: getLocalizedValue(layerConfig.layerName, AppEventProcessor.getDisplayLanguage(this.mapId)) ?? '',
layerStatus: layerConfig.layerStatus!,
Expand Down

0 comments on commit fa06832

Please sign in to comment.