-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stores created Style class created and separated from component Fix for the path for the guide panel Swiper, working state Swiper improved Moved the addEventListener and removeEventListener from the rendering phase to a useEffect mount hook. Better logs and comments Swiper working Had to use async afterall to retrieve the OpenLayers layers Adjusting the swiper template configs to use layer path Finalizing Cleanup
- Loading branch information
1 parent
f3675d4
commit cce9c13
Showing
21 changed files
with
662 additions
and
278 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/geoview-core/public/configs/package-swiper-config-swiper.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"orientation": "vertical", | ||
"keyboardOffset": 10, | ||
"layers": ["esriFeatureLYR4"], | ||
"layers": ["esriFeatureLYR4/0"], | ||
"suportedLanguages": ["en", "fr"] | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/geoview-core/public/configs/package-swiper2-config-swiper.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"orientation": "horizontal", | ||
"keyboardOffset": 10, | ||
"layers": ["esriFeatureLYR4-map2", "esriDynamicLYR3-map2"], | ||
"layers": ["esriFeatureLYR4-map2/2", "esriDynamicLYR3-map2/0"], | ||
"suportedLanguages": ["en", "fr"] | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/geoview-core/public/configs/package-swiper3-config-swiper.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"orientation": "vertical", | ||
"keyboardOffset": 10, | ||
"layers": ["swipe0", "swipe1", "swipe4", "swipe5", "swipe6", "rcs.ccc75c12-5acc-4a6a-959f-ef6f621147b9.en", "swipe7"], | ||
"layers": ["swipe0/toner", "swipe1/msi-94-or-more", "swipe4/polygons.json", "swipe5/ec-msc:CURRENT_CONDITIONS", "swipe6/lakes", "rcs.ccc75c12-5acc-4a6a-959f-ef6f621147b9.en/0"], | ||
"suportedLanguages": ["en", "fr"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
.../geoview-core/src/api/event-processors/event-processor-children/swiper-event-processor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import { GeoviewStoreType } from '@/core/stores'; | ||
import { ISwiperState } from '@/core/stores/store-interface-and-intial-values/swiper-state'; | ||
import { logger } from '@/core/utils/logger'; | ||
|
||
import { AbstractEventProcessor } from '../abstract-event-processor'; | ||
|
||
/** | ||
* Event processor focusing on interacting with the swiper state in the store. | ||
*/ | ||
export class SwiperEventProcessor extends AbstractEventProcessor { | ||
// ********************************************************** | ||
// Static functions for Typescript files to access store actions | ||
// ********************************************************** | ||
//! Typescript MUST always use the defined store actions below to modify store - NEVER use setState! | ||
//! Some action does state modifications AND map actions. | ||
//! ALWAYS use map event processor when an action modify store and IS NOT trap by map state event handler | ||
|
||
/** | ||
* Overrides initialization of the Swiper Event Processor | ||
* @param {GeoviewStoreType} store The store associated with the Swiper 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.orderedLayerInfo, | ||
(cur, prev) => { | ||
// Log | ||
logger.logTraceCoreStoreSubscription('SWIPER EVENT PROCESSOR - orderedLayerInfo', cur); | ||
|
||
// Read the layer paths of each layer info | ||
const curOrderedLayerPaths = cur.map((layerInfo) => layerInfo.layerPath); | ||
const prevOrderedLayerPaths = prev.map((layerInfo) => layerInfo.layerPath); | ||
|
||
// Get all the layer paths to check in a distinct array for looping purposes | ||
const layerPathsToCheck = [...store.getState().swiperState.layerPaths]; | ||
|
||
// For each layer paths the swiper is using | ||
layerPathsToCheck.forEach((layerPath) => { | ||
// If it was in the layerdata array and is not anymore | ||
if (prevOrderedLayerPaths.includes(layerPath) && !curOrderedLayerPaths.includes(layerPath)) { | ||
// Remove it | ||
SwiperEventProcessor.removeLayerPath(store.getState().mapId, layerPath); | ||
} | ||
}); | ||
} | ||
); | ||
|
||
return [unsubLayerRemoved]; | ||
} | ||
|
||
/** | ||
* Shortcut to get the Swiper state for a given map id | ||
* @param {string} mapId The mapId | ||
* @returns {ISwiperState | undefined} The Swiper state. Forcing the return to also be 'undefined', because | ||
* there will be no swiperState if the Swiper plugin isn't active. | ||
* This helps the developers making sure the existence is checked. | ||
*/ | ||
protected static getSwiperState(mapId: string): ISwiperState | undefined { | ||
// Return the swiper state when it exists | ||
return super.getState(mapId).swiperState; | ||
} | ||
|
||
/** | ||
* Sets the layer paths on which the swiper should be activated. | ||
* | ||
* @param {string} mapId the map id | ||
* @param {string[]} layerPaths The array of layer paths | ||
*/ | ||
static setLayerPaths(mapId: string, layerPaths: string[]): void { | ||
// set store layer paths | ||
this.getSwiperState(mapId)?.actions.setLayerPaths(layerPaths); | ||
|
||
// Log | ||
logger.logInfo('Added Swiper functionality for layer paths:', layerPaths); | ||
|
||
// TODO: Also update the layer array in other store state to inform the later has a swiper attached to it? | ||
} | ||
|
||
/** | ||
* Adds a swipe functionality to the specified map id and layer path | ||
* @param {string} mapId The map ID | ||
* @param {string} layerPath The layer path | ||
*/ | ||
static addLayerPath(mapId: string, layerPath: string): void { | ||
// The processor needs an initialized layer paths store which is only initialized if the Swiper Plugin exists. | ||
// Therefore, we validate its existence first. | ||
if (!this.getSwiperState(mapId)) return; | ||
if (!this.getSwiperState(mapId)?.layerPaths) return; | ||
|
||
// If not already added | ||
if (!this.getSwiperState(mapId)!.layerPaths.includes(layerPath)) { | ||
// Add in the array | ||
const updatedArray = [...this.getSwiperState(mapId)!.layerPaths]; | ||
updatedArray.push(layerPath); | ||
|
||
// Update the layer data array in the store | ||
this.getSwiperState(mapId)!.actions.setLayerPaths(updatedArray); | ||
|
||
// Log | ||
logger.logInfo('Added Swiper functionality for layer path:', layerPath); | ||
|
||
// TODO: Also update the layer array in other store state to inform the later has a swiper attached to it? | ||
} else { | ||
// Log | ||
logger.logInfo('Swiper functionality already active for layer path:', layerPath); | ||
} | ||
} | ||
|
||
/** | ||
* Removes a swipe functionality for the specified map id and layer path | ||
* @param {string} mapId The map ID | ||
* @param {string} layerPath The layer path | ||
*/ | ||
static removeLayerPath(mapId: string, layerPath: string): void { | ||
// The processor needs an initialized layer paths store which is only initialized if the Swiper Plugin exists. | ||
// Therefore, we validate its existence first. | ||
if (!this.getSwiperState(mapId)) return; | ||
if (!this.getSwiperState(mapId)?.layerPaths) return; | ||
|
||
// Find the index with the layer path | ||
const layerIndex = this.getSwiperState(mapId)!.layerPaths.findIndex((layer) => layer === layerPath); | ||
|
||
// Config to remove | ||
if (layerIndex !== undefined && layerIndex >= 0) { | ||
// Remove from the array | ||
const updatedArray = [...this.getSwiperState(mapId)!.layerPaths]; | ||
updatedArray.splice(layerIndex, 1); | ||
|
||
// Update the layer data array in the store | ||
this.getSwiperState(mapId)!.actions.setLayerPaths(updatedArray); | ||
|
||
// Log | ||
logger.logInfo('Removed Swiper functionality for layer path:', layerPath); | ||
|
||
// TODO: Also update the layer array in other store state to inform the later has a swiper attached to it? | ||
} | ||
} | ||
|
||
/** | ||
* Removes the swipe functionality for all layer paths | ||
* @param {string} mapId The map ID | ||
*/ | ||
static removeAll(mapId: string) { | ||
// The processor needs an initialized layer paths store which is only initialized if the Swiper Plugin exists. | ||
// Therefore, we validate its existence first. | ||
if (!this.getSwiperState(mapId)) return; | ||
if (!this.getSwiperState(mapId)?.layerPaths) return; | ||
|
||
// Get all layer paths | ||
const { layerPaths } = this.getSwiperState(mapId)!; | ||
|
||
// Update the layer data array in the store | ||
this.getSwiperState(mapId)!.actions.setLayerPaths([]); | ||
|
||
// Log | ||
logger.logInfo('Removed Swiper functionality for all layer paths', layerPaths); | ||
|
||
// TODO: Also update the layer array in other store state to inform the later has a swiper attached to it? | ||
} | ||
|
||
// #endregion | ||
|
||
// ********************************************************** | ||
// Static functions for Store Map State to action on API | ||
// ********************************************************** | ||
//! NEVER add a store action who does set state AND map action at a same time. | ||
//! Review the action in store state to make sure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.