Skip to content

Commit 251e55e

Browse files
committed
adding fit to draws and markers
1 parent bfc801a commit 251e55e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/OpenStreetMap.php

+41
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,51 @@ public function fitToDraws(int $padding = 0)
131131
foreach ($this->draws as $draw) {
132132
$points = \array_merge($points, $draw->getBoundingBox());
133133
}
134+
return $this->fitToPoints($points, $padding);
135+
}
134136

137+
/**
138+
* Fit map to draws.
139+
*
140+
* @param int $padding Padding in pixel
141+
* @return $this Fluent interface
142+
*/
143+
public function fitToMarkers(int $padding = 0)
144+
{
145+
$points = [];
135146
foreach ($this->markers as $markers) {
136147
$points = \array_merge($points, $markers->getBoundingBox());
137148
}
149+
return $this->fitToPoints($points, $padding);
150+
}
151+
152+
/**
153+
* Fit map to draws.
154+
*
155+
* @param int $padding Padding in pixel
156+
* @return $this Fluent interface
157+
*/
158+
public function fitToMarkersAndDraws(int $padding = 0)
159+
{
160+
$points = [];
161+
foreach ($this->draws as $draw) {
162+
$points = \array_merge($points, $draw->getBoundingBox());
163+
}
164+
foreach ($this->markers as $markers) {
165+
$points = \array_merge($points, $markers->getBoundingBox());
166+
}
167+
return $this->fitToPoints($points, $padding);
168+
}
169+
170+
/**
171+
* Fit map to points.
172+
*
173+
* @param LatLng[] $points LatLng points
174+
* @param int $padding Padding in pixel
175+
* @return $this Fluent interface
176+
*/
177+
public function fitToPoints(array $points, int $padding = 0)
178+
{
138179
$outputSize = $this->mapData->getOutputSize();
139180
$tileSize = $this->mapData->getTileSize();
140181
$boundingBox = MapData::getBoundingBoxFromPoints($points);

0 commit comments

Comments
 (0)