Answer the question
In order to leave comments, you need to log in
How to track the creation of a polygon on a Yandex map?
Good evening!
There was a need to mark the area with a polygon on the map with balloons. During creation and after which you need to always look for points inside the area. I understood how to search during creation, but how to reset the event after the creation is completed and hang up a new one is not clear.
This listener is listening when creating myPolygon.editor.events.add("vertexadd");
After creating the polygon, you need to hang this listener myPolygon.events.add('geometrychange');
Here's how to track the end of creation and change the listener?)
var myPolygon = new ymaps.Polygon([], {}, {
// Курсор в режиме добавления новых вершин.
editorDrawingCursor: "crosshair",
// Максимально допустимое количество вершин.
editorMaxPoints: 5,
// Цвет заливки.
fillColor: '#00FF00',
// Цвет обводки.
strokeColor: '#0000FF',
// Ширина обводки.
strokeWidth: 5
});
var stateMonitor = new ymaps.Monitor(myPolygon.editor.state);
stateMonitor.add("drawing", function (newValue) {
myPolygon.options.set("strokeColor", newValue ? '#FF0000' : '#0000FF');
});
var eventer;
eventer = myPolygon.editor.events.add("vertexadd", function (event) {
var storage = ymaps.geoQuery(myMap2.geoObjects);
var objectsInsidePoly = storage.searchInside(myPolygon);
objectsInsidePoly.each(function(pm){
//что-то делаем
});
myPolygon.editor.startDrawing();
Answer the question
In order to leave comments, you need to log in
if you look closely, monitoring of the state of the polygon editor is added in the code.
var stateMonitor = new ymaps.Monitor(myPolygon.editor.state);
stateMonitor.add("drawing", function (newValue) {
myPolygon.options.set("strokeColor", newValue ? '#FF0000' : '#0000FF');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question