Skip to content

Commit 523c591

Browse files
committed
feature #2860 [Map] Deprecate property rawOptions from ux:map:*:before-create events, in favor of bridgeOptions (Kocal)
This PR was merged into the 2.x branch. Discussion ---------- [Map] Deprecate property `rawOptions` from `ux:map:*:before-create` events, in favor of `bridgeOptions` | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | yes <!-- required for new features --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Following #2859, the `rawOptions` does not really reflect its purpose, I find `bridgeOptions` much better. With the follwing code: ```js this.element.addEventListener("ux:map:marker:before-create", (event) => { event.detail.definition.rawOptions = { opacity: 0.5}; event.detail.definition.bridgeOptions = { title: 'Paris!!'}; }); ``` Both options are used, but a deprecation warning is nicely trigged: <img width="1369" alt="image" src="https://github.com/user-attachments/assets/89ff93df-fca8-4a44-b9b3-21e9c245c96c" /> Commits ------- 9158b93 [Map] Deprecate property `rawOptions` from `ux:map:*:before-create` events, in favor of `bridgeOptions`
2 parents a14e6af + 9158b93 commit 523c591

File tree

13 files changed

+225
-106
lines changed

13 files changed

+225
-106
lines changed

src/Map/CHANGELOG.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
# CHANGELOG
22

3-
## 2.29
4-
5-
- Add support for creating `Rectangle` by passing two `Point` instances to the `Rectangle` constructor, e.g.:
6-
```php
7-
$map->addRectangle(new Rectangle(
8-
southWest: new Point(48.856613, 2.352222), // Paris
9-
northEast: new Point(48.51238 2.21080) // Gare de Lyon (Paris)
10-
));
11-
```
3+
## 2.27
124

13-
## 2.28
5+
- The `fitBoundsToMarkers` option is not overridden anymore when using the `Map` LiveComponent, but now respects the value you defined.
6+
You may encounter unwanted behavior when adding/removing elements to the map.
7+
To use the previous behavior, you must call `$this->getMap()->fitBoundsToMarkers(false)` in your LiveComponent's live actions
148

159
- Add support for creating `Circle` by passing a `Point` and a radius (in meters) to the `Circle` constructor, e.g.:
1610
```php
@@ -19,11 +13,16 @@ $map->addCircle(new Circle(
1913
radius: 5_000 // 5km
2014
));
2115
```
22-
## 2.27
2316

24-
- The `fitBoundsToMarkers` option is not overridden anymore when using the `Map` LiveComponent, but now respects the value you defined.
25-
You may encounter unwanted behavior when adding/removing elements to the map.
26-
To use the previous behavior, you must call `$this->getMap()->fitBoundsToMarkers(false)` in your LiveComponent's live actions
17+
- Add support for creating `Rectangle` by passing two `Point` instances to the `Rectangle` constructor, e.g.:
18+
```php
19+
$map->addRectangle(new Rectangle(
20+
southWest: new Point(48.856613, 2.352222), // Paris
21+
northEast: new Point(48.51238 2.21080) // Gare de Lyon (Paris)
22+
));
23+
```
24+
25+
- Deprecate property `rawOptions` from `ux:map:*:before-create` events, in favor of `bridgeOptions` instead.
2726

2827
## 2.26
2928

src/Map/assets/dist/abstract_map_controller.d.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,41 @@ export type MarkerDefinition<BridgeMarkerOptions, BridgeInfoWindowOptions> = Wit
3232
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
3333
icon?: Icon;
3434
rawOptions?: BridgeMarkerOptions;
35+
bridgeOptions?: BridgeMarkerOptions;
3536
extra: Record<string, unknown>;
3637
}>;
37-
export type PolygonDefinition<PolygonOptions, BridgeInfoWindowOptions> = WithIdentifier<{
38+
export type PolygonDefinition<BridgePolygonOptions, BridgeInfoWindowOptions> = WithIdentifier<{
3839
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
3940
points: Array<Point> | Array<Array<Point>>;
4041
title: string | null;
41-
rawOptions?: PolygonOptions;
42+
rawOptions?: BridgePolygonOptions;
43+
bridgeOptions?: BridgePolygonOptions;
4244
extra: Record<string, unknown>;
4345
}>;
44-
export type PolylineDefinition<PolylineOptions, BridgeInfoWindowOptions> = WithIdentifier<{
46+
export type PolylineDefinition<BridgePolylineOptions, BridgeInfoWindowOptions> = WithIdentifier<{
4547
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
4648
points: Array<Point>;
4749
title: string | null;
48-
rawOptions?: PolylineOptions;
50+
rawOptions?: BridgePolylineOptions;
51+
bridgeOptions?: BridgePolylineOptions;
4952
extra: Record<string, unknown>;
5053
}>;
51-
export type CircleDefinition<CircleOptions, BridgeInfoWindowOptions> = WithIdentifier<{
54+
export type CircleDefinition<BridgeCircleOptions, BridgeInfoWindowOptions> = WithIdentifier<{
5255
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
5356
center: Point;
5457
radius: number;
5558
title: string | null;
56-
rawOptions?: CircleOptions;
59+
rawOptions?: BridgeCircleOptions;
60+
bridgeOptions?: BridgeCircleOptions;
5761
extra: Record<string, unknown>;
5862
}>;
59-
export type RectangleDefinition<RectangleOptions, BridgeInfoWindowOptions> = WithIdentifier<{
63+
export type RectangleDefinition<BridgeRectangleOptions, BridgeInfoWindowOptions> = WithIdentifier<{
6064
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
6165
southWest: Point;
6266
northEast: Point;
6367
title: string | null;
64-
rawOptions?: RectangleOptions;
68+
rawOptions?: BridgeRectangleOptions;
69+
bridgeOptions?: BridgeRectangleOptions;
6570
extra: Record<string, unknown>;
6671
}>;
6772
export type InfoWindowDefinition<BridgeInfoWindowOptions> = {
@@ -71,6 +76,7 @@ export type InfoWindowDefinition<BridgeInfoWindowOptions> = {
7176
opened: boolean;
7277
autoClose: boolean;
7378
rawOptions?: BridgeInfoWindowOptions;
79+
bridgeOptions?: BridgeInfoWindowOptions;
7480
extra: Record<string, unknown>;
7581
};
7682
export default abstract class<MapOptions, BridgeMap, BridgeMarkerOptions, BridgeMarker, BridgeInfoWindowOptions, BridgeInfoWindow, BridgePolygonOptions, BridgePolygon, BridgePolylineOptions, BridgePolyline, BridgeCircleOptions, BridgeCircle, BridgeRectangleOptions, BridgeRectangle> extends Controller<HTMLElement> {

src/Map/assets/dist/abstract_map_controller.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class default_1 extends Controller {
9393
const eventAfter = `${type}:after-create`;
9494
return ({ definition }) => {
9595
this.dispatchEvent(eventBefore, { definition });
96+
if (typeof definition.rawOptions !== 'undefined') {
97+
console.warn(`[Symfony UX Map] The event "${eventBefore}" added a deprecated "rawOptions" property to the definition, it will be removed in a next major version, replace it with "bridgeOptions" instead.`, definition);
98+
}
9699
const drawing = factory({ definition });
97100
this.dispatchEvent(eventAfter, { [type]: drawing, definition });
98101
draws.set(definition['@id'], drawing);

src/Map/assets/src/abstract_map_controller.ts

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ export type MarkerDefinition<BridgeMarkerOptions, BridgeInfoWindowOptions> = Wit
4343
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
4444
icon?: Icon;
4545
/**
46+
* @deprecated Use "bridgeOptions" instead.
4647
* Raw options passed to the marker constructor, specific to the map provider (e.g.: `L.marker()` for Leaflet).
4748
*/
4849
rawOptions?: BridgeMarkerOptions;
50+
/**
51+
* Additional options passed to the Marker constructor.
52+
* These options are specific to the Map Bridge, and can be defined through `ux:map:marker:before-create` event.
53+
*/
54+
bridgeOptions?: BridgeMarkerOptions;
4955
/**
5056
* Extra data defined by the developer.
5157
* They are not directly used by the Stimulus controller, but they can be used by the developer with event listeners:
@@ -55,14 +61,20 @@ export type MarkerDefinition<BridgeMarkerOptions, BridgeInfoWindowOptions> = Wit
5561
extra: Record<string, unknown>;
5662
}>;
5763

58-
export type PolygonDefinition<PolygonOptions, BridgeInfoWindowOptions> = WithIdentifier<{
64+
export type PolygonDefinition<BridgePolygonOptions, BridgeInfoWindowOptions> = WithIdentifier<{
5965
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
6066
points: Array<Point> | Array<Array<Point>>;
6167
title: string | null;
6268
/**
63-
* Raw options passed to the marker constructor, specific to the map provider (e.g.: `L.marker()` for Leaflet).
69+
* @deprecated Use "bridgeOptions" instead.
70+
* Raw options passed to the polygon constructor, specific to the map provider (e.g.: `L.polygon()` for Leaflet).
71+
*/
72+
rawOptions?: BridgePolygonOptions;
73+
/**
74+
* Additional options passed to the Polygon constructor.
75+
* These options are specific to the Map Bridge, and can be defined through `ux:map:polygon:before-create` event.
6476
*/
65-
rawOptions?: PolygonOptions;
77+
bridgeOptions?: BridgePolygonOptions;
6678
/**
6779
* Extra data defined by the developer.
6880
* They are not directly used by the Stimulus controller, but they can be used by the developer with event listeners:
@@ -72,14 +84,20 @@ export type PolygonDefinition<PolygonOptions, BridgeInfoWindowOptions> = WithIde
7284
extra: Record<string, unknown>;
7385
}>;
7486

75-
export type PolylineDefinition<PolylineOptions, BridgeInfoWindowOptions> = WithIdentifier<{
87+
export type PolylineDefinition<BridgePolylineOptions, BridgeInfoWindowOptions> = WithIdentifier<{
7688
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
7789
points: Array<Point>;
7890
title: string | null;
7991
/**
80-
* Raw options passed to the marker constructor, specific to the map provider (e.g.: `L.marker()` for Leaflet).
92+
* @deprecated Use "bridgeOptions" instead.
93+
* Raw options passed to the polyline constructor, specific to the map provider (e.g.: `L.polyline()` for Leaflet).
94+
*/
95+
rawOptions?: BridgePolylineOptions;
96+
/**
97+
* Additional options passed to the Polyline constructor.
98+
* These options are specific to the Map Bridge, and can be defined through `ux:map:polyline:before-create` event.
8199
*/
82-
rawOptions?: PolylineOptions;
100+
bridgeOptions?: BridgePolylineOptions;
83101
/**
84102
* Extra data defined by the developer.
85103
* They are not directly used by the Stimulus controller, but they can be used by the developer with event listeners:
@@ -89,15 +107,21 @@ export type PolylineDefinition<PolylineOptions, BridgeInfoWindowOptions> = WithI
89107
extra: Record<string, unknown>;
90108
}>;
91109

92-
export type CircleDefinition<CircleOptions, BridgeInfoWindowOptions> = WithIdentifier<{
110+
export type CircleDefinition<BridgeCircleOptions, BridgeInfoWindowOptions> = WithIdentifier<{
93111
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
94112
center: Point;
95113
radius: number;
96114
title: string | null;
97115
/**
116+
* @deprecated Use "bridgeOptions" instead.
98117
* Raw options passed to the circle constructor, specific to the map provider (e.g.: `L.circle()` for Leaflet).
99118
*/
100-
rawOptions?: CircleOptions;
119+
rawOptions?: BridgeCircleOptions;
120+
/**
121+
* Additional options passed to the Circle constructor.
122+
* These options are specific to the Map Bridge, and can be defined through `ux:map:circle:before-create` event.
123+
*/
124+
bridgeOptions?: BridgeCircleOptions;
101125
/**
102126
* Extra data defined by the developer.
103127
* They are not directly used by the Stimulus controller, but they can be used by the developer with event listeners:
@@ -107,15 +131,21 @@ export type CircleDefinition<CircleOptions, BridgeInfoWindowOptions> = WithIdent
107131
extra: Record<string, unknown>;
108132
}>;
109133

110-
export type RectangleDefinition<RectangleOptions, BridgeInfoWindowOptions> = WithIdentifier<{
134+
export type RectangleDefinition<BridgeRectangleOptions, BridgeInfoWindowOptions> = WithIdentifier<{
111135
infoWindow?: Omit<InfoWindowDefinition<BridgeInfoWindowOptions>, 'position'>;
112136
southWest: Point;
113137
northEast: Point;
114138
title: string | null;
115139
/**
140+
* @deprecated Use "bridgeOptions" instead.
116141
* Raw options passed to the rectangle constructor, specific to the map provider (e.g.: `L.rectangle()` for Leaflet).
117142
*/
118-
rawOptions?: RectangleOptions;
143+
rawOptions?: BridgeRectangleOptions;
144+
/**
145+
* Additional options passed to the Rectangle constructor.
146+
* These options are specific to the Map Bridge, and can be defined through `ux:map:rectangle:before-create` event.
147+
*/
148+
bridgeOptions?: BridgeRectangleOptions;
119149
/**
120150
* Extra data defined by the developer.
121151
* They are not directly used by the Stimulus controller, but they can be used by the developer with event listeners:
@@ -132,10 +162,15 @@ export type InfoWindowDefinition<BridgeInfoWindowOptions> = {
132162
opened: boolean;
133163
autoClose: boolean;
134164
/**
135-
* Raw options passed to the info window constructor,
136-
* specific to the map provider (e.g.: `google.maps.InfoWindow()` for Google Maps).
165+
* @deprecated Use "bridgeOptions" instead.
166+
* Raw options passed to the info window constructor, specific to the map provider (e.g.: `google.maps.InfoWindow()` for Google Maps).
137167
*/
138168
rawOptions?: BridgeInfoWindowOptions;
169+
/**
170+
* Additional options passed to the InfoWindow constructor.
171+
* These options are specific to the Map Bridge, and can be defined through `ux:map:info-window:before-create` event.
172+
*/
173+
bridgeOptions?: BridgeInfoWindowOptions;
139174
/**
140175
* Extra data defined by the developer.
141176
* They are not directly used by the Stimulus controller, but they can be used by the developer with event listeners:
@@ -378,6 +413,14 @@ export default abstract class<
378413
// 'Factory' could be instantiated with an arbitrary type which could be unrelated to '({ definition }: { definition: WithIdentifier<any>; }) => Draw'
379414
return ({ definition }: { definition: WithIdentifier<any> }) => {
380415
this.dispatchEvent(eventBefore, { definition });
416+
417+
if (typeof definition.rawOptions !== 'undefined') {
418+
console.warn(
419+
`[Symfony UX Map] The event "${eventBefore}" added a deprecated "rawOptions" property to the definition, it will be removed in a next major version, replace it with "bridgeOptions" instead.`,
420+
definition
421+
);
422+
}
423+
381424
const drawing = factory({ definition }) as Draw;
382425
this.dispatchEvent(eventAfter, { [type]: drawing, definition });
383426

src/Map/doc/index.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,13 @@ maps and their elements. However, you might occasionally find this
501501
abstraction limiting and need to configure low-level options directly.
502502

503503
Fortunately, you can customize these low-level options through the UX Map
504-
events ``ux:map:*:before-create`` using the special ``rawOptions`` property:
504+
events ``ux:map:*:before-create`` using the special ``bridgeOptions`` property:
505+
506+
.. deprecated:: 2.27
507+
508+
The ``rawOptions`` property was deprecated in UX Map 2.27, and will be removed in 3.0.
509+
Use ``bridgeOptions`` instead, which better reflect the purpose of these options (options that are
510+
specific to the renderer bridge).
505511

506512
.. code-block:: javascript
507513
@@ -519,55 +525,55 @@ events ``ux:map:*:before-create`` using the special ``rawOptions`` property:
519525
520526
_onMarkerBeforeCreate(event) {
521527
// When using Google Maps, to configure a `google.maps.AdvancedMarkerElement`
522-
event.detail.definition.rawOptions = {
528+
event.detail.definition.bridgeOptions = {
523529
gmpDraggable: true,
524530
// ...
525531
};
526532
527533
// When using Leaflet, to configure a `L.Marker` instance
528-
event.detail.definition.rawOptions = {
534+
event.detail.definition.bridgeOptions = {
529535
riseOnHover: true,
530536
// ...
531537
};
532538
}
533539
534540
_onInfoWindowBeforeCreate(event) {
535541
// When using Google Maps, to configure a `google.maps.InfoWindow` instance
536-
event.detail.definition.rawOptions = {
542+
event.detail.definition.bridgeOptions = {
537543
maxWidth: 200,
538544
// ...
539545
};
540546
541547
// When using Leaflet, to configure a `L.Popup` instance
542-
event.detail.definition.rawOptions = {
548+
event.detail.definition.bridgeOptions = {
543549
direction: 'left',
544550
// ...
545551
};
546552
}
547553
548554
_onPolygonBeforeCreate(event) {
549555
// When using Google Maps, to configure a `google.maps.Polygon`
550-
event.detail.definition.rawOptions = {
556+
event.detail.definition.bridgeOptions = {
551557
strokeColor: 'red',
552558
// ...
553559
};
554560
555561
// When using Leaflet, to configure a `L.Polygon`
556-
event.detail.definition.rawOptions = {
562+
event.detail.definition.bridgeOptions = {
557563
color: 'red',
558564
// ...
559565
};
560566
}
561567
562568
_onPolylineBeforeCreate(event) {
563569
// When using Google Maps, to configure a `google.maps.Polyline`
564-
event.detail.definition.rawOptions = {
570+
event.detail.definition.bridgeOptions = {
565571
strokeColor: 'red',
566572
// ...
567573
};
568574
569575
// When using Leaflet, to configure a `L.Polyline`
570-
event.detail.definition.rawOptions = {
576+
event.detail.definition.bridgeOptions = {
571577
color: 'red',
572578
// ...
573579
};

src/Map/src/Bridge/Google/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
const bounds = new google.maps.LatLngBounds();
1717

1818
element.getPath().forEach((latLng) => bounds.extend(latLng));
19-
definition.infoWindow.rawOptions.position = bounds.getCenter();
19+
definition.infoWindow.bridgeOptions.position = bounds.getCenter();
2020
}
2121
});
2222
```

src/Map/src/Bridge/Google/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ $map = (new Map())
6969
$googleOptions = (new GoogleOptions())
7070
// You can skip this option if you configure "ux_map.google_maps.default_map_id"
7171
// in your "config/packages/ux_map.yaml".
72-
->mapId('YOUR_MAP_ID')
73-
72+
->mapId('YOUR_MAP_ID')
73+
7474
->gestureHandling(GestureHandling::GREEDY)
7575
->backgroundColor('#f00')
7676
->doubleClickZoom(true)
@@ -133,24 +133,24 @@ export default class extends Controller
133133

134134
_onMarkerBeforeCreate(event) {
135135
// You can access the marker definition and the google object
136-
// Note: `definition.rawOptions` is the raw options object that will be passed to the `google.maps.Marker` constructor.
136+
// Note: `definition.bridgeOptions` is the raw options object that will be passed to the `google.maps.Marker` constructor.
137137
const { definition, google } = event.detail;
138138

139-
// 1. To use a custom image for the marker
139+
// 1. To use a custom image for the marker
140140
const beachFlagImg = document.createElement("img");
141141
// Note: instead of using a hardcoded URL, you can use the `extra` parameter from `new Marker()` (PHP) and access it here with `definition.extra`.
142142
beachFlagImg.src = "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png";
143-
definition.rawOptions = {
143+
definition.bridgeOptions = {
144144
content: beachFlagImg
145145
}
146-
146+
147147
// 2. To use a custom glyph for the marker
148148
const pinElement = new google.maps.marker.PinElement({
149-
// Note: instead of using a hardcoded URL, you can use the `extra` parameter from `new Marker()` (PHP) and access it here with `definition.extra`.
150-
glyph: new URL('https://maps.gstatic.com/mapfiles/place_api/icons/v2/museum_pinlet.svg'),
149+
// Note: instead of using a hardcoded URL, you can use the `extra` parameter from `new Marker()` (PHP) and access it here with `definition.extra`.
150+
glyph: new URL('https://maps.gstatic.com/mapfiles/place_api/icons/v2/museum_pinlet.svg'),
151151
glyphColor: "white",
152152
});
153-
definition.rawOptions = {
153+
definition.bridgeOptions = {
154154
content: pinElement.element,
155155
}
156156
}

0 commit comments

Comments
 (0)