Skip to content

Commit fe81fc5

Browse files
committed
fix lint and tests
1 parent 8e458ce commit fe81fc5

File tree

14 files changed

+93
-157
lines changed

14 files changed

+93
-157
lines changed

src/Map/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
- Add method `Symfony\UX\Map\Renderer\AbstractRenderer::tapOptions()`, to allow Renderer to modify options before rendering a Map.
66
- Add `ux_map.google_maps.default_map_id` configuration to set the Google ``Map ID``
77

8+
## 2.22
9+
10+
- Add `Polyline` support
11+
812
## 2.20
913

1014
- Deprecate `render_map` Twig function (will be removed in 2.21). Use
@@ -15,7 +19,6 @@
1519
- The importmap entry `@symfony/ux-map/abstract-map-controller` can be removed
1620
from your importmap, it is no longer needed.
1721
- Add `Polygon` support
18-
- Add `Polyline` support
1922

2023
## 2.19
2124

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,17 @@ export default abstract class<MapOptions, Map, MarkerOptions, Marker, InfoWindow
6565
protected abstract doCreateMarker(definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>): Marker;
6666
protected abstract doCreatePolygon(definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>): Polygon;
6767
protected abstract doCreatePolyline(definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>): Polyline;
68-
protected createInfoWindow({ definition, element, }: {
69-
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'] | PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'] | PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
70-
element: Marker | Polygon | Polyline;
68+
protected abstract createInfoWindow(args: {
69+
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
70+
element: Marker;
71+
} | {
72+
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
73+
element: Polygon;
74+
} | {
75+
definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
76+
element: Polyline;
7177
}): InfoWindow;
72-
protected abstract doCreateInfoWindow({ definition, element, }: {
78+
protected abstract doCreateInfoWindow(args: {
7379
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
7480
element: Marker;
7581
} | {

src/Map/assets/dist/abstract_map_controller.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class default_1 extends Controller {
99
this.polylines = [];
1010
}
1111
connect() {
12-
const { center, zoom, options, markers, polygons, fitBoundsToMarkers } = this.viewValue;
12+
const { center, zoom, options, markers, polygons, polylines, fitBoundsToMarkers } = this.viewValue;
1313
this.dispatchEvent('pre-connect', { options });
1414
this.map = this.doCreateMap({ center, zoom, options });
1515
markers.forEach((marker) => this.createMarker(marker));
@@ -47,7 +47,8 @@ class default_1 extends Controller {
4747
this.polylines.push(polyline);
4848
return polyline;
4949
}
50-
createInfoWindow({ definition, element, }) {
50+
createInfoWindow(args) {
51+
const { definition, element } = args;
5152
this.dispatchEvent('info-window:before-create', { definition, element });
5253
const infoWindow = this.doCreateInfoWindow({ definition, element });
5354
this.dispatchEvent('info-window:after-create', { infoWindow, element });

src/Map/assets/src/abstract_map_controller.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default abstract class<
9191
protected polylines: Array<Polyline> = [];
9292

9393
connect() {
94-
const { center, zoom, options, markers, polygons, fitBoundsToMarkers } = this.viewValue;
94+
const { center, zoom, options, markers, polygons, polylines, fitBoundsToMarkers } = this.viewValue;
9595

9696
this.dispatchEvent('pre-connect', { options });
9797

@@ -156,16 +156,22 @@ export default abstract class<
156156
protected abstract doCreatePolygon(definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>): Polygon;
157157
protected abstract doCreatePolyline(definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>): Polyline;
158158

159-
protected createInfoWindow({
160-
definition,
161-
element,
162-
}: {
163-
definition:
164-
| MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow']
165-
| PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow']
166-
| PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
167-
element: Marker | Polygon | Polyline;
168-
}): InfoWindow {
159+
protected abstract createInfoWindow(
160+
args:
161+
| {
162+
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
163+
element: Marker;
164+
}
165+
| {
166+
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
167+
element: Polygon;
168+
}
169+
| {
170+
definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
171+
element: Polyline;
172+
}
173+
): InfoWindow {
174+
const { definition, element } = args;
169175
this.dispatchEvent('info-window:before-create', { definition, element });
170176
const infoWindow = this.doCreateInfoWindow({ definition, element });
171177
this.dispatchEvent('info-window:after-create', { infoWindow, element });
@@ -175,22 +181,21 @@ export default abstract class<
175181
return infoWindow;
176182
}
177183

178-
protected abstract doCreateInfoWindow({
179-
definition,
180-
element,
181-
}:
182-
| {
183-
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
184-
element: Marker;
185-
}
186-
| {
187-
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
188-
element: Polygon;
189-
}
190-
| {
191-
definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
192-
element: Polyline;
193-
}): InfoWindow;
184+
protected abstract doCreateInfoWindow(
185+
args:
186+
| {
187+
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
188+
element: Marker;
189+
}
190+
| {
191+
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
192+
element: Polygon;
193+
}
194+
| {
195+
definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
196+
element: Polyline;
197+
}
198+
): InfoWindow;
194199

195200
protected abstract doFitBoundsToMarkers(): void;
196201

src/Map/doc/index.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,39 +136,41 @@ You can add markers to a map using the ``addMarker()`` method::
136136
))
137137
;
138138

139-
Add Polylines
140-
~~~~~~~~~~~~~
141139

142-
You can add Polylines, which represents a path made by a series of `Point` instances
143-
$myMap->addPolyline(new Polyline(
140+
Add Polygons
141+
~~~~~~~~~~~~
142+
143+
You can also add Polygons, which represents an area enclosed by a series of ``Point`` instances::
144+
145+
$myMap->addPolygon(new Polygon(
144146
points: [
145147
new Point(48.8566, 2.3522),
146148
new Point(45.7640, 4.8357),
147149
new Point(43.2965, 5.3698),
148150
new Point(44.8378, -0.5792),
149151
],
150152
infoWindow: new InfoWindow(
151-
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
153+
content: 'Paris, Lyon, Marseille, Bordeaux',
152154
),
153155
));
154156

155-
Add Polygons
156-
~~~~~~~~~~~~
157-
158-
You can also add Polygons, which represents an area enclosed by a series of ``Point`` instances::
157+
Add Polylines
158+
~~~~~~~~~~~~~
159159

160-
$myMap->addPolygon(new Polygon(
160+
You can add Polylines, which represents a path made by a series of `Point` instances
161+
$myMap->addPolyline(new Polyline(
161162
points: [
162163
new Point(48.8566, 2.3522),
163164
new Point(45.7640, 4.8357),
164165
new Point(43.2965, 5.3698),
165166
new Point(44.8378, -0.5792),
166167
],
167168
infoWindow: new InfoWindow(
168-
content: 'Paris, Lyon, Marseille, Bordeaux',
169+
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
169170
),
170171
));
171172

173+
172174
Render a map
173175
------------
174176

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let default_1$1 = class default_1 extends Controller {
1010
this.polylines = [];
1111
}
1212
connect() {
13-
const { center, zoom, options, markers, polygons, fitBoundsToMarkers } = this.viewValue;
13+
const { center, zoom, options, markers, polygons, polylines, fitBoundsToMarkers } = this.viewValue;
1414
this.dispatchEvent('pre-connect', { options });
1515
this.map = this.doCreateMap({ center, zoom, options });
1616
markers.forEach((marker) => this.createMarker(marker));
@@ -48,7 +48,8 @@ let default_1$1 = class default_1 extends Controller {
4848
this.polylines.push(polyline);
4949
return polyline;
5050
}
51-
createInfoWindow({ definition, element, }) {
51+
createInfoWindow(args) {
52+
const { definition, element } = args;
5253
this.dispatchEvent('info-window:before-create', { definition, element });
5354
const infoWindow = this.doCreateInfoWindow({ definition, element });
5455
this.dispatchEvent('info-window:after-create', { infoWindow, element });
@@ -165,24 +166,7 @@ class default_1 extends default_1$1 {
165166
infoWindow.open({ map: this.map, anchor: element });
166167
}
167168
}
168-
else if (element instanceof google.maps.Polygon) {
169-
element.addListener('click', (event) => {
170-
if (definition.autoClose) {
171-
this.closeInfoWindowsExcept(infoWindow);
172-
}
173-
infoWindow.setPosition(event.latLng);
174-
infoWindow.open(this.map);
175-
});
176-
if (definition.opened) {
177-
const bounds = new google.maps.LatLngBounds();
178-
element.getPath().forEach((point) => {
179-
bounds.extend(point);
180-
});
181-
infoWindow.setPosition(bounds.getCenter());
182-
infoWindow.open({ map: this.map, anchor: element });
183-
}
184-
}
185-
else if (element instanceof google.maps.Polyline) {
169+
else if (element instanceof google.maps.Polygon || element instanceof google.maps.Polyline) {
186170
element.addListener('click', (event) => {
187171
if (definition.autoClose) {
188172
this.closeInfoWindowsExcept(infoWindow);

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,24 +210,7 @@ export default class extends AbstractMapController<
210210
if (definition.opened) {
211211
infoWindow.open({ map: this.map, anchor: element });
212212
}
213-
} else if (element instanceof google.maps.Polygon) {
214-
element.addListener('click', (event: any) => {
215-
if (definition.autoClose) {
216-
this.closeInfoWindowsExcept(infoWindow);
217-
}
218-
infoWindow.setPosition(event.latLng);
219-
infoWindow.open(this.map);
220-
});
221-
222-
if (definition.opened) {
223-
const bounds = new google.maps.LatLngBounds();
224-
element.getPath().forEach((point: google.maps.LatLng) => {
225-
bounds.extend(point);
226-
});
227-
infoWindow.setPosition(bounds.getCenter());
228-
infoWindow.open({ map: this.map, anchor: element });
229-
}
230-
} else if (element instanceof google.maps.Polyline) {
213+
} else if (element instanceof google.maps.Polygon || element instanceof google.maps.Polyline) {
231214
element.addListener('click', (event: any) => {
232215
if (definition.autoClose) {
233216
this.closeInfoWindowsExcept(infoWindow);

0 commit comments

Comments
 (0)