O
O
Obivankinobi2017-02-25 14:45:12
JavaScript
Obivankinobi, 2017-02-25 14:45:12

How to close a polyline on Yandex maps?

Good afternoon!
The task is to make a polyline editor on the Yandex map, with the ability to close the line when clicking on the first vertex.
Actually, I thought of doing it only through the menu item that appears when you click on the top.
But I don’t understand how to do it without clicking ((

var myPolyline = new ymaps.Polyline([], {}, {
             fillColor: '#7df9ff33',
          fillOpacity: 0.5,
              strokeColor: '#0000FF',
          strokeOpacity: 0.5,
          strokeWidth: 2,
          editorDrawingCursor: "crosshair",
              // Добавляем в контекстное меню новый пункт, позволяющий удалить ломаную.
              editorMenuManager: function (items) {
              	var items = [];
                  items.push({
                      title: "Удалить QQQ линию",
                     onClick:  function () {
                      myPolygon = new     ymaps.Polygon([myPolyline.editor.geometry.getCoordinates()], {}, {});
        		 	myMap2.geoObjects.remove(myPolyline);
        		 	myMap2.geoObjects.add(myPolygon);
        		 	
        		 	var forfilter = [];
             	var objectsInsideLine = storage.searchInside(myPolygon);
                  objectsInsideLine.each(function(pm){
                    	forfilter.push(pm.idnakarte);
                    });
                      }
                  });
                  return items;
              }
          });
// При добавлении отслеживается добавление вершин, но как реализовать задуманное я не понял еще..

         myPolyline.editor.events.add("vertexadd", function (event) {
         	t++;
         	console.log("fff =" + t);
         	if(t === 1){
         		var coords = myPolyline.geometry.getCoordinates()

         		var myPlacemark1 = new ymaps.Placemark(coords[0], {
                    balloonContent: 'Маленькая иконка'
                }, {});

         		myMap2.geoObjects.add(myPlacemark1);
         			
         		}
         })

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question