Skip to content

Commit

Permalink
Merge branch 'develop' into adding-global-style-overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
cphelefu authored Feb 21, 2024
2 parents 1427b4b + dc2a362 commit 594375d
Show file tree
Hide file tree
Showing 25 changed files with 777 additions and 421 deletions.
2 changes: 1 addition & 1 deletion packages/geoview-core/public/configs/sample-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
},
"externalPackages": [],
"serviceUrls": {
"keys": "https://geocore.api.geo.ca"
"geocoreUrl": "https://geocore.api.geo.ca"
},
"suportedLanguages": ["en", "fr"],
"version": "1.0"
Expand Down
29 changes: 24 additions & 5 deletions packages/geoview-core/public/templates/raw-add-layers.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,22 @@ <h4>Add Layer Examples</h4>
<li class="source-link">https://b6ryuvakk5.execute-api.us-east-1.amazonaws.com/dev/collections/lakes</li>
</ul>
</div>
<div>
GeoCore UUID Layer
<ul>
<li>ccc75c12-5acc-4a6a-959f-ef6f621147b9</li>
</ul>
<div style="margin-bottom:20px;">
<div>
GeoCore UUID Layer
</div>
<div style="margin-top:10px; margin-left:20px;">
<input id='selectGeoCore' list="geocoreids" style="width:300px;">
<datalist id="geocoreids">
<option value="21b821cf-0f1c-40ee-8925-eab12d357668"></option>
<option value="ccc75c12-5acc-4a6a-959f-ef6f621147b9"></option>
<option value="0fca08b5-e9d0-414b-a3c4-092ff9c5e326"></option>
<option value="03ccfb5c-a06e-43e3-80fd-09d4f8f69703"></option>
<option value="ea4c0bdb-a63f-49a4-b14a-09c1560aad0b"></option>
<option value="0fe65119-e96e-4a57-8bfe-9d9245fba06b"></option>
</datalist>
<button type="button" onclick="addGeocore()">Add layer</button>
</div>
</div>
<div>
GeoPackage Layer
Expand Down Expand Up @@ -293,6 +304,14 @@ <h4 id="HUC2">2. Layer Panel with layers in config</h4>
<script src="codedoc.js"></script>

<script>
function addGeocore() {
// Precond
if (!document.getElementById('selectGeoCore').value) return;

// Add the layer on the map
cgpv.api.maps['mapWM'].layer.addGeoviewLayerByGeoCoreUUID(document.getElementById('selectGeoCore').value);
}

document.addEventListener('DOMContentLoaded', function () {
var sourceLinks = document.querySelectorAll('li.source-link');

Expand Down
2 changes: 1 addition & 1 deletion packages/geoview-core/schema-default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"corePackages": [],
"externalPackages": [],
"serviceUrls": {
"keys": "https://geocore.api.geo.ca",
"geocoreUrl": "https://geocore.api.geo.ca",
"geolocator": "https://geolocator.api.geo.ca?keys=geonames,nominatim,locate"
},
"suportedLanguages": [
Expand Down
6 changes: 2 additions & 4 deletions packages/geoview-core/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@
"type": "object",
"description": "Service endpoint urls",
"properties": {
"keys": {
"geocoreUrl": {
"type": "string",
"default": "https://geocore.api.geo.ca",
"description": "Service end point to access API for layers specification (loading and plugins parameters). By default it is GeoCore but can be another endpoint with similar output."
Expand All @@ -2061,9 +2061,7 @@
"description": "Service end point to access geo location of searched value."
}
},
"required": [
"keys"
]
"required": ["geocoreUrl"]
},
"TypeDisplayLanguage": {
"enum": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GeoviewStoreType, IFeatureInfoState } from '@/core/stores';
import { TypeFeatureInfoResultsSet, EventType, TypeLayerData, TypeArrayOfLayerData } from '@/api/events/payloads/get-feature-info-payload';
import { IFeatureInfoState } from '@/core/stores';
import { logger } from '@/core/utils/logger';

import { GeochartEventProcessor } from './geochart-event-processor';
import { AbstractEventProcessor, BatchedPropagationLayerDataArrayByMap } from '../abstract-event-processor';
import { UIEventProcessor } from './ui-event-processor';

Expand All @@ -25,6 +25,45 @@ export class FeatureInfoEventProcessor extends AbstractEventProcessor {
// The longer the delay, the longer it'll take to update the UI. The delay can be bypassed using the layer path bypass method.
private static timeDelayBetweenPropagationsForBatch = 1000;

/**
* Overrides initialization of the Feature Info Event Processor
* @param {GeoviewStoreType} store The store associated with the Feature Info Event Processor
* @returns An array of the subscriptions callbacks which were created
*/
protected onInitialize(store: GeoviewStoreType): Array<() => void> | void {
// Checks for udpated layers in layer order
const unsubLayerRemoved = store.subscribe(
(state) => state.mapState.layerOrder,
(cur, prev) => {
// Log
logger.logTraceCoreStoreSubscription('FEATUREINFO EVENT PROCESSOR - layerOrder', cur);

// For each layer path in the layer data array
store
.getState()
.detailsState.layerDataArray.map((layerInfo) => layerInfo.layerPath)
.forEach((layerPath) => {
// If it was in the layer data array and is not anymore
if (prev.includes(layerPath) && !cur.includes(layerPath)) {
// Remove it from feature info array
FeatureInfoEventProcessor.deleteFeatureInfo(store.getState().mapId, layerPath);

// Remove it from hover array
FeatureInfoEventProcessor.deleteFeatureHoverInfo(store.getState().mapId, layerPath);

// Remove it from all features array
FeatureInfoEventProcessor.deleteFeatureAllInfo(store.getState().mapId, layerPath);

// Log
logger.logDebug('Removed Feature Info in stores for layer path:', layerPath);
}
});
}
);

return [unsubLayerRemoved];
}

/**
* Shortcut to get the Feature Info state for a given map id
* @param {string} mapId The mapId
Expand All @@ -36,15 +75,93 @@ export class FeatureInfoEventProcessor extends AbstractEventProcessor {
}

/**
* Static method used to propagate feature info layer sets to the store
* Deletes the specified layer path from the layer sets in the store
* @param {string} mapId The map identifier
* @param {string} layerPath The layer path to delete
*/
private static deleteFeatureInfo(mapId: string, layerPath: string) {
// The feature info state
const featureInfoState = this.getFeatureInfoState(mapId);

// Redirect to helper function
this.deleteFromArray(featureInfoState.layerDataArray, layerPath, (layerArrayResult) => {
// Update the layer data array in the store
featureInfoState.actions.setLayerDataArray(layerArrayResult);

// Also propagate in the batched array
FeatureInfoEventProcessor.propagateFeatureInfoToStoreBatch(mapId, layerArrayResult);
});
}

/**
* Deletes the specified layer path from the hover layers sets in the store
* @param {string} mapId The map identifier
* @param {string} layerPath The layer path to delete
*/
private static deleteFeatureHoverInfo(mapId: string, layerPath: string) {
// The feature info state
const featureInfoState = this.getFeatureInfoState(mapId);

// Redirect to helper function
this.deleteFromArray(featureInfoState.hoverDataArray, layerPath, (layerArrayResult) => {
// Update the layer data array in the store
featureInfoState.actions.setHoverDataArray(layerArrayResult);
});
}

/**
* Deletes the specified layer path from the all features layers sets in the store
* @param {string} mapId The map identifier
* @param {string} layerPath The layer path to delete
*/
private static deleteFeatureAllInfo(mapId: string, layerPath: string) {
// The feature info state
const featureInfoState = this.getFeatureInfoState(mapId);

// Redirect to helper function
this.deleteFromArray(featureInfoState.allFeaturesDataArray, layerPath, (layerArrayResult) => {
// Update the layer data array in the store
featureInfoState.actions.setAllFeaturesDataArray(layerArrayResult);
});
}

/**
* Helper function to delete a layer information from an array when found
* @param {TypeArrayOfLayerData} layerArray The layer array to work with
* @param {string} layerPath The layer path to delete
* @param {(layerArray: TypeArrayOfLayerData) => void} onDeleteCallback The callback executed when the array is updated
*/
private static deleteFromArray(
layerArray: TypeArrayOfLayerData,
layerPath: string,
onDeleteCallback: (layerArray: TypeArrayOfLayerData) => void
) {
// Find the layer data info to delete from the array
const layerDataInfoToDelIndex = layerArray.findIndex((layerInfo) => layerInfo.layerPath === layerPath);

// If found
if (layerDataInfoToDelIndex >= 0) {
// Remove from the array
layerArray.splice(layerDataInfoToDelIndex, 1);

// Callback with updated array
onDeleteCallback(layerArray);
}
}

/**
* Propagates feature info layer sets to the store
*
* @param {string} mapId The map identifier of the resul set modified.
* @param {string} mapId The map identifier of the modified result set.
* @param {string} layerPath The layer path that has changed.
* @param {EventType} eventType The event type that triggered the layer set update.
* @param {TypeFeatureInfoResultsSet} resultsSet The resul sets associated to the map.
*/
static propagateFeatureInfoToStore(mapId: string, layerPath: string, eventType: EventType, resultsSet: TypeFeatureInfoResultsSet) {
// The feature info state
const featureInfoState = this.getFeatureInfoState(mapId);

// Depending on the event type
if (eventType === 'click') {
/**
* Create a details object for each layer which is then used to render layers in details panel.
Expand All @@ -66,9 +183,6 @@ export class FeatureInfoEventProcessor extends AbstractEventProcessor {

// Also propagate in the batched array
FeatureInfoEventProcessor.propagateFeatureInfoToStoreBatch(mapId, layerDataArray);

// Also propagate in the geochart arrays
GeochartEventProcessor.propagateArrayDataToStore(mapId, layerDataArray);
} else if (eventType === 'hover') {
/**
* Create a hover object for each layer which is then used to render layers
Expand All @@ -91,7 +205,7 @@ export class FeatureInfoEventProcessor extends AbstractEventProcessor {
}

/**
* Propagate feature info layer sets to the store in a batched manner, every 'timeDelayBetweenPropagationsForBatch' millisecond.
* Propagates feature info layer sets to the store in a batched manner, every 'timeDelayBetweenPropagationsForBatch' millisecond.
* This is used to provide another 'layerDataArray', in the store, which updates less often so that we save a couple 'layerDataArray'
* update triggers in the components that are listening to the store array.
* The propagation can be bypassed using the store 'layerDataArrayBatchLayerPathBypass' state which tells the process to
Expand Down
Loading

0 comments on commit 594375d

Please sign in to comment.