Skip to content

Commit

Permalink
FullscreenMap replaces LeafletMap, increasing consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Stassi committed Nov 15, 2024
1 parent 9725d8e commit b4eb66d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/leaf/map/fullscreen/fullscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { controlAddedListener } from './control/control-added-listener'
import { type ControlAnchorTitleStates } from './control/anchor/update-title'
import { joinClassNames } from './dom-element/join-class-names'
import {
type LeafletMapLifecycleEvent,
mapLifecycleListener,
type FullscreenMapLifecycleEvent,
fullscreenMapLifecycleListener,
} from './map/map-lifecycle-listener'
import {
type ControlAnchor,
Expand Down Expand Up @@ -110,11 +110,11 @@ export function fullscreenMap({
control: Control = leafletControl({ position }),
map: Map = leafletMap(id, mapOptions),
handleMapLifecycleChange: (
mapLifecycleEvents: LeafletMapLifecycleEvent,
mapLifecycleEvents: FullscreenMapLifecycleEvent,
) => () => void = (
mapLifecycleEvent: LeafletMapLifecycleEvent,
mapLifecycleEvent: FullscreenMapLifecycleEvent,
): (() => void) =>
mapLifecycleListener({
fullscreenMapLifecycleListener({
document: {
map: {
control: {
Expand Down
20 changes: 11 additions & 9 deletions src/leaf/map/fullscreen/map/map-lifecycle-listener.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { DomEvent, DomUtil, type Map } from 'leaflet'
import { type Map, DomEvent, DomUtil } from 'leaflet'

import { type ControlAnchorAssign } from '../control/anchor/anchor'
import { type UseBoolean } from '../state/use-boolean'
import { type ControlAnchorAssign } from '../control/anchor/anchor'
import {
type ControlAnchorTitleStates,
updateControlAnchorTitle,
} from '../control/anchor/update-title'

export type LeafletMapLifecycleEvent = 'ready' | 'unload'
export type MapLifecycleListenerOptions = {
export type FullscreenMapLifecycleEvent = 'ready' | 'unload'
export type FullscreenMapLifecycleListenerOptions = {
document: {
map: {
control: {
Expand All @@ -21,13 +21,15 @@ export type MapLifecycleListenerOptions = {
classNames: string
state: UseBoolean
}
lifecycleEvent: LeafletMapLifecycleEvent
lifecycleEvent: FullscreenMapLifecycleEvent
map: Map
}
}
}

export function mapLifecycleListener({
export type FullscreenMapLifecycleListener = () => void

export function fullscreenMapLifecycleListener({
document: {
map: {
control: {
Expand All @@ -41,13 +43,13 @@ export function mapLifecycleListener({
map,
},
},
}: MapLifecycleListenerOptions) {
return function handleFullscreenMapLifecycleEvent() {
}: FullscreenMapLifecycleListenerOptions): FullscreenMapLifecycleListener {
return function handleFullscreenMapLifecycleEvent(): void {
DomEvent[mapLifecycleEvent === 'ready' ? 'on' : 'off'](
// @ts-expect-error -- `Document` type is assignable to first DomEvent.on argument
document,
'fullscreenchange',
function handleFullscreenMapChange() {
function handleFullscreenMapChange(): void {
;(getFullscreenState() ? DomUtil.removeClass : DomUtil.addClass)(
map.getContainer(),
fullscreenMapClassNames,
Expand Down

0 comments on commit b4eb66d

Please sign in to comment.