-
Notifications
You must be signed in to change notification settings - Fork 3
/
example-2.php
45 lines (37 loc) · 1.62 KB
/
example-2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/*
* This file is part of the StaticMaps.
*
* (c) RUNALYZE <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
require_once '../../vendor/autoload.php';
use Intervention\Image\ImageManager;
use League\Flysystem\Local\LocalFilesystemAdapter;
use League\Flysystem\Filesystem;
use Runalyze\StaticMaps\Cache\FilesystemCache;
use Runalyze\StaticMaps\Feature\CopyrightNotice;
use Runalyze\StaticMaps\Feature\Route;
use Runalyze\StaticMaps\Feature\TileMap;
use Runalyze\StaticMaps\Map\Map;
use Runalyze\StaticMaps\Renderer;
use Runalyze\StaticMaps\TileProvider;
use Runalyze\StaticMaps\TileService\OpenStreetMapDe;
use Runalyze\StaticMaps\Viewport\Viewport;
$imageManager = ImageManager::gd();
$tileService = new OpenStreetMapDe();
$tileCache = new FilesystemCache(new Filesystem(new LocalFilesystemAdapter(__DIR__.'/cache/tiles')), $imageManager);
$tileProvider = new TileProvider($tileService, $imageManager, new \GuzzleHttp\Client(), $tileCache);
$route = new Route([[53.57532, 10.01534], [52.520008, 13.404954], [48.13743, 11.57549]], '#ff5500', 5);
$viewport = new Viewport(500, 350, $route->getBoundingBox(), $tileService);
$map = new Map($viewport);
$map->addFeature(new TileMap($tileProvider));
$map->addFeature($route);
$map->addFeature(new CopyrightNotice($tileService->getAttributionText(), function (\Intervention\Image\Typography\FontFactory $font) {
$font->file('../../resources/font/Roboto-Regular.ttf');
}));
$provider = new Renderer($imageManager);
$image = $provider->renderMap($map);
file_put_contents('example-2.png', $image->toPng());