-
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.
Merge pull request #1351 from jolevesq/1328-store-ol
refactor(store): Moved OL events in the store (#1351) Co-Authored-By: Johann Levesque <[email protected]>
- Loading branch information
Showing
15 changed files
with
231 additions
and
194 deletions.
There are no files selected for viewing
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
57 changes: 45 additions & 12 deletions
57
packages/geoview-core/src/api/eventProcessors/map-event-process.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 |
---|---|---|
@@ -1,28 +1,61 @@ | ||
import { GeoViewStoreType } from '@/core/stores/geoview-store'; | ||
import { AbstractEventProcessor } from './abstract-event-processor'; | ||
import { api } from '@/app'; | ||
import { mapPayload, lngLatPayload, mapMouseEventPayload } from '@/api/events/payloads'; | ||
import { mapPayload, lngLatPayload, mapMouseEventPayload, numberPayload } from '@/api/events/payloads'; | ||
import { EVENT_NAMES } from '@/api/events/event-types'; | ||
|
||
export class MapEventProcessor extends AbstractEventProcessor { | ||
onInitialize(store: GeoViewStoreType) { | ||
const unsub = store.subscribe((curState, prevState) => { | ||
if (curState.mapState.mapLoaded && prevState.mapState.mapLoaded === false && curState.mapState.mapElement) { | ||
api.event.emit(mapPayload(EVENT_NAMES.MAP.EVENT_MAP_LOADED, curState.mapId, curState.mapState.mapElement)); | ||
const { mapId } = store.getState(); | ||
|
||
const unsubMapLoaded = store.subscribe( | ||
(state) => state.mapState.mapLoaded, | ||
(cur, prev) => { | ||
if (cur !== prev) api.event.emit(mapPayload(EVENT_NAMES.MAP.EVENT_MAP_LOADED, mapId, store.getState().mapState.mapElement!)); | ||
} | ||
); | ||
|
||
const unsubMapCenterCoord = store.subscribe( | ||
(state) => state.mapState.mapCenterCoordinates, | ||
(cur, prev) => { | ||
if (cur !== prev) { | ||
api.maps[mapId].mapCenterCoordinates = cur; | ||
api.event.emit(lngLatPayload(EVENT_NAMES.MAP.EVENT_MAP_MOVE_END, mapId, cur)); | ||
} | ||
} | ||
); | ||
|
||
const unsubMapPointerPosition = store.subscribe( | ||
(state) => state.mapState.pointerPosition, | ||
(cur, prev) => { | ||
if (cur !== prev) { | ||
api.maps[mapId].pointerPosition = cur!; | ||
api.event.emit(mapMouseEventPayload(EVENT_NAMES.MAP.EVENT_MAP_POINTER_MOVE, mapId, cur!)); | ||
} | ||
} | ||
); | ||
|
||
if (curState.mapState.mapCenterCoordinates !== prevState.mapState.mapCenterCoordinates) { | ||
api.maps[curState.mapId].mapCenterCoordinates = curState.mapState.mapCenterCoordinates; | ||
api.event.emit(lngLatPayload(EVENT_NAMES.MAP.EVENT_MAP_MOVE_END, curState.mapId, curState.mapState.mapCenterCoordinates)); | ||
const unsubMapZoom = store.subscribe( | ||
(state) => state.mapState.zoom, | ||
(cur, prev) => { | ||
if (cur !== prev) { | ||
api.maps[mapId].currentZoom = cur!; | ||
api.event.emit(numberPayload(EVENT_NAMES.MAP.EVENT_MAP_ZOOM_END, mapId, cur!)); | ||
} | ||
} | ||
); | ||
|
||
if (curState.mapState.pointerPosition !== prevState.mapState.pointerPosition) { | ||
api.maps[curState.mapId].pointerPosition = curState.mapState.pointerPosition!; | ||
api.event.emit(mapMouseEventPayload(EVENT_NAMES.MAP.EVENT_MAP_POINTER_MOVE, curState.mapId, curState.mapState.pointerPosition!)); | ||
const unsubMapSingleClick = store.subscribe( | ||
(state) => state.mapState.mapClickCoordinates, | ||
(cur, prev) => { | ||
if (cur !== prev) { | ||
api.maps[mapId].singleClickedPosition = cur!; | ||
api.event.emit(mapMouseEventPayload(EVENT_NAMES.MAP.EVENT_MAP_SINGLE_CLICK, mapId, cur!)); | ||
} | ||
} | ||
}); | ||
); | ||
|
||
// add to arr of subscriptions so it can be destroyed later | ||
this.subscriptionArr.push(unsub); | ||
this.subscriptionArr.push(unsubMapLoaded, unsubMapCenterCoord, unsubMapPointerPosition, unsubMapZoom, unsubMapSingleClick); | ||
} | ||
} |
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.