|
3 | 3 | namespace DantSu\OpenStreetMapStaticAPI; |
4 | 4 |
|
5 | 5 |
|
| 6 | +use DantSu\OpenStreetMapStaticAPI\Utils\GeographicConverter; |
| 7 | + |
6 | 8 | /** |
7 | 9 | * DantSu\OpenStreetMapStaticAPI\MapData convert latitude and longitude to image pixel position. |
8 | 10 | * |
@@ -73,27 +75,6 @@ public static function yTileToLat(int $id, int $position, int $zoom, int $tileSi |
73 | 75 | return \rad2deg(\atan(\sinh(M_PI * (1 - 2 * ($id + $position / $tileSize) / \pow(2, $zoom))))); |
74 | 76 | } |
75 | 77 |
|
76 | | - /** |
77 | | - * Get center between two coordinates. |
78 | | - * @param LatLng $point1 Vertical OpenStreetMap tile id |
79 | | - * @param LatLng $point2 Vertical pixel position on tile |
80 | | - * @return LatLng midpoint between the given coordinates |
81 | | - */ |
82 | | - public static function getCenter(LatLng $point1, LatLng $point2): LatLng |
83 | | - { |
84 | | - //return new LatLng(($point1->getLat() + $point2->getLat()) / 2, ($point1->getLng() + $point2->getLng()) / 2); |
85 | | - $dLng = \deg2rad($point2->getLng() - $point1->getLng()); |
86 | | - $lat1 = \deg2rad($point1->getLat()); |
87 | | - $lat2 = \deg2rad($point2->getLat()); |
88 | | - $lng1 = \deg2rad($point1->getLng()); |
89 | | - $bx = \cos($lat2) * \cos($dLng); |
90 | | - $by = \cos($lat2) * \sin($dLng); |
91 | | - return new LatLng( |
92 | | - \rad2deg(\atan2(\sin($lat1) + \sin($lat2), \sqrt(\pow(\cos($lat1) + $bx, 2) + \pow($by, 2)))), |
93 | | - \rad2deg($lng1 + \atan2($by, \cos($lat1) + $bx)) |
94 | | - ); |
95 | | - } |
96 | | - |
97 | 78 | /** |
98 | 79 | * Transform array of LatLng to bounding box |
99 | 80 | * |
@@ -146,7 +127,7 @@ public static function getCenterAndZoomFromBoundingBox(LatLng $topLeft, LatLng $ |
146 | 127 | $pxZoneHeight = ($bottomTilePos['id'] - $topTilePos['id']) * $tileSize + $bottomTilePos['position'] - $topTilePos['position']; |
147 | 128 |
|
148 | 129 | return [ |
149 | | - 'center' => MapData::getCenter($topLeft, $bottomRight), |
| 130 | + 'center' => GeographicConverter::getCenter($topLeft, $bottomRight), |
150 | 131 | 'zoom' => \intval( |
151 | 132 | \floor( |
152 | 133 | \log( |
|
0 commit comments