1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sourcestaticmapservice.php
См. документацию.
1<?php
2
3namespace Bitrix\Location\Source\Google;
4
5use Bitrix\Location\Geometry\Type\Point;
6use Bitrix\Location\StaticMap;
7use Bitrix\Location\StaticMap\StaticMapResult;
8use Bitrix\Main\Error;
9use Bitrix\Main\Web\HttpClient;
10
12{
13 private HttpClient $httpClient;
14 private ?string $backendKey;
15
17 {
18 parent::__construct($source);
19
20 $this->httpClient = new HttpClient([
21 'version' => HttpClient::HTTP_1_1,
22 'socketTimeout' => 5,
23 'streamTimeout' => 5,
24 'redirect' => true,
25 'redirectMax' => 5,
26 ]);
27 }
28
29 public function getStaticMap(Point $point, int $zoom, int $width, int $height): StaticMapResult
30 {
32
33 if (is_null($this->backendKey))
34 {
35 $result->addError(new Error('API key is not specified'));
36
37 return $result;
38 }
39
40 $response = $this->httpClient->get(
41 'https://maps.googleapis.com/maps/api/staticmap?' . http_build_query([
42 'center' => implode(
43 ',',
44 [
45 $point->getLat(),
46 $point->getLng(),
47 ]
48 ),
49 'zoom' => $zoom,
50 'size' => implode(
51 'x',
52 [
53 $width,
54 $height,
55 ]
56 ),
57 'key' => $this->backendKey,
58 ])
59 );
60 $status = $this->httpClient->getStatus();
61
62 if (!$response || $status !== 200)
63 {
64 $result->addError(new Error('Service request error'));
65
66 return $result;
67 }
68
69 return $result
70 ->setContent($response)
71 ->setMimeType('image/png')
72 ;
73 }
74
75 public function setBackendKey(?string $backendKey): SourceStaticMapService
76 {
77 $this->backendKey = $backendKey;
78
79 return $this;
80 }
81}
getStaticMap(Point $point, int $zoom, int $width, int $height)
Определения sourcestaticmapservice.php:29
Определения error.php:15
$result
Определения get_property_values.php:14
$status
Определения session.php:10
$width
Определения html.php:68
$response
Определения result.php:21