AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 3.147.7.215
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/bitrix/www/bitrix/js/location/google/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/bitrix/www/bitrix/js/location/google/src/geocodingservice.js
import {Location, AddressType, LocationType, GeocodingServiceBase} from 'location.core';

export default class GeocodingService extends GeocodingServiceBase
{
	#map;
	#geocoder;
	#loadingPromise;
	#googleSource;

	constructor(props)
	{
		super(props);

		this.#map = props.map;
		this.#googleSource = props.googleSource;
	}

	#getLoaderPromise()
	{
		if(!this.#loadingPromise)
		{
			//map haven't rendered yet	`
			if(this.#googleSource.loaderPromise === null)
			{
				return;
			}

			this.#loadingPromise = this.#googleSource.loaderPromise.then(() => {
				this.#geocoder = new google.maps.Geocoder();
			});
		}

		return this.#loadingPromise;
	}

	#convertLocationType(types: Array)
	{
		let typeMap = {
			'country': LocationType.COUNTRY,
			'locality': LocationType.LOCALITY,
			'postal_town': LocationType.LOCALITY,
			'route': LocationType.STREET,
			'street_address': LocationType.ADDRESS_LINE_1,
			'administrative_area_level_4': LocationType.ADM_LEVEL_4,
			'administrative_area_level_3': LocationType.ADM_LEVEL_3,
			'administrative_area_level_2': LocationType.ADM_LEVEL_2,
			'administrative_area_level_1': LocationType.ADM_LEVEL_1,
			'floor': LocationType.FLOOR,
			'postal_code': AddressType.POSTAL_CODE,
			'room': LocationType.ROOM,
			'sublocality': LocationType.SUB_LOCALITY,
			'sublocality_level_1': LocationType.SUB_LOCALITY_LEVEL_1,
			'sublocality_level_2': LocationType.SUB_LOCALITY_LEVEL_2,
			'street_number': LocationType.BUILDING
		};

		let result = LocationType.UNKNOWN;

		for (let item of types)
		{
			if(typeof typeMap[item] !== 'undefined')
			{
				result = typeMap[item];
				break;
			}
		}

		return result;
	}

	#convertResultToLocations(data: Array)
	{
		let result = [];

		for (let item of data)
		{
			let location = new Location;
			location.sourceCode = this.#googleSource.sourceCode;
			location.languageId = this.#googleSource.languageId;
			location.externalId = item.place_id;
			location.type = this.#convertLocationType(item.types);
			location.name = item.formatted_address;
			location.latitude = item.geometry.location.lat();
			location.longitude = item.geometry.location.lng();
			result.push(location);
		}

		return result;
	}

	geocodeConcrete(addressString: string): Promise
	{
		return new Promise((resolve) => {

			const loaderPromise = this.#getLoaderPromise();

			if(!loaderPromise)
			{
				resolve([]);
				return;
			}

			loaderPromise
				.then(() => {
					this.#geocoder.geocode({address: addressString}, (results, status) => {
						if(status === 'OK') {
							resolve(this.#convertResultToLocations(results));
						}
						else if(status === 'ZERO_RESULTS')
						{
							resolve([]);
						}
						else
						{
							BX.debug(`Geocode was not successful for the following reason: ${status}`);
						}
					});
				});
		});
	}
}

Anon7 - 2022
AnonSec Team