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.