1/** @namespace ymaps */ 2/** @namespace item.GeoObjectCollection */ 3/** @namespace item.Placemark */ 4/** @namespace item.Button */ 5 6 7let YaMapsShown = false; 8const mapContainer = 'contacts__ymaps' 9 10 11window.addEventListener('scroll', function () { 12 if (!YaMapsShown && document.getElementById(mapContainer)) { 13 if (onScreen(document.getElementById(mapContainer))) { 14 YaMapsShown = true 15 showYaMaps() 16 } 17 } 18}); 19 20$(window).on('load', function () { 21 if (!YaMapsShown && document.getElementById(mapContainer)) { 22 if (onScreen(document.getElementById(mapContainer))) { 23 YaMapsShown = true 24 showYaMaps() 25 } 26 } 27}); 28 29function showYaMaps() { 30 let script = document.createElement("script"); 31 script.type = "text/javascript"; 32 script.src = '//api-maps.yandex.ru/2.1/?apikey=' + mapKey + '&lang=ru_RU'; 33 script.addEventListener('load', function () { 34 try { 35 if (document.getElementById(mapContainer)) { 36 ymaps.ready(initMap); 37 } 38 } catch (e) { 39 console.error('Yandex.Map not download!'); 40 } 41 }, false) 42 document.body.appendChild(script); 43} 44 45/** иниÑиализаÑÐ¸Ñ ÐºÐ°ÑÑÑ Ð¯Ð½Ð´ÐµÐºÑа */ 46function initMap() { 47 // ÐÑем кооÑдинаÑÑ ÑекÑÑего гоÑода 48 let cityCoords = $('.contacts').first().attr('data-coords').split(','); 49 // ÐниÑиализаÑÐ¸Ñ ÑÐ½Ð´ÐµÐºÑ ÐºÐ°ÑÑÑ 50 let contactMap = new ymaps.Map(mapContainer, { 51 controls: ['fullscreenControl'], 52 center: cityCoords, 53 zoom: 12 54 }); 55 contactMap.behaviors.disable('scrollZoom'); 56 contactMap.controls.add(new ymaps.control.ZoomControl({ 57 options: { 58 position: { 59 right: 10, 60 top: document.querySelector('#contacts__ymaps').offsetHeight / 2 - 206 61 } 62 } 63 })); 64 65 // ÐÑкÑÑваем заглÑÑÐºÑ Ð½Ð° ÑелеÑоне и планÑеÑе 66 if ($(window).width() < '1024') { 67 let wrapper = $('#contacts__windows'); 68 wrapper.removeClass('hidden'); 69 wrapper.on('click', function () { 70 wrapper.addClass('hidden'); 71 }); 72 } 73 74 // Создаем ÑпиÑок кооÑÐ´Ð¸Ð½Ð°Ñ 75 let coordsBranch = []; 76 $('.contacts__item[data-coords]').each(function () {
77 let coords = $(this).attr('data-coords').split(";").filter(coord => coord); 78 let address = $(this).attr('data-address').split(";").filter(address => address); 79 let type = $(this).attr('data-type'); // ÐолÑÑаем Ñип Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð¹ меÑки 80 81 coords.forEach((coord, index) => { 82 if (coordsBranch.indexOf(coords) === -1 && coord !== '') coordsBranch.push({ 83 coords: coord, 84 hint: address[index], 85 type: type 86 }); 87 }) 88 }); 89 90 // ÐÑли пÑиÑÑÑÑÑвÑÑÑ ÑÐ¸Ð»Ð¸Ð°Ð»Ñ Ð½Ð°ÑÑÑаиваем каÑÑÑ 91 if (coordsBranch.length) { 92 93 // Создаем коллекÑÐ¸Ñ Ð¼ÐµÑок ÑекÑÑÐ¸Ñ Ñилиалов 94 let currentBranches = new ymaps.GeoObjectCollection({}, { 95 preset: 'islands#blueIcon', 96 iconColor: '#dd514c', 97 // hintContent: "Ð¥Ð¸Ð½Ñ Ð¼ÐµÑки" 98 }); 99 100 // ÐаполнÑем коллекÑÐ¸Ñ 101 coordsBranch.forEach(function (item) { 102 const isExhibit = item.type === 'вÑÑÑавоÑнÑе обÑазÑÑ'; 103 104 currentBranches.add(new ymaps.Placemark( 105 item.coords.split(','), 106 { 107 hintContent: '<div class="contact-hint">' + 108 (item.type ? '<strong>' + item.type.charAt(0).toUpperCase() + item.type.slice(1) + '</strong><br>' : '') + 109 item.hint + 110 '</div>', 111 balloonContentBody: 112 '<b>' + (item.type ? item.type.charAt(0).toUpperCase() + item.type.slice(1) : '') + '</b>' + 113 (item.type ? ' <br>' : '') + 114 '<b>ÐдÑеÑ:</b> <br>' + item.hint 115 }, 116 { 117 preset: isExhibit ? 'islands#blueIcon' : 'islands#redIcon' 118 } 119 )); 120 }); 121 122 // ÐобавлÑем меÑки на каÑÑÑ 123 contactMap.geoObjects.add(currentBranches); 124 125 126 // function getCenter() { 127 // // ЦенÑÑиÑование каÑÑÑ 128 // if (currentBranches.getLength() > 1) 129 // contactMap.setBounds(currentBranches.getBounds(), {checkZoomRange: true, zoomMargin: 100}); 130 // else 131 // contactMap.setCenter(currentBranches.getBounds()[0], 17); 132 // } 133 134 135 function getCenter() { 136 // ÐаÑÑив Ñ ÐºÐ¾Ð¾ÑдинаÑами Ð´Ð»Ñ ÐоÑÐºÐ²Ñ (коÑÑÑлÑ, Ñак как пока не пÑидÑмал, как ÑÑо опÑимизиÑоваÑÑ) 137 let specificCoords = [ 138 "55.703574126952425,37.3561726111", // ÐооÑдинаÑÑ ÑоÑки в ÐоÑкве (коÑÑÑлÑ) 139 "55.709094,37.803506" // ÐÑе одна ÑоÑка в ÐоÑкве (коÑÑÑлÑ) 140 ]; 141 142 // ÐÑовеÑÑем, еÑÑÑ Ð»Ð¸ в coordsBranch Ñ Ð¾ÑÑ Ð±Ñ Ð¾Ð´Ð½Ð° кооÑдинаÑа, коÑоÑÐ°Ñ ÑооÑвеÑÑÑвÑÐµÑ ÑоÑкам из specificCoords 143 let foundCoords = coordsBranch.some(item => specificCoords.includes(item.coords)); 144 145 // ÐпÑеделÑем, ÑвлÑеÑÑÑ Ð»Ð¸ ÑекÑÑее ÑÑÑÑойÑÑво деÑкÑопом (ÑиÑина ÑкÑана болÑÑе 640px) 146 // ÐÑо важно, Ñак как на мобилÑнÑÑ ÑÑÑÑойÑÑÐ²Ð°Ñ Ð¼Ñ Ð½Ðµ Ñ Ð¾Ñим изменÑÑÑ ÑенÑÑ ÐºÐ°ÑÑÑ Ð¸Ð»Ð¸ зÑм 147 let isDesktop = window.innerWidth > 640; 148 149 // ÐÑли на каÑÑе болÑÑе одной ÑоÑки (Ñ.е. еÑÑÑ Ð½ÐµÑколÑко обÑекÑов), пÑименÑем меÑод Ð´Ð»Ñ ÑабоÑÑ Ñ Ð³ÑаниÑами каÑÑÑ 150 if (currentBranches.getLength() > 1) { 151 // УÑÑанавливаем гÑаниÑÑ ÐºÐ°ÑÑÑ, ÑÑиÑÑÐ²Ð°Ñ Ð²Ñе обÑекÑÑ, и добавлÑем оÑÑÑÑÐ¿Ñ Ð´Ð»Ñ ÑлÑÑÑенного оÑобÑÐ°Ð¶ÐµÐ½Ð¸Ñ 152 contactMap.setBounds(currentBranches.getBounds(), {checkZoomRange: true, zoomMargin: 100}); 153 154 // ÐÑли Ð½Ð°Ð¹Ð´ÐµÐ½Ñ Ð½ÑжнÑе кооÑдинаÑÑ Ð¸ ÑÑÑÑойÑÑво деÑкÑопное, ÑмеÑаем ÑенÑÑ ÐºÐ°ÑÑÑ 155 if (foundCoords && isDesktop) { 156 // ÐÑполÑзÑем setTimeout, ÑÑÐ¾Ð±Ñ Ð´Ð°ÑÑ ÐºÐ°ÑÑе вÑÐµÐ¼Ñ Ð½Ð° обновление пеÑед пÑименением изменений 157 setTimeout(() => { 158 // ÐолÑÑаем ÑекÑÑие кооÑдинаÑÑ ÑенÑÑа каÑÑÑ 159 let center = contactMap.getCenter(); 160 // СмеÑаем ÑенÑÑ ÐºÐ°ÑÑÑ Ð²Ð½Ð¸Ð· (по оÑи Y) на 0.2 и ÑменÑÑаем зÑм до 11, ÑÑÐ¾Ð±Ñ ÑвелиÑиÑÑ Ð¾Ð±Ð»Ð°ÑÑÑ Ð¾ÑобÑÐ°Ð¶ÐµÐ½Ð¸Ñ 161 contactMap.setCenter([center[0], center[1] - 0.2], 10); // СмеÑение ÑенÑÑа и зÑм Ð´Ð»Ñ ÐоÑÐºÐ²Ñ (коÑÑÑлÑ) 162 }, 500); // ÐадеÑжка Ð´Ð»Ñ Ð°ÑÐ¸Ð½Ñ Ñонного вÑÐ¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ 163 } 164 } else { 165 // ÐÑли на каÑÑе ÑолÑко одна ÑоÑка (один обÑекÑ), ÑÑÑанавливаем ÑенÑÑ ÐºÐ°ÑÑÑ Ð½Ð° ÑÑÑ ÑоÑÐºÑ Ñ Ð·Ñмом 17 166 contactMap.setCenter(currentBranches.getBounds()[0], 17); 167 168 // ÐÑли Ð½Ð°Ð¹Ð´ÐµÐ½Ñ Ð½ÑжнÑе кооÑдинаÑÑ Ð¸ ÑÑо деÑкÑоп, пÑименÑем Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ ÑенÑÑа каÑÑÑ 169 if (foundCoords && isDesktop) { 170 // УÑÑанавливаем задеÑжкÑ, ÑÑÐ¾Ð±Ñ ÐºÐ°ÑÑа ÑÑпела оÑобÑазиÑÑÑÑ 171 setTimeout(() => { 172 // ÐолÑÑаем ÑекÑÑий ÑенÑÑ ÐºÐ°ÑÑÑ 173 let center = contactMap.getCenter(); 174 // СмеÑаем ÑенÑÑ ÐºÐ°ÑÑÑ Ð½ÐµÐ¼Ð½Ð¾Ð³Ð¾ ввеÑÑ (по оÑи Y) на 0.02 и ÑвелиÑиваем зÑм до 15 175 // ÐÑо нÑжно Ð´Ð»Ñ Ñого, ÑÑÐ¾Ð±Ñ ÐºÐ°ÑÑа показÑвала более деÑалÑно ÑоÑкÑ, еÑли она в наÑем ÑпиÑке 176 contactMap.setCenter([center[0], center[1] + 0.02], 15); // СмеÑение ÑенÑÑа и зÑм Ð´Ð»Ñ ÐоÑÐºÐ²Ñ (коÑÑÑлÑ) 177 }, 500); // ÐадеÑжка Ð´Ð»Ñ Ð°ÑÐ¸Ð½Ñ Ñонного вÑÐ¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ 178 } 179 } 180 } 181 182 183 // ЦенÑÑиÑÑем каÑÑÑ 184 getCenter(); 185 186 } 187}
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.