O
O
Obivankinobi2017-02-05 02:19:22
JavaScript
Obivankinobi, 2017-02-05 02:19:22

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

1 answer(s)
D
dmz9, 2017-02-05
@Obivankinobi

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');
          });

"field" state is monitored.
documentation for it is here https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/refe...
where the description plate is written on the right that in addition to "drawing" there is also the "editing" property, i.e. e. the state is "editing", and it is of boolean type.
in handlers that are hung on properties, it seems like not only newValue is passed, but oldValue should also be passed, put it in the function call as the second argument and check it out or not.
the end of editing is if newValue==false, oldValue==true, this will, in theory, be the end of creation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question