PageSourceSearch

https://kingfisher.kz/assets/dacd5ae0/ymaps3-extensions.js

js kingfisher.kz collected 2026-09-24 10:12:17 UTC 6,135 bytes, 133 lines download raw bytes

1/**
2 * Раширения для объекта карты YMap3
3 */
4window.YMap3Extensions = {
5    // Контекст объекта карты YMap3
6    YMap3: null,
7    // Контекст объекта API карты ymaps3
8    ymaps3: null,
9    /**
10     * @param {object} YMap3
11     * @param {object} ymaps3
12     * @returns {object - YMap3} модифицированный объект YMap3
13     */
14    init: function (YMap3, ymaps3) {
15        // Настройка свойств объекта расширения
16        this.YMap3 = YMap3;
17        this.ymaps3 = ymaps3;
18
19        /**
20         * ========================================
21         * Добавление методов в объект карты YMap3.
22         * В теле методов:
23         * this - контекст текущего объекта.
24         * this.YMap3 контекст объекта карты YMap3.
25         * this.ymaps3 контекст объекта API карты ymaps3.
26         */
27
28        /** @returns {array} возвращает массив координат */
29        this.YMap3.getCenterCoordinates = () => {
30            return this.YMap3?._props.location.center || [76.93376, 43.224729];
31        };
32
33        /**
34         * Получение информации объекта
35         * по строке адреса или по координатам
36         * переданных в аргументе
37         *
38         * @param {string|array} searchData
39         * @returns {Promise} возвращает промис
40         */
41        this.YMap3.getGeoObject = (searchData) => {
42            return this.YMap3.centerObject(searchData);
43        };
44
45        /**
46         * Серверный геокод через window.Geo вместо клиентского ymaps3.search.
47         * Раньше дёргался Search API (`api-maps.yandex.ru/services/search`), не подключённый к ключу →
48         * `net::ERR_BLOCKED_BY_ORB` («fetching failed» в консоли). Теперь:
49         *  - нет searchData или массив [lon,lat] → Geo.reverse (координаты→адрес);
50         *  - строка адреса → Geo.forward (адрес→координаты; Geo даёт [lat,lon] → [lon,lat]).
51         * Возвращает Promise<[pointFound]> (контракт res[0], как у прежнего ymaps3.search);
52         * pointFound.geometry.coordinates — в порядке v3 [lon,lat].
53         *
54         * @param {string|array} searchData
55         * @returns {Promise} возвращает промис
56         */
57        this.YMap3.centerObject = (searchData) => {
58            const toResult = (lonLat, address) =>
59                lonLat
60                    ? [{ geometry: { type: 'Point', coordinates: lonLat }, properties: { name: address || '', description: address || '' } }]
61                    : [];
62            if (!window.Geo) {
63                return Promise.resolve([]);
64            }
65            // Координаты (нет аргумента → центр карты, либо явный массив [lon,lat]) → reverse
66            if (!searchData || Array.isArray(searchData)) {
67                const coords = Array.isArray(searchData) ? searchData : this.YMap3.getCenterCoordinates();
68                const lon = coords[0];
69                const lat = coords[1];
70                return window.Geo.reverse(lat, lon).then((address) => toResult([lon, lat], address));
71            }
72            // Строка адреса → forward
73            return window.Geo.forward(searchData).then((c) => toResult(c ? [c[1], c[0]] : null, searchData));
74        };
75
76        this.YMap3.getCoordinates = (object) => {
77            let mapObjectCoordinates = [];
78            let coordinatesNumeric = null;
79
80            // Получение координат из элемента объекта YMapCollection
81            if (object?.B2D_id) {
82                mapObjectCoordinates = object?._props?.geometry.coordinates[0];
83                if (mapObjectCoordinates) {
84                    if (mapObjectCoordinates.length > 0) {
85                        mapObjectCoordinates.forEach((itemCoords) => {
86                            coordinatesNumeric = [
87                                [+itemCoords[0], +itemCoords[1]],
88                            ];
89                        });
90                    }
91                }
92            } else if (object?.geometry) {
93                //# Получение координат из объекта поиска
94                mapObjectCoordinates = object.geometry.coordinates;
95                if (mapObjectCoordinates) {
96                    if (mapObjectCoordinates.length == 1) {
97                        coordinatesNumeric = [[]];
98                        mapObjectCoordinates[0].forEach((itemCoords) => {
99                            coordinatesNumeric[0].push([
100                                +itemCoords[0],
101                                +itemCoords[1],
102                            ]);
103                        });
104                    }
105                    if (mapObjectCoordinates.length == 2) {
106                        coordinatesNumeric = [
107                            +mapObjectCoordinates[0],
108                            +mapObjectCoordinates[1],
109                        ];
110                    }
111                }
112            } else {
113                //# Получение координат города из БД
114                mapObjectCoordinates = object?.coordinates;
115                if (mapObjectCoordinates) {
116                    if (isString(mapObjectCoordinates)) {
117                        mapObjectCoordinates = mapObjectCoordinates.split(',');
118                    }
119                    if (mapObjectCoordinates.length == 2) {
120                        coordinatesNumeric = [
121                            +mapObjectCoordinates[1],
122                            +mapObjectCoordinates[0],
123                        ];
124                    }
125                }
126            }
127
128            return coordinatesNumeric;
129        };
130
131        return this.YMap3;
132    },
133};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.