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