Skip to content

Commit

Permalink
refactor(geo): Set hybrid mode as default to use gv-layers class
Browse files Browse the repository at this point in the history
  • Loading branch information
jolevesq committed Nov 27, 2024
1 parent 922790b commit 52cadd4
Show file tree
Hide file tree
Showing 24 changed files with 148 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ <h3>Events that will generate notifications:</h3>
});

// listen to individual layer loaded event
cgpv.api.maps.Map1.layer.getGeoviewLayerHybrid(LYR_PATH_NON_METAL)?.onIndividualLayerLoaded((sender, payload) => {
cgpv.api.maps.Map1.layer.getGeoviewLayer(LYR_PATH_NON_METAL)?.onIndividualLayerLoaded((sender, payload) => {
cgpv.api.maps.Map1.notifications.addNotificationSuccess('Nonmetal mines has finished loading');
console.log(sender.olRootLayer.getSource().getFeatures());
});
Expand All @@ -331,22 +331,22 @@ <h3>Events that will generate notifications:</h3>
// !!

// listen to layer visibility changed event (individual geoview layer)
cgpv.api.maps.Map1.layer.getGeoviewLayerHybrid(LYR_PATH_UNIQUE)?.onVisibleChanged((sender, payload) => {
cgpv.api.maps.Map1.layer.getGeoviewLayer(LYR_PATH_UNIQUE)?.onVisibleChanged((sender, payload) => {
cgpv.api.maps.Map1.notifications.addNotificationSuccess(`${LYR_PATH_UNIQUE} visibility set to ${payload.visible} - individual`);
});

// listen to layer visibility changed event (individual geoview layer)
cgpv.api.maps.Map1.layer.getGeoviewLayerHybrid(LYR_PATH_GEOCORE)?.onVisibleChanged((sender, payload) => {
cgpv.api.maps.Map1.layer.getGeoviewLayer(LYR_PATH_GEOCORE)?.onVisibleChanged((sender, payload) => {
cgpv.api.maps.Map1.notifications.addNotificationSuccess(`layer ${payload.layerPath} visibility set to ${payload.visible} - individual`);
});

// listen to layer opacity changed event
cgpv.api.maps.Map1.layer.getGeoviewLayerHybrid(LYR_PATH_UNIQUE)?.onLayerOpacityChanged((sender, payload) => {
cgpv.api.maps.Map1.layer.getGeoviewLayer(LYR_PATH_UNIQUE)?.onLayerOpacityChanged((sender, payload) => {
cgpv.api.maps.Map1.notifications.addNotificationSuccess(`${payload.layerPath} opacity changed to ${payload.opacity}`);
});

// listen to layer filter applied event
cgpv.api.maps.Map1.layer.getGeoviewLayerHybrid(LYR_PATH_UNIQUE)?.onLayerFilterApplied((sender, payload) => {
cgpv.api.maps.Map1.layer.getGeoviewLayer(LYR_PATH_UNIQUE)?.onLayerFilterApplied((sender, payload) => {
cgpv.api.maps.Map1.notifications.addNotificationSuccess(`Filter ${payload.filter} applied to ${payload.layerPath}`);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/geoview-core/public/templates/ui-components.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ <h3>Accessing slider value from outside of the core viewer using api event liste
track: 'normal',
onChange: (dates) => {
const field = cgpv.api.maps.UI1.layer
.getGeoviewLayerHybrid('historical-flood/0')
.getTemporalDimension('historical-flood/0').field;
.getGeoviewLayer('historical-flood/0')
.getTemporalDimension().field;
cgpv.api.maps.UI1.layer
.getGeoviewLayerHybrid('historical-flood/0')
.getGeoviewLayer('historical-flood/0')
.applyViewFilter('historical-flood/0', `${field} >= date '${dates[0]}-01-01' and ${field} <= date '${dates[1]}-12-31'`);
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class LegendEventProcessor extends AbstractEventProcessor {
* @returns {Promise<Extent | undefined>} The extent of the feature, if available
*/
static getExtentFromFeatures(mapId: string, layerPath: string, objectIds: string[]): Promise<Extent | undefined> | undefined {
return MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayerHybrid(layerPath)?.getExtentFromFeatures(layerPath, objectIds);
return MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayer(layerPath)?.getExtentFromFeatures(layerPath, objectIds);
}

static getLayerIconImage(layerLegend: TypeLegend | null): TypeLegendLayerItem[] | undefined {
Expand Down Expand Up @@ -239,7 +239,7 @@ export class LegendEventProcessor extends AbstractEventProcessor {
if (!layerConfig) return;

// Get the layer
const layer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayerHybrid(entryLayerPath);
const layer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayer(entryLayerPath);

// Interpret the layer name the best we can
const layerName =
Expand Down Expand Up @@ -536,7 +536,7 @@ export class LegendEventProcessor extends AbstractEventProcessor {
const layer = LegendEventProcessor.findLayerByPath(curLayers, layerPath);
if (layer) {
layer.opacity = opacity;
MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayerHybrid(layerPath)?.setOpacity(opacity, layerPath);
MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayer(layerPath)?.setOpacity(opacity);
if (isChild) {
layer.opacityFromParent = opacity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ export class MapEventProcessor extends AbstractEventProcessor {
* @param {string} layerPath The path of the layer to apply filters to.
*/
static applyLayerFilters(mapId: string, layerPath: string): void {
const geoviewLayer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayerHybrid(layerPath);
const geoviewLayer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayer(layerPath);
if (geoviewLayer) {
if (
geoviewLayer instanceof WMS ||
Expand Down Expand Up @@ -1265,7 +1265,7 @@ export class MapEventProcessor extends AbstractEventProcessor {
* @param {string} layerPath The path for the layer to get filters from.
*/
static getActiveVectorFilters(mapId: string, layerPath: string): (string | undefined)[] | undefined {
const geoviewLayer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayerHybrid(layerPath);
const geoviewLayer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayer(layerPath);
if (geoviewLayer) {
const initialFilter = this.getInitialFilter(mapId, layerPath);
const tableFilter = DataTableEventProcessor.getTableFilter(mapId, layerPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
TimeSliderLayerSet,
TypeTimeSliderValues,
} from '@/core/stores/store-interface-and-intial-values/time-slider-state';
import { AbstractGeoViewLayer } from '@/geo/layer/geoview-layers/abstract-geoview-layers';
import { WMS } from '@/geo/layer/geoview-layers/raster/wms';
import { TypeFeatureInfoLayerConfig, TypeLayerEntryConfig, layerEntryIsGroupLayer } from '@/geo/map/map-schema-types';
import { EsriImage } from '@/geo/layer/geoview-layers/raster/esri-image';
Expand Down Expand Up @@ -123,16 +122,16 @@ export class TimeSliderEventProcessor extends AbstractEventProcessor {
static getInitialTimeSliderValues(mapId: string, layerConfig: TypeLayerEntryConfig): TypeTimeSliderValues | undefined {
// Get the layer using the map event processor, If no temporal dimension OR layerPath, return undefined
if (!layerConfig.layerPath) return undefined;
const geoviewLayer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayerHybrid(layerConfig.layerPath)!;
const geoviewLayer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayer(layerConfig.layerPath)!;

// If a group
if (layerEntryIsGroupLayer(layerConfig)) return undefined;

// Cast the layer
const geoviewLayerCasted = geoviewLayer as AbstractGeoViewLayer | AbstractGVLayer;
const geoviewLayerCasted = geoviewLayer as AbstractGVLayer | AbstractGVLayer;

// Get the temporal dimension information
const temporalDimensionInfo = geoviewLayerCasted.getTemporalDimension(layerConfig.layerPath);
const temporalDimensionInfo = geoviewLayerCasted.getTemporalDimension();

// If no temporal dimension information
if (!temporalDimensionInfo || !temporalDimensionInfo.range) return undefined;
Expand Down Expand Up @@ -259,7 +258,7 @@ export class TimeSliderEventProcessor extends AbstractEventProcessor {
values: number[]
): void {
// Get the layer using the map event processor
const geoviewLayer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayerHybrid(layerPath)!;
const geoviewLayer = MapEventProcessor.getMapViewerLayerAPI(mapId).getGeoviewLayer(layerPath)!;

let filter: string;
if (geoviewLayer instanceof WMS || geoviewLayer instanceof GVWMS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
TypeLayerStatus,
TypeStyleGeometry,
CONST_LAYER_ENTRY_TYPES,
TypeLoadEndListenerType,
TypeFeatureInfoEntry,
codedValueType,
rangeDomainType,
Expand All @@ -43,7 +42,6 @@ import {
import { GeoViewLayerCreatedTwiceError } from '@/geo/layer/exceptions/layer-exceptions';
import { getLegendStyles, getFeatureCanvas } from '@/geo/utils/renderer/geoview-renderer';
import { ConfigBaseClass } from '@/core/utils/config/validation-classes/config-base-class';
import { LayerApi } from '../layer';
import { TypeLegend } from '@/core/stores/store-interface-and-intial-values/layer-state';
import { MapViewer } from '@/geo/map/map-viewer';

Expand Down Expand Up @@ -1461,49 +1459,6 @@ export abstract class AbstractGeoViewLayer {
return Promise.resolve();
}

/**
* The olLayerAndLoadEndListeners setter method for the ConfigBaseClass class and its descendant classes.
* @param {AbstractBaseLayerEntryConfig} layerConfig - The layer configuration we are creating a layer for.
* @param {BaseLayer} olLayer - The OpenLayer we are creating
* @param {TypeLoadEndListenerType} listenerType - The layer listener type.
*/
setLayerAndLoadEndListeners(layerConfig: AbstractBaseLayerEntryConfig, olLayer: BaseLayer, listenerType: TypeLoadEndListenerType): void {
// Precond:
if (!olLayer) throw new Error(`An OpenLayer must be provided to register listeners. Layer path ${layerConfig.layerPath}`);
if (!listenerType) throw new Error(`A listenerType must be provided to register listeners. Layer path ${layerConfig.layerPath}`);

// If in old LAYERS_HYBRID_MODE (in the new LAYERS_HYBRID_MODE we want the new classes to handle that)
if (!LayerApi.LAYERS_HYBRID_MODE) {
// Group layers have no listener
if (layerConfig.entryType !== CONST_LAYER_ENTRY_TYPES.GROUP) {
let loadErrorListener: () => void;

// Definition of the load end listener functions
const loadEndListener = (): void => {
// Call the overridable loaded function
this.onLoaded(layerConfig);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
(olLayer.get('source') as any).un(`${listenerType}loaderror`, loadErrorListener);
};

loadErrorListener = (): void => {
// Call the overridable error function
this.onError(layerConfig);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
(olLayer.get('source') as any).un(`${listenerType}loadend`, loadEndListener);
};

// Activation of the load end listeners
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(olLayer.get('source') as any).once(`${listenerType}loaderror`, loadErrorListener);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(olLayer.get('source') as any).once(`${listenerType}loadend`, loadEndListener);
}
}
}

/**
* Recursively gets all layer entry configs in the GeoView Layer.
* @returns {ConfigBaseClass[]} The list of layer entry configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// We have many reassign for layerPath-layerConfig. We keep it global...
import { ImageArcGISRest } from 'ol/source';
import { Options as SourceOptions } from 'ol/source/ImageArcGISRest';
import { Options as ImageOptions } from 'ol/layer/BaseImage';
import BaseLayer from 'ol/layer/Base';
import { Image as ImageLayer } from 'ol/layer';
import { Coordinate } from 'ol/coordinate';
Expand Down Expand Up @@ -287,32 +286,7 @@ export class EsriDynamic extends AbstractGeoViewRaster {
if (requestResult.length > 0) {
// Get the OpenLayer that was created
olLayer = requestResult[0] as ImageLayer<ImageArcGISRest>;
}

// If no olLayer was obtained
if (!olLayer) {
// We're working in old LAYERS_HYBRID_MODE (in the new mode the code below is handled in the new classes)
const imageLayerOptions: ImageOptions<ImageArcGISRest> = {
source,
properties: { layerConfig },
};
// layerConfig.initialSettings cannot be undefined because config-validation set it to {} if it is undefined.
if (layerConfig.initialSettings?.className !== undefined) imageLayerOptions.className = layerConfig.initialSettings.className;
if (layerConfig.initialSettings?.extent !== undefined) imageLayerOptions.extent = layerConfig.initialSettings.extent;
if (layerConfig.initialSettings?.maxZoom !== undefined) imageLayerOptions.maxZoom = layerConfig.initialSettings.maxZoom;
if (layerConfig.initialSettings?.minZoom !== undefined) imageLayerOptions.minZoom = layerConfig.initialSettings.minZoom;
if (layerConfig.initialSettings?.states?.opacity !== undefined)
imageLayerOptions.opacity = layerConfig.initialSettings.states.opacity;
// If a layer on the map has an initialSettings.visible set to false, its status will never reach the status 'loaded' because
// nothing is drawn on the map. We must wait until the 'loaded' status is reached to set the visibility to false. The call
// will be done in the layerConfig.loadedFunction() which is called right after the 'loaded' signal.

// Create the OpenLayer layer
olLayer = new ImageLayer(imageLayerOptions);

// Hook the loaded event
this.setLayerAndLoadEndListeners(layerConfig, olLayer, 'image');
}
} else throw new Error('Error on layerRequesting event');

// GV Time to emit about the layer creation!
this.emitLayerCreation({ config: layerConfig, layer: olLayer });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ImageArcGISRest } from 'ol/source';
import { Options as SourceOptions } from 'ol/source/ImageArcGISRest';
import BaseLayer from 'ol/layer/Base';
import { Options as ImageOptions } from 'ol/layer/BaseImage';
import { Image as ImageLayer } from 'ol/layer';
import { Extent } from 'ol/extent';

Expand Down Expand Up @@ -336,32 +335,7 @@ export class EsriImage extends AbstractGeoViewRaster {
if (requestResult.length > 0) {
// Get the OpenLayer that was created
olLayer = requestResult[0] as ImageLayer<ImageArcGISRest>;
}

// If no olLayer was obtained
if (!olLayer) {
// We're working in old LAYERS_HYBRID_MODE (in the new mode the code below is handled in the new classes)
const imageLayerOptions: ImageOptions<ImageArcGISRest> = {
source,
properties: { layerConfig },
};
// layerConfig.initialSettings cannot be undefined because config-validation set it to {} if it is undefined.
if (layerConfig.initialSettings?.className !== undefined) imageLayerOptions.className = layerConfig.initialSettings.className;
if (layerConfig.initialSettings?.extent !== undefined) imageLayerOptions.extent = layerConfig.initialSettings.extent;
if (layerConfig.initialSettings?.maxZoom !== undefined) imageLayerOptions.maxZoom = layerConfig.initialSettings.maxZoom;
if (layerConfig.initialSettings?.minZoom !== undefined) imageLayerOptions.minZoom = layerConfig.initialSettings.minZoom;
if (layerConfig.initialSettings?.states?.opacity !== undefined)
imageLayerOptions.opacity = layerConfig.initialSettings.states.opacity;
// If a layer on the map has an initialSettings.visible set to false, its status will never reach the status 'loaded' because
// nothing is drawn on the map. We must wait until the 'loaded' status is reached to set the visibility to false. The call
// will be done in the layerConfig.loadedFunction() which is called right after the 'loaded' signal.

// Create the OpenLayer layer
olLayer = new ImageLayer(imageLayerOptions);

// Hook the loaded event
this.setLayerAndLoadEndListeners(layerConfig, olLayer, 'image');
}
} else throw new Error('Error on layerRequesting event');

// GV Time to emit about the layer creation!
this.emitLayerCreation({ config: layerConfig, layer: olLayer });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import axios from 'axios';

import Static, { Options as SourceOptions } from 'ol/source/ImageStatic';
import BaseLayer from 'ol/layer/Base';
import { Options as ImageOptions } from 'ol/layer/BaseImage';
import ImageLayer from 'ol/layer/Image';
import { Extent } from 'ol/extent';

Expand Down Expand Up @@ -274,27 +273,7 @@ export class ImageStatic extends AbstractGeoViewRaster {
if (requestResult.length > 0) {
// Get the OpenLayer that was created
olLayer = requestResult[0] as ImageLayer<Static>;
}

// If no olLayer was obtained
if (!olLayer) {
// We're working in old LAYERS_HYBRID_MODE (in the new mode the code below is handled in the new classes)
const staticImageOptions: ImageOptions<Static> = { source };
// layerConfig.initialSettings cannot be undefined because config-validation set it to {} if it is undefined.
if (layerConfig.initialSettings?.extent !== undefined) staticImageOptions.extent = layerConfig.initialSettings.extent;
if (layerConfig.initialSettings?.maxZoom !== undefined) staticImageOptions.maxZoom = layerConfig.initialSettings.maxZoom;
if (layerConfig.initialSettings?.minZoom !== undefined) staticImageOptions.minZoom = layerConfig.initialSettings.minZoom;
if (layerConfig.initialSettings?.states?.opacity !== undefined)
staticImageOptions.opacity = layerConfig.initialSettings.states.opacity;
// GV IMPORTANT: The initialSettings.visible flag must be set in the layerConfig.loadedFunction otherwise the layer will stall
// GV in the 'loading' state if the flag value is false.

// Create the OpenLayer layer
olLayer = new ImageLayer(staticImageOptions);

// Hook the loaded event
this.setLayerAndLoadEndListeners(layerConfig, olLayer, 'image');
}
} else throw new Error('Error on layerRequesting event');

// GV Time to emit about the layer creation!
this.emitLayerCreation({ config: layerConfig, layer: olLayer });
Expand Down
Loading

0 comments on commit 52cadd4

Please sign in to comment.