[[+content_image]]
A
A
Anton2021-11-19 14:10:19
JavaScript
Anton, 2021-11-19 14:10:19

Determining whether a label occurs in a collection of polygons?

Kind people. Faced a problem.

A collection of city area polygons is added to the map.

var myCollection = new ymaps.GeoObjectCollection();

 p9 = new ymaps.Polygon([[[33.9967073,45.0188305],[33.9967957,45.0146412],[33.9982684,45.0144175],[33.9990598,45.0152349],[34.0044352,45.0155271],[34.0049901,45.0171008],[34.0059437,45.0189984],[34.006411,45.0211516],[34.006432,45.0215641],[34.0060948,45.0214767],[34.0061177,45.0240635],[34.0009129,45.0240516],[33.9983283,45.0239652],[33.9979934,45.0235538],[33.9970247,45.0210183],[33.9967073,45.0188305]]], {hintContent: "район Аэрофлотский",balloonContentHeader: 'header',balloonContentBody: 'body',balloonContentFooter: 'footer', }, { fillColor: '#00FF00', fillOpacity: 0.3, strokeColor: '#00FF00', opacity: 1, zIndex: 20, strokeWidth: 2, strokeStyle: 'solid', strokeOpacity: 0.9 });

myCollection.add(p9);
            
p10 = new ymaps.Polygon([[[34.0347518,44.9954807],[34.0378191,44.9909103],[34.0397733,44.9888502],[34.0408051,44.9889261],[34.0409147,44.9928598],[34.0449782,44.9895491],[34.04526,44.9897],[34.0502774,44.9932948],[34.0472859,44.9959956],[34.0386682,44.9996306],[34.0347518,44.9954807]]], { hintContent: "район Центральный",balloonContentHeader: 'header',balloonContentBody: 'body',balloonContentFooter: 'footer',}, { fillColor: '#0000FF', fillOpacity: 0.3, strokeColor: '#0000FF', opacity: 1, zIndex: 1, strokeWidth: 2, strokeStyle: 'solid', strokeOpacity: 0.9 });

myCollection.add(p10);

myMap.geoObjects.add(myCollection);


The user then adds a marker on the map.

var placemark = new ymaps.Placemark([34.0044352,45.0155271], { 'hintContent': yandex_coordinats, 'balloonContent': 'Район Аэрофлотский'  }, {  'preset': 'islands#redDotIcon' });

myMap.geoObjects.add(placemark);


How can I alert() or understand that the label is in one of the polygons and in which polygon? I've been sitting here since morning, scratching my head.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
F
freeExec, 2021-11-19
Veida @aveyda7

geoQuery + Contains

D
Dymok, 2021-11-19
@UnluckySerivelha

Should help:
https://yandex.ru/dev/maps/jsbox/2.1/delivery_zones/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question