Answer the question
In order to leave comments, you need to log in
How to find out the coordinates of which point on the multiroute have changed (yandex maps)?
Good day. Interested in the question of how to find out what changes have occurred on the route when editing it.
I found an event when changing the route, but I can’t find exactly what changes (with which points) occurred.
How can I find these changes?
So far I've implemented it like this:
class Ymap {
constructor(mapId) {
this.points = undefined;
this.map = undefined;
ymaps.ready(() => {
this.map = new ymaps.Map(mapId, { center: [58, 40], zoom: 7, controls: []});
});
this.AddMultiRoute([]);
}
AddMultiRoute(geoPoints) {
ymaps.ready(() => {
this.multiRoute = new ymaps.multiRouter.MultiRoute({
referencePoints: geoPoints
}, {
// Тип промежуточных точек, которые могут быть добавлены при редактировании.
editorMidPointsType: "via",
// В режиме добавления новых путевых точек запрещаем ставить точки поверх объектов карты.
editorDrawOver: false
});
this.map.geoObjects.add(this.multiRoute);
});
}
MultiRouteUpdate(func) {
ymaps.ready(() => {
this.multiRoute.events.add('update',
function (e) {
Func(e.get('target').model.getReferencePoints(), this.points);
this.points = e.get('target').model.getReferencePoints();
});
});
}
}
Answer the question
In order to leave comments, you need to log in
this.points = e.get('target').model.getReferencePoints();
function comparison(newPoints, oldPoints) {
const
oldPoint = oldPoints.find(n => !newPoints.includes(n)),
newPoint = newPoints.find(n => !oldPoints.includes(n));
if (oldPoint && newPoint) {
console.log('update', oldPoint, 'to', newPoint);
} else if (oldPoint) {
console.log('delete', oldPoint);
} else if (newPoint) {
console.log('create', newPoint);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question