Skip to content

Commit 5031c9e

Browse files
committed
removed rawOptions from Polygon.php
adding auto opened info window for google polygons remove latLngs conversion from points
1 parent 6567339 commit 5031c9e

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ class default_1 extends AbstractMapController {
5858
}
5959
doCreatePolygon(definition) {
6060
const { points, title, infoWindow, rawOptions = {}, extra } = definition;
61-
const latLngs = points.map((point) => ({ lat: point.lat, lng: point.lng }));
6261
const polygon = new _google.maps.Polygon({
6362
...rawOptions,
64-
paths: latLngs,
63+
paths: points,
6564
map: this.map,
6665
});
6766
if (title) {
@@ -97,6 +96,14 @@ class default_1 extends AbstractMapController {
9796
infoWindow.setPosition(event.latLng);
9897
infoWindow.open(this.map);
9998
});
99+
if (definition.opened) {
100+
const bounds = new google.maps.LatLngBounds();
101+
element.getPath().forEach((point) => {
102+
bounds.extend(point);
103+
});
104+
infoWindow.setPosition(bounds.getCenter());
105+
infoWindow.open({ map: this.map, anchor: element });
106+
}
100107
}
101108
return infoWindow;
102109
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,9 @@ export default class extends AbstractMapController<
132132
): google.maps.Polygon {
133133
const { points, title, infoWindow, rawOptions = {}, extra } = definition;
134134

135-
const latLngs = points.map((point) => ({ lat: point.lat, lng: point.lng }));
136-
137135
const polygon = new _google.maps.Polygon({
138136
...rawOptions,
139-
paths: latLngs,
137+
paths: points,
140138
map: this.map,
141139
});
142140

@@ -187,6 +185,15 @@ export default class extends AbstractMapController<
187185
infoWindow.setPosition(event.latLng);
188186
infoWindow.open(this.map);
189187
});
188+
189+
if (definition.opened) {
190+
const bounds = new google.maps.LatLngBounds();
191+
element.getPath().forEach((point: google.maps.LatLng) => {
192+
bounds.extend(point);
193+
});
194+
infoWindow.setPosition(bounds.getCenter());
195+
infoWindow.open({ map: this.map, anchor: element });
196+
}
190197
}
191198

192199
return infoWindow;

src/Map/src/Polygon.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Represents a polygon on a map.
1616
*
17-
* @author [Pierre S]
17+
* @author [Pierre Svgnt]
1818
*/
1919
final readonly class Polygon
2020
{
@@ -24,7 +24,6 @@
2424
public function __construct(
2525
private array $points,
2626
private ?string $title = null,
27-
private ?array $rawOptions = null,
2827
private ?InfoWindow $infoWindow = null,
2928
private array $extra = [],
3029
) {
@@ -38,7 +37,6 @@ public function toArray(): array
3837
return [
3938
'points' => array_map(fn (Point $point) => $point->toArray(), $this->points),
4039
'title' => $this->title,
41-
'rawOptions' => (object) $this->rawOptions,
4240
'infoWindow' => $this->infoWindow?->toArray(),
4341
'extra' => (object) $this->extra,
4442
];

0 commit comments

Comments
 (0)