Skip to content

Commit c2223ed

Browse files
author
Danny van Wijk
committed
[Map] Add possibility to configure extra options
1 parent 8f02bd6 commit c2223ed

File tree

8 files changed

+31
-2
lines changed

8 files changed

+31
-2
lines changed

src/Map/src/Bridge/Google/assets/dist/map_controller.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { LoaderOptions } from '@googlemaps/js-api-loader';
22
import AbstractMapController from '@symfony/ux-map';
33
import type { Icon, InfoWindowWithoutPositionDefinition, MarkerDefinition, Point, PolygonDefinition, PolylineDefinition } from '@symfony/ux-map';
4-
type MapOptions = Pick<google.maps.MapOptions, 'mapId' | 'gestureHandling' | 'backgroundColor' | 'disableDoubleClickZoom' | 'zoomControl' | 'zoomControlOptions' | 'mapTypeControl' | 'mapTypeControlOptions' | 'streetViewControl' | 'streetViewControlOptions' | 'fullscreenControl' | 'fullscreenControlOptions'>;
4+
type MapOptions = Pick<google.maps.MapOptions, 'mapId' | 'gestureHandling' | 'backgroundColor' | 'disableDoubleClickZoom' | 'zoomControl' | 'zoomControlOptions' | 'mapTypeControl' | 'mapTypeControlOptions' | 'streetViewControl' | 'streetViewControlOptions' | 'fullscreenControl' | 'fullscreenControlOptions'> & {
5+
extra?: Record<string, unknown>;
6+
};
57
export default class extends AbstractMapController<MapOptions, google.maps.Map, google.maps.marker.AdvancedMarkerElementOptions, google.maps.marker.AdvancedMarkerElement, google.maps.InfoWindowOptions, google.maps.InfoWindow, google.maps.PolygonOptions, google.maps.Polygon, google.maps.PolylineOptions, google.maps.Polyline> {
68
providerOptionsValue: Pick<LoaderOptions, 'apiKey' | 'id' | 'language' | 'region' | 'nonce' | 'retries' | 'url' | 'version' | 'libraries'>;
79
map: google.maps.Map;

src/Map/src/Bridge/Google/assets/dist/map_controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class map_controller extends default_1 {
160160
options.fullscreenControl = typeof options.fullscreenControlOptions !== 'undefined';
161161
return new _google.maps.Map(this.element, {
162162
...options,
163+
...options.extra,
163164
center,
164165
zoom,
165166
});

src/Map/src/Bridge/Google/assets/src/map_controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ type MapOptions = Pick<
3333
| 'streetViewControlOptions'
3434
| 'fullscreenControl'
3535
| 'fullscreenControlOptions'
36-
>;
36+
> & {
37+
extra?: Record<string, unknown>;
38+
};
3739

3840
let _google: typeof google;
3941

@@ -135,6 +137,7 @@ export default class extends AbstractMapController<
135137

136138
return new _google.maps.Map(this.element, {
137139
...options,
140+
...options.extra,
138141
center,
139142
zoom,
140143
});

src/Map/src/Bridge/Google/src/GoogleOptions.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __construct(
3636
private StreetViewControlOptions $streetViewControlOptions = new StreetViewControlOptions(),
3737
private bool $fullscreenControl = true,
3838
private FullscreenControlOptions $fullscreenControlOptions = new FullscreenControlOptions(),
39+
private array $extra = [],
3940
) {
4041
}
4142

@@ -132,6 +133,13 @@ public function fullscreenControlOptions(FullscreenControlOptions $fullscreenCon
132133
return $this;
133134
}
134135

136+
public function extra(array $extra): self
137+
{
138+
$this->extra = $extra;
139+
140+
return $this;
141+
}
142+
135143
/**
136144
* @internal
137145
*/
@@ -174,6 +182,7 @@ public function toArray(): array
174182
'gestureHandling' => $this->gestureHandling->value,
175183
'backgroundColor' => $this->backgroundColor,
176184
'disableDoubleClickZoom' => $this->disableDoubleClickZoom,
185+
'extra' => $this->extra,
177186
];
178187

179188
if ($this->zoomControl) {

src/Map/src/Bridge/Leaflet/assets/dist/map_controller.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type MapOptions = Pick<LeafletMapOptions, 'center' | 'zoom'> & {
99
attribution: string;
1010
options: Record<string, unknown>;
1111
} | false;
12+
extra?: Record<string, unknown>;
1213
};
1314
export default class extends AbstractMapController<MapOptions, L.Map, MarkerOptions, L.Marker, PopupOptions, L.Popup, PolygonOptions, L.Polygon, PolylineOptions, L.Polyline> {
1415
map: L.Map;

src/Map/src/Bridge/Leaflet/assets/dist/map_controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class map_controller extends default_1 {
142142
doCreateMap({ center, zoom, options, }) {
143143
const map = L.map(this.element, {
144144
...options,
145+
...options.extra,
145146
center: center === null ? undefined : center,
146147
zoom: zoom === null ? undefined : zoom,
147148
});

src/Map/src/Bridge/Leaflet/assets/src/map_controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020

2121
type MapOptions = Pick<LeafletMapOptions, 'center' | 'zoom'> & {
2222
tileLayer: { url: string; attribution: string; options: Record<string, unknown> } | false;
23+
extra?: Record<string, unknown>;
2324
};
2425

2526
export default class extends AbstractMapController<
@@ -77,6 +78,7 @@ export default class extends AbstractMapController<
7778
}: { center: Point | null; zoom: number | null; options: MapOptions }): L.Map {
7879
const map = L.map(this.element, {
7980
...options,
81+
...options.extra,
8082
center: center === null ? undefined : center,
8183
zoom: zoom === null ? undefined : zoom,
8284
});

src/Map/src/Bridge/Leaflet/src/LeafletOptions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function __construct(
2424
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
2525
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
2626
),
27+
private array $extra = [],
2728
) {
2829
}
2930

@@ -34,13 +35,21 @@ public function tileLayer(TileLayer|false $tileLayer): self
3435
return $this;
3536
}
3637

38+
public function extra(array $extra): self
39+
{
40+
$this->extra = $extra;
41+
42+
return $this;
43+
}
44+
3745
/**
3846
* @internal
3947
*/
4048
public static function fromArray(array $array): MapOptionsInterface
4149
{
4250
return new self(
4351
tileLayer: $array['tileLayer'] ? TileLayer::fromArray($array['tileLayer']) : false,
52+
extra: $array['extra'] ?? []
4453
);
4554
}
4655

@@ -51,6 +60,7 @@ public function toArray(): array
5160
{
5261
return [
5362
'tileLayer' => $this->tileLayer ? $this->tileLayer->toArray() : false,
63+
'extra' => $this->extra,
5464
];
5565
}
5666
}

0 commit comments

Comments
 (0)