|
| 1 | +import { Controller } from '@hotwired/stimulus'; |
| 2 | +export type LatLng = { |
| 3 | + lat: number; |
| 4 | + lng: number; |
| 5 | +}; |
| 6 | +export type MapView<Options, MarkerOptions, InfoWindowOptions> = { |
| 7 | + center: LatLng; |
| 8 | + zoom: number; |
| 9 | + fitBoundsToMarkers: boolean; |
| 10 | + markers: Array<MarkerDefinition<MarkerOptions, InfoWindowOptions>>; |
| 11 | + options: Options; |
| 12 | +}; |
| 13 | +export type MarkerDefinition<MarkerOptions, InfoWindowOptions> = { |
| 14 | + position: LatLng; |
| 15 | + title: string | null; |
| 16 | + infoWindow?: Omit<InfoWindowDefinition<InfoWindowOptions>, 'position'>; |
| 17 | + rawOptions?: MarkerOptions; |
| 18 | +}; |
| 19 | +export type InfoWindowDefinition<InfoWindowOptions> = { |
| 20 | + headerContent: string | null; |
| 21 | + content: string | null; |
| 22 | + position: LatLng; |
| 23 | + opened: boolean; |
| 24 | + autoClose: boolean; |
| 25 | + rawOptions?: InfoWindowOptions; |
| 26 | +}; |
| 27 | +export default abstract class<MapOptions, Map, MarkerOptions, Marker, InfoWindowOptions, InfoWindow> extends Controller<HTMLElement> { |
| 28 | + static values: { |
| 29 | + providerOptions: ObjectConstructor; |
| 30 | + view: ObjectConstructor; |
| 31 | + }; |
| 32 | + viewValue: MapView<MapOptions, MarkerOptions, InfoWindowOptions>; |
| 33 | + protected map: Map; |
| 34 | + protected markers: Array<Marker>; |
| 35 | + protected infoWindows: Array<InfoWindow>; |
| 36 | + initialize(): void; |
| 37 | + connect(): void; |
| 38 | + protected abstract doCreateMap({ center, zoom, options, }: { |
| 39 | + center: LatLng; |
| 40 | + zoom: number; |
| 41 | + options: MapOptions; |
| 42 | + }): Map; |
| 43 | + createMarker(definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>): Marker; |
| 44 | + protected abstract doCreateMarker(definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>): Marker; |
| 45 | + protected createInfoWindow({ definition, marker, }: { |
| 46 | + definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow']; |
| 47 | + marker: Marker; |
| 48 | + }): InfoWindow; |
| 49 | + protected abstract doCreateInfoWindow({ definition, marker, }: { |
| 50 | + definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow']; |
| 51 | + marker: Marker; |
| 52 | + }): InfoWindow; |
| 53 | + protected abstract doFitBoundsToMarkers(): void; |
| 54 | + private dispatchEvent; |
| 55 | +} |
0 commit comments