Skip to content

Commit 8aba6ab

Browse files
committed
add polyline support
1 parent 6fa0f4f commit 8aba6ab

File tree

7 files changed

+50
-8
lines changed

7 files changed

+50
-8
lines changed

src/Map/assets/src/abstract_map_controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export type InfoWindowDefinition<InfoWindowOptions> = {
6565
extra: Record<string, unknown>;
6666
};
6767

68-
export default abstract class<
68+
export default abstract class <
6969
MapOptions,
7070
Map,
7171
MarkerOptions,
@@ -180,9 +180,9 @@ export default abstract class<
180180
element,
181181
}:
182182
| {
183-
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
184-
element: Marker;
185-
}
183+
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
184+
element: Marker;
185+
}
186186
| {
187187
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
188188
element: Polygon;

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class default_1 extends default_1$1 {
120120
const { points, title, infoWindow, rawOptions = {} } = definition;
121121
const polygon = new _google.maps.Polygon({
122122
...rawOptions,
123-
paths: points,
123+
path: points,
124124
map: this.map,
125125
});
126126
if (title) {
@@ -182,6 +182,23 @@ class default_1 extends default_1$1 {
182182
infoWindow.open({ map: this.map, anchor: element });
183183
}
184184
}
185+
else if (element instanceof google.maps.Polyline) {
186+
element.addListener('click', (event) => {
187+
if (definition.autoClose) {
188+
this.closeInfoWindowsExcept(infoWindow);
189+
}
190+
infoWindow.setPosition(event.latLng);
191+
infoWindow.open(this.map);
192+
});
193+
if (definition.opened) {
194+
const bounds = new google.maps.LatLngBounds();
195+
element.getPath().forEach((point) => {
196+
bounds.extend(point);
197+
});
198+
infoWindow.setPosition(bounds.getCenter());
199+
infoWindow.open({ map: this.map, anchor: element });
200+
}
201+
}
185202
return infoWindow;
186203
}
187204
createTextOrElement(content) {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ export default class extends AbstractMapController<
219219
infoWindow.open(this.map);
220220
});
221221

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) {
231+
element.addListener('click', (event: any) => {
232+
if (definition.autoClose) {
233+
this.closeInfoWindowsExcept(infoWindow);
234+
}
235+
infoWindow.setPosition(event.latLng);
236+
infoWindow.open(this.map);
237+
});
238+
222239
if (definition.opened) {
223240
const bounds = new google.maps.LatLngBounds();
224241
element.getPath().forEach((point: google.maps.LatLng) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ export default class extends AbstractMapController<MapOptions, typeof L.Map, Mar
2727
}): L.Popup;
2828
protected doFitBoundsToMarkers(): void;
2929
}
30-
export {};
30+
export { };

src/Map/src/Map.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ public function addPolygon(Polygon $polygon): self
9999

100100
return $this;
101101
}
102+
public function addPolyline(Polyline $polyline): self
103+
{
104+
$this->polylines[] = $polyline;
105+
106+
return $this;
107+
}
102108

103109
public function addPolyline(Polyline $polyline): self
104110
{

src/Map/src/Twig/MapRuntime.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public function renderMap(
6464
foreach ($polylines ?? [] as $polyline) {
6565
$map->addPolyline(Polyline::fromArray($polyline));
6666
}
67+
foreach ($polylines ?? [] as $polylines) {
68+
$map->addPolyline(Polyline::fromArray($polylines));
69+
}
6770
if (null !== $center) {
6871
$map->center(Point::fromArray($center));
6972
}

src/Map/src/Twig/UXMapComponent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\UX\Map\Twig;
1313

14-
use Symfony\UX\Map\Marker;
1514
use Symfony\UX\Map\Point;
15+
use Symfony\UX\Map\Marker;
1616
use Symfony\UX\Map\Polygon;
1717
use Symfony\UX\Map\Polyline;
1818

@@ -36,7 +36,6 @@ final class UXMapComponent
3636
* @var Polygon[]
3737
*/
3838
public array $polygons;
39-
4039
/**
4140
* @var Polyline[]
4241
*/

0 commit comments

Comments
 (0)