Found such an example of code from the comments to the question - Smooth moving of the Yandex map on click
I substituted my values ββin the data-goto = "ΠΠΈΠ΅Π²" and everything stopped working.
The question is how can I configure the map switching by clicking on the link (address via data-goto ) and how to place a custom marker on the map with this same address?
I suspect that the conclusion of the marker can be done somehow
myPlacemark2 = new ymaps.Placemark(destinations['ΠΠΈΠ΅Π²'], { balloonContent: ... But something in any way I will not connect something with destinations[data-goto] .
//ΠΠΎΠΆΠ΄ΡΠΌΡΡ Π·Π°Π³ΡΡΠ·ΠΊΠΈ API ΠΈ Π³ΠΎΡΠΎΠ²Π½ΠΎΡΡΠΈ DOM. ymaps.ready(init); function init() { var result = document.getElementById('result'), // Π΄Π»Ρ ΠΎΡΠ»Π°Π΄ΠΊΠΈ // Π² ΡΡΠΎΠΉ Π²Π΅ΡΡΠΈΠΈ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΠΏΡΠΎΡΡΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° (ΠΈ ΠΎΠ½ΠΈ ΠΏΠΎΠΌΠ΅Π½ΡΠ½Ρ ΠΌΠ΅ΡΡΠ°ΠΌΠΈ) destinations = { 'ΠΠΎΡΠΊΠ²Π°': [55.753559, 37.609218], 'Π‘Π°Π½ΠΊΡ-ΠΠ΅ΡΠ΅ΡΠ±ΡΡΠ³': [59.938531, 30.313497], 'ΠΠΊΠ°ΡΠ΅ΡΠΈΠ½Π±ΡΡΠ³': [56.829748, 60.617435], 'ΠΠ΄Π΅ΡΡΠ°': [46.466444, 30.7058] }, // Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΡΠΊΠ·Π΅ΠΌΠΏΠ»ΡΡΠ° ΠΊΠ°ΡΡΡ ΠΈ Π΅Π³ΠΎ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠ° ΠΊ ΠΊΠΎΠ½ΡΠ΅ΠΉΠ½Π΅ΡΡ Ρ // Π·Π°Π΄Π°Π½Π½ΡΠΌ id ("map"). myMap = new ymaps.Map('map', { // ΠΡΠΈ ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ ΠΊΠ°ΡΡΡ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΠΎ Π½ΡΠΆΠ½ΠΎ ΡΠΊΠ°Π·Π°ΡΡ // Π΅Ρ ΡΠ΅Π½ΡΡ ΠΈ ΠΊΠΎΡΡΡΠΈΡΠΈΠ΅Π½Ρ ΠΌΠ°ΡΡΡΠ°Π±ΠΈΡΠΎΠ²Π°Π½ΠΈΡ. center: destinations['ΠΠΎΡΠΊΠ²Π°'], // ΠΠΎΡΠΊΠ²Π° zoom: 10 }); // Π²ΡΠ΅ ΠΎΠΊ result.textContent = 'map init'; // ΠΊΡΠ΄Π° ΡΠΊΠ°ΠΊΠ°ΡΡ function clickGoto() { // Π³ΠΎΡΠΎΠ΄ var pos = this.getAttribute('data-goto'); // ΠΈΠ»ΠΈ this.getAttribute('title') result.textContent = pos; // ΠΏΠ΅ΡΠ΅Ρ
ΠΎΠ΄ΠΈΠΌ ΠΏΠΎ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΠ°ΠΌ myMap.panTo(destinations[pos], { flying: 1 }); return false; } // Π½Π°Π²Π΅ΡΠΈΠ²Π°Π΅ΠΌ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ var col = document.getElementsByClassName('goto'); for (var i = 0, n = col.length; i < n; ++i) { col[i].onclick = clickGoto; result.textContent = result.textContent + ' ' + i; } } <script src="http://api-maps.yandex.ru/2.1/?load=package.standard&lang=ru-RU" type="text/javascript"></script> <div id="map" style="width:400px; height:300px"></div> <a href=\"#\" class="goto" data-goto="ΠΠΎΡΠΊΠ²Π°" title="ΠΠΎΡΠΊΠ²Π°">ΠΠ΅ΡΠ΅ΠΉΡΠΈ</a><br> <a href=\"#\" class="goto" data-goto="ΠΠΈΠ΅Π²" title="ΠΠΈΠ΅Π²">ΠΠ΅ΡΠ΅ΠΉΡΠΈ</a><br> <a href=\"#\" class="goto" data-goto="ΠΠΊΠ°ΡΠ΅ΡΠΈΠ½Π±ΡΡΠ³" title="ΠΠΊΠ°ΡΠ΅ΡΠΈΠ½Π±ΡΡΠ³">ΠΠ΅ΡΠ΅ΠΉΡΠΈ</a><br> <a href=\"#\" class="goto" data-goto="ΠΠ΄Π΅ΡΡΠ°" title="ΠΠ΄Π΅ΡΡΠ°">ΠΠ΅ΡΠ΅ΠΉΡΠΈ</a> <div id="result"></div> So the non-click custom icon does not work at all:
//ΠΠΎΠΆΠ΄ΡΠΌΡΡ Π·Π°Π³ΡΡΠ·ΠΊΠΈ API ΠΈ Π³ΠΎΡΠΎΠ²Π½ΠΎΡΡΠΈ DOM. ymaps.ready(init); function init() { // Π² ΡΡΠΎΠΉ Π²Π΅ΡΡΠΈΠΈ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΠΏΡΠΎΡΡΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° (ΠΈ ΠΎΠ½ΠΈ ΠΏΠΎΠΌΠ΅Π½ΡΠ½Ρ ΠΌΠ΅ΡΡΠ°ΠΌΠΈ) destinations = { 'ΠΠΎΡΠΊΠ²Π°': [55.753559, 37.609218], 'Π‘Π°Π½ΠΊΡ-ΠΠ΅ΡΠ΅ΡΠ±ΡΡΠ³': [59.938531, 30.313497], 'ΠΠΊΠ°ΡΠ΅ΡΠΈΠ½Π±ΡΡΠ³': [56.829748, 60.617435], 'ΠΠ΄Π΅ΡΡΠ°': [46.466444, 30.7058] }, // Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΡΠΊΠ·Π΅ΠΌΠΏΠ»ΡΡΠ° ΠΊΠ°ΡΡΡ ΠΈ Π΅Π³ΠΎ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠ° ΠΊ ΠΊΠΎΠ½ΡΠ΅ΠΉΠ½Π΅ΡΡ Ρ // Π·Π°Π΄Π°Π½Π½ΡΠΌ id ("map"). myMap = new ymaps.Map('map', { center: destinations['ΠΠΎΡΠΊΠ²Π°'], zoom: 10, controls: [] }); // ΠΊΡΠ΄Π° ΡΠΊΠ°ΠΊΠ°ΡΡ function clickGoto() { // Π³ΠΎΡΠΎΠ΄ var pos = this.getAttribute('data-goto'); // ΠΈΠ»ΠΈ this.getAttribute('title') result.textContent = pos; // ΠΏΠ΅ΡΠ΅Ρ
ΠΎΠ΄ΠΈΠΌ ΠΏΠΎ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΠ°ΠΌ myMap.panTo(destinations[pos], { flying: 1 }); return false; } // Π½Π°Π²Π΅ΡΠΈΠ²Π°Π΅ΠΌ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ var col = document.getElementsByClassName('goto'); for (var i = 0, n = col.length; i < n; ++i) { col[i].onclick = clickGoto; result.textContent = result.textContent + ' ' + i; } var myPlacemark = new ymaps.Placemark(destinations['ΠΠΎΡΠΊΠ²Π°'], { }, { iconImageHref: 'map-icon.png', iconImageSize: [79, 96], iconImageOffset: [0, -50], }); /* ΠΠΎΠ±Π°Π²Π»ΡΠ΅ΠΌ */ myMap.geoObjects .add(myPlacemark); } <script src="http://api-maps.yandex.ru/2.1/?load=package.standard&lang=ru-RU" type="text/javascript"></script> <div id="map" style="width:400px; height:300px"></div> <a href=\"#\" class="goto" data-goto="ΠΠΎΡΠΊΠ²Π°" title="ΠΠΎΡΠΊΠ²Π°">ΠΠ΅ΡΠ΅ΠΉΡΠΈ</a><br> <a href=\"#\" class="goto" data-goto="ΠΠΈΠ΅Π²" title="ΠΠΈΠ΅Π²">ΠΠ΅ΡΠ΅ΠΉΡΠΈ</a><br> <a href=\"#\" class="goto" data-goto="ΠΠΊΠ°ΡΠ΅ΡΠΈΠ½Π±ΡΡΠ³" title="ΠΠΊΠ°ΡΠ΅ΡΠΈΠ½Π±ΡΡΠ³">ΠΠ΅ΡΠ΅ΠΉΡΠΈ</a><br> <a href=\"#\" class="goto" data-goto="ΠΠ΄Π΅ΡΡΠ°" title="ΠΠ΄Π΅ΡΡΠ°">ΠΠ΅ΡΠ΅ΠΉΡΠΈ</a> <div id="result"></div> Help please solve the problem !!!
All addresses are not known in advance, they will be edited only through the data attribute and not through a script, so it makes no sense to manually register all addresses at destinations .
In general, there are links with addresses such as string, map. How to display the desired address on the map by clicking on the link with this same address?
destinations['ΠΠΈΠ΅Π²']to work, you need at least that thesedestinations['ΠΠΈΠ΅Π²']exist. - br3t