1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
repository.php
См. документацию.
1<?php
2
3namespace Bitrix\Location\Source\Osm;
4
5use Bitrix\Location\Entity\Location;
6use Bitrix\Location\Geometry\Converter\Manager;
7use Bitrix\Location\Geometry\Type\Point;
8use Bitrix\Location\Infrastructure\Service\CustomFieldsService;
9use Bitrix\Location\Repository\Location\Capability\IFindByCoords;
10use Bitrix\Location\Repository\Location\Capability\IFindByExternalId;
11use Bitrix\Location\Repository\Location\Capability\ISupportAutocomplete;
12use Bitrix\Location\Repository\Location\IRepository;
13use Bitrix\Location\Repository\Location\ISource;
14use Bitrix\Location\Source\BaseRepository;
15use Bitrix\Location\Source\Osm\Api\Api;
16use Bitrix\Location\Source\Osm\Converters\Factory;
17
23final class Repository extends BaseRepository implements
29{
31 protected static $sourceCode = 'OSM';
32
34 protected $api;
35
37 protected $osmSource;
38
45 {
46 $this->api = $api;
47 $this->osmSource = $osmSource;
48 }
49
53 public function findByExternalId(string $externalId, string $sourceCode, string $languageId)
54 {
55 $osmType = ExternalIdBuilder::getOsmTypeByExternalId($externalId);
56 $osmId = ExternalIdBuilder::getOsmIdByExternalId($externalId);
57
58 if ($sourceCode !== self::$sourceCode || is_null($osmType) || is_null($osmId))
59 {
60 return null;
61 }
62
63 $details = $this->api->details(
64 [
65 'osm_type' => $osmType,
66 'osm_id' => $osmId,
67 'addressdetails' => 1,
68 'accept-language' => $this->osmSource->convertLang($languageId),
69 ]
70 );
71
72 $location = Factory::make($details)->convert(
73 $languageId, $details
74 );
75
76 if (
78 && isset($details['centroid'])
79 )
80 {
81 $centroid = Manager::makeConverter(Manager::FORMAT_ARRAY)->read($details['centroid']);
82
83 if ($centroid instanceof Point)
84 {
85 $customFieldsScenario = CustomFieldsService::getInstance()->getCustomFieldsByPoint($centroid);
86 if ($customFieldsScenario)
87 {
88 $customFieldsScenario->adjustLocation($location);
89 }
90 }
91 }
92
93 return $location;
94 }
95
96 public function findByCoords(
97 float $lat,
98 float $lng,
99 int $zoom,
100 string $languageId
101 ): ?Location
102 {
103 $reverse = $this->api->reverse(
104 [
105 'lat' => $lat,
106 'lng' => $lng,
107 'zoom' => $zoom,
108 'addressdetails' => 0,
109 'accept-language' => $this->osmSource->convertLang($languageId),
110 ]
111 );
112
113 if (
114 !(
115 isset($reverse['osm_type'])
116 && isset($reverse['osm_id'])
117 )
118 )
119 {
120 return null;
121 }
122
124 NodeTypeMap::getShortNodeTypeCode($reverse['osm_type']),
125 $reverse['osm_id']
126 );
127
128 if (!$externalId)
129 {
130 return null;
131 }
132
133 return $this->findByExternalId(
134 $externalId,
135 self::$sourceCode,
136 $languageId
137 );
138 }
139
143 public function autocomplete(array $params): array
144 {
145 $result = $this->api->autocomplete([
146 'q' => $params['q'],
147 'lang' => $this->osmSource->convertLang($params['lang']),
148 'lat' => $params['lat'] ?? null,
149 'lon' => $params['lon'] ?? null,
150 ]);
151
152 if (
153 is_array($result)
154 && isset($result['features'])
155 && is_array($result['features'])
156 )
157 {
158 foreach ($result['features'] as $key => $feature)
159 {
160 if (!isset($feature['geometry']))
161 {
162 continue;
163 }
164
165 $geometry = Manager::makeConverter(Manager::FORMAT_ARRAY)->read($feature['geometry']);
166 if (!$geometry instanceof Point)
167 {
168 continue;
169 }
170
171 $customFieldsScenario = CustomFieldsService::getInstance()->getCustomFieldsByPoint($geometry);
172 if (!$customFieldsScenario)
173 {
174 continue;
175 }
176 $customFieldsScenario->adjustAutocompleteItem($result['features'][$key]['properties']);
177 }
178 }
179
180 return $result;
181 }
182
186 public static function getSourceCode(): string
187 {
188 return self::$sourceCode;
189 }
190}
static buildExternalId(string $osmType, int $osmId)
Определения externalidbuilder.php:17
static getOsmIdByExternalId(string $externalId)
Определения externalidbuilder.php:40
static getOsmTypeByExternalId(string $externalId)
Определения externalidbuilder.php:31
static getShortNodeTypeCode(string $longNodeTypeCode)
Определения nodetypemap.php:13
findByCoords(float $lat, float $lng, int $zoom, string $languageId)
Определения repository.php:96
findByExternalId(string $externalId, string $sourceCode, string $languageId)
Определения repository.php:53
__construct(Api $api, OsmSource $osmSource)
Определения repository.php:44
autocomplete(array $params)
Определения repository.php:143
static getInstance()
Определения application.php:98
</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
if(empty($signedUserToken)) $key
Определения quickway.php:257
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$location
Определения options.php:2729