Skip to content

Commit 0922b26

Browse files
committed
Adding OpenStreetMap attribution
1 parent f70f3db commit 0922b26

File tree

12 files changed

+43
-32
lines changed

12 files changed

+43
-32
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use \DantSu\OpenStreetMapStaticAPI\Markers;
3030
(new Markers(__DIR__ . '/resources/marker.png'))
3131
->setAnchor(Markers::ANCHOR_CENTER, Markers::ANCHOR_BOTTOM)
3232
->addMarker(new LatLng(44.351933, 2.568113))
33+
->addMarker(new LatLng(44.351510, 2.570020))
34+
->addMarker(new LatLng(44.351873, 2.566250))
3335
)
3436
->addLine(
3537
(new Line('FF0000', 2))

docs/classes/DantSu/OpenStreetMapStaticAPI/BoundingBox.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@ Convert a latitude and longitude to a XY pixel position in the image
129129

130130

131131
---
132-
> Automatically generated from source code comments on 2021-09-08 using [phpDocumentor](http://www.phpdoc.org/)
132+
> Automatically generated from source code comments on 2021-09-09 using [phpDocumentor](http://www.phpdoc.org/)

docs/classes/DantSu/OpenStreetMapStaticAPI/LatLng.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ Get longitude
8282

8383

8484
---
85-
> Automatically generated from source code comments on 2021-09-08 using [phpDocumentor](http://www.phpdoc.org/)
85+
> Automatically generated from source code comments on 2021-09-09 using [phpDocumentor](http://www.phpdoc.org/)

docs/classes/DantSu/OpenStreetMapStaticAPI/Line.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ Draw the line on the map image.
9898

9999

100100
---
101-
> Automatically generated from source code comments on 2021-09-08 using [phpDocumentor](http://www.phpdoc.org/)
101+
> Automatically generated from source code comments on 2021-09-09 using [phpDocumentor](http://www.phpdoc.org/)

docs/classes/DantSu/OpenStreetMapStaticAPI/Markers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,4 @@ Draw markers on the image map.
135135

136136

137137
---
138-
> Automatically generated from source code comments on 2021-09-08 using [phpDocumentor](http://www.phpdoc.org/)
138+
> Automatically generated from source code comments on 2021-09-09 using [phpDocumentor](http://www.phpdoc.org/)

docs/classes/DantSu/OpenStreetMapStaticAPI/OpenStreetMap.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ DantSu\OpenStreetMapStaticAPI\OpenStreetMap is a PHP library created for easily
2323
- [addMarkers](#-addmarkers)
2424
- [addLine](#-addline)
2525
- [getBoundingBox](#-getboundingbox)
26-
- [getMapImage](#-getmapimage)
2726
- [getImage](#-getimage)
2827

2928
### ::lngToXTile
@@ -222,28 +221,6 @@ Get the bounding box of the map
222221

223222

224223

225-
---
226-
### ->getMapImage
227-
228-
Get only the map image.
229-
230-
231-
232-
233-
234-
235-
236-
237-
238-
#### Return Value:
239-
240-
**\DantSu\PHPImageEditor\Image** : An instance of DantSu\PHPImageEditor\Image
241-
242-
243-
#### See Also:
244-
245-
* https://github.com/DantSu/php-image-editor - See more about DantSu\PHPImageEditor\Image
246-
247224
---
248225
### ->getImage
249226

@@ -270,4 +247,4 @@ Get the map image with markers and lines.
270247

271248

272249
---
273-
> Automatically generated from source code comments on 2021-09-08 using [phpDocumentor](http://www.phpdoc.org/)
250+
> Automatically generated from source code comments on 2021-09-09 using [phpDocumentor](http://www.phpdoc.org/)

docs/classes/DantSu/OpenStreetMapStaticAPI/XY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ Get Y
8282

8383

8484
---
85-
> Automatically generated from source code comments on 2021-09-08 using [phpDocumentor](http://www.phpdoc.org/)
85+
> Automatically generated from source code comments on 2021-09-09 using [phpDocumentor](http://www.phpdoc.org/)

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ This is an automatically generated documentation for **PHP OpenStreetMap Static
2424

2525

2626
---
27-
> Automatically generated from source code comments on 2021-09-08 using [phpDocumentor](http://www.phpdoc.org/)
27+
> Automatically generated from source code comments on 2021-09-09 using [phpDocumentor](http://www.phpdoc.org/)

src/OpenStreetMap.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function getBoundingBox(): BoundingBox
138138
* @see https://github.com/DantSu/php-image-editor See more about DantSu\PHPImageEditor\Image
139139
* @return Image An instance of DantSu\PHPImageEditor\Image
140140
*/
141-
public function getMapImage(): Image
141+
protected function getMapImage(): Image
142142
{
143143
$bbox = $this->boundingBox;
144144
$xTile = static::lngToXTile($bbox->getBottomLeft()->getLng(), $this->zoom);
@@ -164,6 +164,35 @@ public function getMapImage(): Image
164164
return $image;
165165
}
166166

167+
/**
168+
* Draw OpenStreetMap attribution at the right bottom of the image
169+
* @param Image $image The image of the map
170+
* @return Image The image of the map with attribution
171+
*/
172+
protected function drawAttribution(Image $image): Image
173+
{
174+
$margin = 5;
175+
$attribution = function (Image $image, $margin): array {
176+
return $image->writeTextAndGetBoundingBox(
177+
'© OpenStreetMap contributors',
178+
__DIR__ . '/resources/font.ttf',
179+
10,
180+
'0078A8',
181+
$margin,
182+
$margin,
183+
Image::ALIGN_LEFT,
184+
Image::ALIGN_TOP
185+
);
186+
};
187+
188+
$bbox = $attribution(Image::newCanvas(1, 1), $margin);
189+
$imageAttribution = Image::newCanvas($bbox['bottom-right']['x'] + $margin, $bbox['bottom-right']['y'] + $margin);
190+
$imageAttribution->drawRectangle(0, 0, $imageAttribution->getWidth(), $imageAttribution->getHeight(), 'FFFFFF33');
191+
$attribution($imageAttribution, $margin);
192+
193+
return $image->pasteOn($imageAttribution, Image::ALIGN_RIGHT, Image::ALIGN_BOTTOM);
194+
}
195+
167196
/**
168197
* Get the map image with markers and lines.
169198
*
@@ -182,6 +211,6 @@ public function getImage(): Image
182211
$markers->draw($image, $this->boundingBox);
183212
}
184213

185-
return $image;
214+
return $this->drawAttribution($image);
186215
}
187216
}

src/resources/font.ttf

31.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)