-
Notifications
You must be signed in to change notification settings - Fork 0
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 #4 from helsingborg-stad/refactor/options
refactor: options
- Loading branch information
Showing
8 changed files
with
83 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { ConfigInterface } from './setupMap/config/configInterface'; | ||
import { Map as LeafletMap } from 'leaflet'; | ||
import { ConfigOptions } from './types'; | ||
|
||
export interface MapInterface { | ||
getMap(): LeafletMap; | ||
getConfig(): ConfigInterface; | ||
getOptions(): ConfigOptions; | ||
} |
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,37 +1,35 @@ | ||
import { LatLngObject } from "../../types"; | ||
import { ConfigInterface, Options, AttributionPosition, MapStyle } from "./configInterface"; | ||
import { PartialConfigOptions, ConfigOptions } from "../../types"; | ||
import { ConfigInterface } from "./configInterface"; | ||
|
||
export class Config implements ConfigInterface { | ||
constructor(private options: Options) { | ||
} | ||
|
||
public getId(): string { | ||
return this.options.id; | ||
} | ||
|
||
public getMapStyle(): MapStyle { | ||
return this.options.mapStyle ?? 'default'; | ||
} | ||
|
||
public getStartPosition(): LatLngObject { | ||
return this.options.startPosition && this.options.startPosition.lat && this.options.startPosition.lng ? | ||
this.options.startPosition : | ||
{ lat: 59.32932, lng: 18.06858 }; | ||
} | ||
|
||
public getInitialZoom(): number { | ||
return this.options.initialZoom ?? 16; | ||
} | ||
|
||
public getMaxZoom(): number { | ||
return this.options.maxZoom ?? 19; | ||
} | ||
|
||
public getMinZoom(): number { | ||
return this.options.minZoom ?? 0; | ||
} | ||
|
||
public getAttributionPosition(): AttributionPosition { | ||
return this.options.attributionPosition ?? 'bottomleft'; | ||
private options: ConfigOptions; | ||
constructor(options: PartialConfigOptions) { | ||
this.options = this.getOptions(options); | ||
} | ||
|
||
private getOptions(options: PartialConfigOptions): ConfigOptions { | ||
return { | ||
...this.getDefaultOptions(), | ||
...options | ||
} | ||
} | ||
|
||
private getDefaultOptions(): ConfigOptions { | ||
return { | ||
id: '', | ||
mapStyle: 'default', | ||
keyboard: false, | ||
attributionPosition: 'bottomleft', | ||
center: { lat: 59.32932, lng: 18.06858 }, | ||
zoom: 16, | ||
maxZoom: 19, | ||
minZoom: 0, | ||
zoomControl: false, | ||
scrollWheelZoom: false | ||
} | ||
} | ||
|
||
public getConfig(): ConfigOptions { | ||
return this.options; | ||
} | ||
} |
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,24 +1,5 @@ | ||
import { LatLngObject, Nullable } from '../../types'; | ||
|
||
export type MapStyle = "dark"|"pale"|"default"|"color"; | ||
export type AttributionPosition = "topleft"|"topright"|"bottomleft"|"bottomright"; | ||
|
||
export type Options = { | ||
id: string; | ||
mapStyle?: Nullable<MapStyle>; | ||
startPosition?: Nullable<LatLngObject>; | ||
initialZoom?: Nullable<number>; | ||
maxZoom?: Nullable<number> | ||
minZoom?: Nullable<number> | ||
attributionPosition?: Nullable<AttributionPosition> | ||
} | ||
import { LatLngObject, MapStyle, AttributionPosition, ConfigOptions } from '../../types'; | ||
|
||
export interface ConfigInterface { | ||
getId(): string; | ||
getMapStyle(): MapStyle; | ||
getStartPosition(): LatLngObject; | ||
getInitialZoom(): number; | ||
getMaxZoom(): number; | ||
getMinZoom(): number; | ||
getAttributionPosition(): AttributionPosition; | ||
getConfig(): ConfigOptions; | ||
} |
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