Answer the question
In order to leave comments, you need to log in
Yandex.Maps (API v.2) - how to get data on regions added to the map?
Suppose regions have been added to the map, as follows:
ymaps.regions.load('RU', {
lang: 'ru',
quality: 1
}).then(function (result) {
var regions = result.geoObjects;
myMap.geoObjects.add(regions);
});
regions.each(function (reg) {
if (reg.properties.get('name') == 'Какой-то регион') {
myMap.setBounds(reg.geometry.getBounds());
...
}
});
Answer the question
In order to leave comments, you need to log in
The method is used to traverse the collection of GeoObjects
Inside the method, you can already check if the current object is a region and perform the desired action.
This is not very convenient if there are a lot of objects on the map.
An alternative would be to add all regions to a separate layer:
To do this, a new object of type geoObjectCollection is created, all regions are added to it.
After that, we simply call the each method and get only the regions. Method information:
geoObjectCollection yandex maps api
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question