Skip to content

Commit bfc801a

Browse files
committed
adding fit to draws
1 parent 6f67304 commit bfc801a

19 files changed

+374
-28
lines changed

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/Circle.md

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DantSu\OpenStreetMapStaticAPI\Circle draw circle on the map.
2020
- [setEdgePoint](#-setedgepoint)
2121
- [setRadius](#-setradius)
2222
- [draw](#-draw)
23+
- [getBoundingBox](#-getboundingbox)
2324

2425
### ->__construct
2526

@@ -123,6 +124,25 @@ Draw the circle on the map image.
123124

124125
* https://github.com/DantSu/php-image-editor - See more about DantSu\PHPImageEditor\Image
125126

127+
---
128+
### ->getBoundingBox
129+
130+
Get bounding box of the shape
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
#### Return Value:
141+
142+
**\DantSu\OpenStreetMapStaticAPI\LatLng[]** :
143+
144+
145+
126146
---
127147

128148

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/Interfaces/Draw.md

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212

1313
## Methods
1414

15+
### ->getBoundingBox
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
#### Return Value:
28+
29+
**array** :
30+
31+
32+
33+
---
1534
### ->draw
1635

1736

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/Line.md

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ DantSu\OpenStreetMapStaticAPI\Line draw line on the map.
1919
- [__construct](#-__construct)
2020
- [addPoint](#-addpoint)
2121
- [draw](#-draw)
22+
- [getBoundingBox](#-getboundingbox)
2223

2324
### ->__construct
2425

@@ -95,6 +96,25 @@ Draw the line on the map image.
9596

9697
* https://github.com/DantSu/php-image-editor - See more about DantSu\PHPImageEditor\Image
9798

99+
---
100+
### ->getBoundingBox
101+
102+
Get bounding box of the shape
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
#### Return Value:
113+
114+
**\DantSu\OpenStreetMapStaticAPI\LatLng[]** :
115+
116+
117+
98118
---
99119

100120

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/MapData.md

+57
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ DantSu\OpenStreetMapStaticAPI\MapData convert latitude and longitude to image pi
2020
- *(static)* [xTileToLng](#xtiletolng)
2121
- *(static)* [yTileToLat](#ytiletolat)
2222
- *(static)* [getCenter](#getcenter)
23+
- *(static)* [getBoundingBoxFromPoints](#getboundingboxfrompoints)
24+
- *(static)* [getCenterAndZoomFromBoundingBox](#getcenterandzoomfromboundingbox)
2325
- [__construct](#-__construct)
2426
- [getLatLngTopLeft](#-getlatlngtopleft)
2527
- [getLatLngTopRight](#-getlatlngtopright)
@@ -169,6 +171,61 @@ Get center between two coordinates.
169171

170172

171173

174+
---
175+
### ::getBoundingBoxFromPoints
176+
177+
Transform array of LatLng to bounding box
178+
179+
180+
181+
* This method is **static**.
182+
183+
184+
185+
186+
#### Parameters:
187+
188+
| Parameter | Type | Description |
189+
|-----------|------|-------------|
190+
| `points` | **\DantSu\OpenStreetMapStaticAPI\LatLng[]** | |
191+
192+
193+
#### Return Value:
194+
195+
**\DantSu\OpenStreetMapStaticAPI\LatLng[]** :
196+
197+
198+
199+
---
200+
### ::getCenterAndZoomFromBoundingBox
201+
202+
Get center and zoom from two points.
203+
204+
205+
206+
* This method is **static**.
207+
208+
209+
210+
211+
#### Parameters:
212+
213+
| Parameter | Type | Description |
214+
|-----------|------|-------------|
215+
| `topLeft` | **\DantSu\OpenStreetMapStaticAPI\LatLng** | |
216+
| `bottomRight` | **\DantSu\OpenStreetMapStaticAPI\LatLng** | |
217+
| `padding` | **int** | |
218+
| `imageWidth` | **int** | |
219+
| `imageHeight` | **int** | |
220+
| `tileSize` | **int** | |
221+
222+
223+
#### Return Value:
224+
225+
**array** : center : LatLng, zoom : int
226+
227+
228+
172229
---
173230
### ->__construct
174231

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/Markers.md

+20
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ DantSu\OpenStreetMapStaticAPI\Markers display markers on the map.
3030
- [addMarker](#-addmarker)
3131
- [setAnchor](#-setanchor)
3232
- [draw](#-draw)
33+
- [getBoundingBox](#-getboundingbox)
3334

3435
### ->__construct
3536

@@ -131,6 +132,25 @@ Draw markers on the image map.
131132

132133
* https://github.com/DantSu/php-image-editor - See more about DantSu\PHPImageEditor\Image
133134

135+
---
136+
### ->getBoundingBox
137+
138+
Get bounding box of markers
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
#### Return Value:
149+
150+
**\DantSu\OpenStreetMapStaticAPI\LatLng[]** :
151+
152+
153+
134154
---
135155

136156

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/OpenStreetMap.md

+26
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ DantSu\OpenStreetMapStaticAPI\OpenStreetMap is a PHP library created for easily
2121
- [addLayer](#-addlayer)
2222
- [addMarkers](#-addmarkers)
2323
- [addDraw](#-adddraw)
24+
- [fitToDraws](#-fittodraws)
2425
- [getMapData](#-getmapdata)
2526
- [getImage](#-getimage)
2627

@@ -185,6 +186,31 @@ Add a line on the map
185186

186187

187188

189+
---
190+
### ->fitToDraws
191+
192+
Fit map to draws.
193+
194+
195+
196+
197+
198+
199+
200+
201+
#### Parameters:
202+
203+
| Parameter | Type | Description |
204+
|-----------|------|-------------|
205+
| `padding` | **int** | Padding in pixel |
206+
207+
208+
#### Return Value:
209+
210+
**$this** : Fluent interface
211+
212+
213+
188214
---
189215
### ->getMapData
190216

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/Polygon.md

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ DantSu\OpenStreetMapStaticAPI\Polygon draw polygon on the map.
1919
- [__construct](#-__construct)
2020
- [addPoint](#-addpoint)
2121
- [draw](#-draw)
22+
- [getBoundingBox](#-getboundingbox)
2223

2324
### ->__construct
2425

@@ -96,6 +97,25 @@ Draw the polygon on the map image.
9697

9798
* https://github.com/DantSu/php-image-editor - See more about DantSu\PHPImageEditor\Image
9899

100+
---
101+
### ->getBoundingBox
102+
103+
Get bounding box of the shape
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
#### Return Value:
114+
115+
**\DantSu\OpenStreetMapStaticAPI\LatLng[]** :
116+
117+
118+
99119
---
100120

101121

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/TileLayer.md

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ TileLayer constructor
6464
| `url` | **string** | tile server url with placeholders (`x`, `y`, `z`, `r`, `s`) |
6565
| `attributionText` | **string** | tile server attribution text |
6666
| `subdomains` | **string** | tile server subdomains |
67+
| `curlOptions` | **array** | Array of curl options |
68+
| `failCurlOnError` | **bool** | If true, curl will throw an exception on error. |
6769

6870

6971

Diff for: docs/classes/DantSu/OpenStreetMapStaticAPI/Utils/GeographicConverter.md

+28
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- *(static)* [earthRadiusAtLatitude](#earthradiusatlatitude)
1515
- *(static)* [metersToLatLng](#meterstolatlng)
16+
- *(static)* [latLngToMeters](#latlngtometers)
1617

1718
### ::earthRadiusAtLatitude
1819

@@ -42,6 +43,7 @@ Calculate the earth radius at the given latitude
4243
### ::metersToLatLng
4344

4445
Convert distance and angle from a point to latitude and longitude
46+
0 : top, 90 : right; 180 : bottom, 270 : left
4547

4648

4749

@@ -65,6 +67,32 @@ Convert distance and angle from a point to latitude and longitude
6567

6668

6769

70+
---
71+
### ::latLngToMeters
72+
73+
Get distance in meters between two points.
74+
75+
76+
77+
* This method is **static**.
78+
79+
80+
81+
82+
#### Parameters:
83+
84+
| Parameter | Type | Description |
85+
|-----------|------|-------------|
86+
| `from` | **\DantSu\OpenStreetMapStaticAPI\LatLng** | Starting coordinate |
87+
| `end` | **\DantSu\OpenStreetMapStaticAPI\LatLng** | Ending coordinate |
88+
89+
90+
#### Return Value:
91+
92+
**float** :
93+
94+
95+
6896
---
6997

7098

Diff for: src/Circle.php

+14
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,18 @@ public function draw(Image $image, MapData $mapData): Circle
110110
return $this;
111111
}
112112

113+
114+
/**
115+
* Get bounding box of the shape
116+
* @return LatLng[]
117+
*/
118+
public function getBoundingBox(): array
119+
{
120+
$distance = GeographicConverter::latLngToMeters($this->center, $this->edge);
121+
$latLng1 = GeographicConverter::metersToLatLng($this->center, $distance, 0);
122+
$latLng2 = GeographicConverter::metersToLatLng($this->center, $distance, 90);
123+
$latLng3 = GeographicConverter::metersToLatLng($this->center, $distance, 180);
124+
$latLng4 = GeographicConverter::metersToLatLng($this->center, $distance, 270);
125+
return [new LatLng($latLng1->getLat(), $latLng4->getLng()), new LatLng($latLng3->getLat(), $latLng2->getLng())];
126+
}
113127
}

Diff for: src/Interfaces/Draw.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
interface Draw
1010
{
11+
public function getBoundingBox(): array;
12+
1113
public function draw(Image $image, MapData $mapData);
1214
}

Diff for: src/Line.php

+9
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,13 @@ function (LatLng $p) use ($mapData) {
7878
}
7979
return $this;
8080
}
81+
82+
/**
83+
* Get bounding box of the shape
84+
* @return LatLng[]
85+
*/
86+
public function getBoundingBox(): array
87+
{
88+
return MapData::getBoundingBoxFromPoints($this->points);
89+
}
8190
}

0 commit comments

Comments
 (0)