Skip to content

Commit 23e5928

Browse files
committed
fix lint and tests
1 parent 67befe6 commit 23e5928

File tree

14 files changed

+94
-157
lines changed

14 files changed

+94
-157
lines changed

src/Map/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 2.22
4+
5+
- Add `Polyline` support
6+
37
## 2.20
48

59
- Deprecate `render_map` Twig function (will be removed in 2.21). Use
@@ -10,7 +14,6 @@
1014
- The importmap entry `@symfony/ux-map/abstract-map-controller` can be removed
1115
from your importmap, it is no longer needed.
1216
- Add `Polygon` support
13-
- Add `Polyline` support
1417

1518
## 2.19
1619

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: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,40 +130,43 @@ You can add markers to a map using the ``addMarker()`` method::
130130
)
131131
;
132132

133-
Add Polylines
134-
~~~~~~~~~~~~~
135133

136-
You can add Polylines, which represents a path made by a series of `Point` instances
137-
$myMap->addPolyline(new Polyline(
134+
Add Polygons
135+
~~~~~~~~~~~~
136+
137+
You can also add Polygons, which represents an area enclosed by a series of ``Point`` instances::
138+
139+
$myMap->addPolygon(new Polygon(
138140
points: [
139141
new Point(48.8566, 2.3522),
140142
new Point(45.7640, 4.8357),
141143
new Point(43.2965, 5.3698),
142144
new Point(44.8378, -0.5792),
143145
],
144146
infoWindow: new InfoWindow(
145-
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
147+
content: 'Paris, Lyon, Marseille, Bordeaux',
146148
),
147149
));
148150

149-
Add Polygons
150-
~~~~~~~~~~~~
151-
152-
You can also add Polygons, which represents an area enclosed by a series of ``Point`` instances::
151+
Add Polylines
152+
~~~~~~~~~~~~~
153153

154-
$myMap->addPolygon(new Polygon(
154+
You can add Polylines, which represents a path made by a series of `Point` instances
155+
$myMap->addPolyline(new Polyline(
155156
points: [
156157
new Point(48.8566, 2.3522),
157158
new Point(45.7640, 4.8357),
158159
new Point(43.2965, 5.3698),
159160
new Point(44.8378, -0.5792),
160161
],
161162
infoWindow: new InfoWindow(
162-
content: 'Paris, Lyon, Marseille, Bordeaux',
163+
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
163164
),
164165
));
165166

167+
166168
Render a map
169+
------------
167170

168171
To render a map in your Twig template, use the ``ux_map`` Twig function, e.g.:
169172

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)