Answer the question
In order to leave comments, you need to log in
How to return the old label in Yandex maps?
Greetings. Tell me how to return the old mark on the map? Currently, when you click on a label, its icon changes to another one. When closing the balloon, it is necessary to return the previous icon
ymaps.ready(function () {
// Create map
var myMap = new ymaps.Map("m-map", {
center: [55.75396, 37.620393],
zoom: 10
});
var myCollection = new ymaps.GeoObjectCollection();
myMap.events.add('balloonopen', function (e) {
var balloon = e.get('balloon');
myMap.events.add('click', function (e) {
if(e.get('target') === myMap) {
balloon.close();
}
});
});
// Add buttons and placemarks
var offset_left = width>=640 ? margin + 63 : 20;
myMap.controls.add('zoomControl', {top: '45px', left: offset_left +'px', height: '50px'});
//myMap.controls.add(new ymaps.control.SmallZoomControl());
$.each(markArray, function(index, element){
var left = element.left;
var right = element.right;
var iconImageHref = element.iconImageHref;
var hintContent = element.hintContent;
var help_hint = element.help_hint;
var balloonContent = element.balloonContent;
var myPlacemark = new ymaps.Placemark([left, right], {
hintContent: hintContent,
help_hint: help_hint,
balloonContent: balloonContent
}, {
iconImageHref: iconImageHref,
iconImageSize: [26, 43],
iconImageOffset: [-8, -26],
hideIconOnBalloonOpen: false
});
// Add placemarks
myCollection.add(myPlacemark);
myPlacemark.events.add('click', function (e) {
e.get('target').options.set({iconImageHref: 'static/img/marker-orange.png'});
});
});
myMap.geoObjects.add(myCollection);
var bounds = myCollection.getBounds();
myMap.setBounds(bounds,{ checkZoomRange: true, zoomMargin: 50,
callback: function(err) {
if (!err) {
//myMap.setZoom(myMap.getZoom()-1);
}
}
});
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question