|
1 | | -import AbstractMapController from '@symfony/ux-map/abstract-map-controller'; |
| 1 | +import { Controller } from '@hotwired/stimulus'; |
2 | 2 | import { Loader } from '@googlemaps/js-api-loader'; |
3 | 3 |
|
| 4 | +let default_1$1 = class default_1 extends Controller { |
| 5 | + constructor() { |
| 6 | + super(...arguments); |
| 7 | + this.markers = []; |
| 8 | + this.infoWindows = []; |
| 9 | + } |
| 10 | + connect() { |
| 11 | + const { center, zoom, options, markers, fitBoundsToMarkers } = this.viewValue; |
| 12 | + this.dispatchEvent('pre-connect', { options }); |
| 13 | + this.map = this.doCreateMap({ center, zoom, options }); |
| 14 | + markers.forEach((marker) => this.createMarker(marker)); |
| 15 | + if (fitBoundsToMarkers) { |
| 16 | + this.doFitBoundsToMarkers(); |
| 17 | + } |
| 18 | + this.dispatchEvent('connect', { |
| 19 | + map: this.map, |
| 20 | + markers: this.markers, |
| 21 | + infoWindows: this.infoWindows, |
| 22 | + }); |
| 23 | + } |
| 24 | + createMarker(definition) { |
| 25 | + this.dispatchEvent('marker:before-create', { definition }); |
| 26 | + const marker = this.doCreateMarker(definition); |
| 27 | + this.dispatchEvent('marker:after-create', { marker }); |
| 28 | + this.markers.push(marker); |
| 29 | + return marker; |
| 30 | + } |
| 31 | + createInfoWindow({ definition, marker, }) { |
| 32 | + this.dispatchEvent('info-window:before-create', { definition, marker }); |
| 33 | + const infoWindow = this.doCreateInfoWindow({ definition, marker }); |
| 34 | + this.dispatchEvent('info-window:after-create', { infoWindow, marker }); |
| 35 | + this.infoWindows.push(infoWindow); |
| 36 | + return infoWindow; |
| 37 | + } |
| 38 | +}; |
| 39 | +default_1$1.values = { |
| 40 | + providerOptions: Object, |
| 41 | + view: Object, |
| 42 | +}; |
| 43 | + |
4 | 44 | let _google; |
5 | | -class default_1 extends AbstractMapController { |
| 45 | +class default_1 extends default_1$1 { |
6 | 46 | async connect() { |
7 | 47 | if (!_google) { |
8 | 48 | _google = { maps: {} }; |
|
0 commit comments