Answer the question
In order to leave comments, you need to log in
How to check whether a label is in polygons?
Hello comrades! Please help me figure it out.
There is a collection (GeoObjectCollection) in which polygons (Polygon) are stored. I'm trying to check if a Placemark is in a polygon. What is the correct way to do this in my particular case? I found the each
method
in the documentation , which was supposed to iterate over all the elements of the collection. The below code doesn't work. What am I doing wrong?
self.polygonCollection.each(function (polygon) {
if(polygon.contains(res.geometry.getCoordinates())) {
console.log("Метка входит в полигон.")
}
});
Answer the question
In order to leave comments, you need to log in
Found the problem. The correct code looks like this:
self.polygonCollection.each(function(polygon) {
if (polygon.geometry.contains(res.geometry.getCoordinates())) {
console.log("Метка входит в полигон.")
}
});
Try ditching jQuery and moving to forEach :
self.polygonCollection.forEach(function(polygon, i, arr) {
if(polygon.contains(res.geometry.getCoordinates())) {
console.log("Метка входит в полигон.")
}
});
$.each(self.polygonCollection, function (key, polygon) {
if(polygon.contains(res.geometry.getCoordinates())) {
console.log("Метка входит в полигон.")
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question