1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
osmsource.php
См. документацию.
1<?php
2
3namespace Bitrix\Location\Source\Osm;
4
5use Bitrix\Location\Entity\Source;
6use Bitrix\Location\Repository\Location\IRepository;
7use Bitrix\Location\Source\Osm\Api\Api;
8use Bitrix\Location\StaticMap\ISourceStaticMapService;
9use Bitrix\Main\Application;
10use Bitrix\Main\ModuleManager;
11use Bitrix\Main\Context;
12use Bitrix\Main\License\UrlProvider;
13
19final class OsmSource extends Source
20{
21 public const API_PATH = '/api';
22
23 private UrlProvider $urlProvider;
24 private TokenRequester $tokenRequester;
25
26 public function __construct()
27 {
28 $this->urlProvider = new UrlProvider();
29 $this->tokenRequester = (new TokenRequester())->setSource($this);
30 }
31
35 public function makeRepository(): IRepository
36 {
37 static $result = null;
38
39 if ($result !== null)
40 {
41 return $result;
42 }
43
44 $result = new Repository(
45 new Api($this),
46 $this
47 );
48
49 return $result;
50 }
51
56 {
57 return new SourceStaticMapService($this);
58 }
59
63 public function getJSParams(): array
64 {
65 $token = $this->getOsmToken();
66
67 return [
68 'serviceUrl' => $this->getOsmApiUrl(),
69 'mapServiceUrl' => $this->getOsmMapServiceUrl(),
70 'token' => $token ? $token->getToken() : null,
71 'useGeocodingService' => true,
72 'hostName' => $this->getOsmHostName()
73 ];
74 }
75
79 public function convertLang(string $bitrixLang): string
80 {
81 $langMap = [
82 'br' => 'pt', // Portuguese (Brazil)
83 'la' => 'es', // Spanish
84 'sc' => 'zh', // Chinese (Simplified)
85 'tc' => 'zh', // Chinese (Traditional)
86 'vn' => 'vi', // Vietnamese
87 'ua' => 'uk', // Ukrainian
88 ];
89
90 return $langMap[$bitrixLang] ?? $bitrixLang;
91 }
92
96 public function getOsmHostName(): string
97 {
98 if (defined('BX24_HOST_NAME') && ModuleManager::isModuleInstalled('bitrix24'))
99 {
100 $result = BX24_HOST_NAME;
101 }
102 else
103 {
104 $result = Context::getCurrent()->getServer()->get('HTTP_HOST');
105
106 if (strpos($result, ':') !== false)
107 {
108 $result = explode(':', $result)[0];
109 }
110 }
111
112 return $result;
113 }
114
115 public function getOsmApiUrl(): ?string
116 {
117 $serviceUrl = $this->getOsmServiceUrl();
118 if (!$serviceUrl)
119 {
120 return null;
121 }
122
123 return $serviceUrl . static::API_PATH;
124 }
125
126 public function getOsmServiceUrl(): ?string
127 {
128 if (defined('LOCATION_OSM_SERVICE_URL') && LOCATION_OSM_SERVICE_URL)
129 {
130 return (string)LOCATION_OSM_SERVICE_URL;
131 }
132
133 return 'https://osm-' . $this->getSubDomainSuffix() . '-002.' . $this->urlProvider->getTechDomain();
134 }
135
136 public function getOsmMapServiceUrl(): ?string
137 {
138 if (defined('LOCATION_OSM_MAP_SERVICE_URL') && LOCATION_OSM_MAP_SERVICE_URL)
139 {
140 return (string)LOCATION_OSM_MAP_SERVICE_URL;
141 }
142
143 return 'https://osm-' . $this->getSubDomainSuffix() . '-001.' . $this->urlProvider->getTechDomain();
144 }
145
146 public function getOsmToken(): ?Token
147 {
148 return $this->tokenRequester->getToken();
149 }
150
151 public function isAvailable(): bool
152 {
153 $token = $this->tokenRequester->getToken();
154 if ($token)
155 {
156 return true;
157 }
158
159 return !$this->tokenRequester->hasLicenseIssues();
160 }
161
162 private function getSubDomainSuffix(): string
163 {
164 $region = Application::getInstance()->getLicense()->getRegion();
165
166 return in_array($region, ['ru', 'by', 'kz', 'uz'], true) ? 'ru' : 'de';
167 }
168}
convertLang(string $bitrixLang)
Определения osmsource.php:79
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$region
Определения .description.php:13