Я пытаюсь сравнить два массива объектов, каждый из которых имеет два объекта, используя метод loda sh isEqual
. Свойства, которые отличаются, вероятно, наследуются. Это ложно сообщает правду. Я также сравнил только первый элемент массива (только для сравнения объектов), и он также сообщает, что они равны:
Сравнение этих двух массивов или первый элемент каждого массива с isEqual
сообщает true
. Вы можете видеть, что координаты в свойстве points разные, так почему он говорит, что они равны? Это потому, что очки наследуются? Объект является polylineOverlay
описанным здесь .
Кроме того, преобразование каждого из них в простой объект всегда сообщает об ошибке, даже если они одинаковы (насколько я могу судить).
Объекты показаны на изображении (newRunInArrow
и runInArrow
). Код прост:
const trueRunIn = settings.magneticRunIn + magVar;
const boundingRegion = map.region.toBoundingRegion();
const style = new mapkit.Style({
lineWidth: 5,
lineJoin: 'round',
strokeColor: '#FFF',
});
const newRunInArrow = createArrow(boundingRegion, trueRunIn, style);
const areEqual = isEqualWith(runInArrow[0], newRunInArrow[0])
&& isEqualWith(runInArrow[1], newRunInArrow[1]);
console.log('areEqual', areEqual); // Returns true
или
const areEqual = isEqualWith(runInArrow, newRunInArrow)
console.log('areEqual', areEqual); // Returns true
Выполнение пробега в стрелке
export function createArrow(
boundingRegion: mapkit.BoundingRegion,
runInHeading: number,
style: mapkit.Style,
): mapkit.PolylineOverlay[] {
const { smallestRadius, largestRadius } = getRadii(boundingRegion);
const arrowLength = largestRadius / 3;
const arrowPointLength = arrowLength / 4;
const arrowOffset = largestRadius / 8;
let arrowTipFromCenter = largestRadius - arrowLength - arrowOffset;
if (arrowTipFromCenter + arrowPointLength > smallestRadius) arrowTipFromCenter = smallestRadius - arrowPointLength;
const { center } = boundingRegion.toCoordinateRegion();
const topOfArrow = computeDestinationPoint(
{ latitude: center.latitude, longitude: center.longitude },
arrowTipFromCenter,
runInHeading - 180,
);
const bottomOfArrow = computeDestinationPoint(topOfArrow, arrowLength, runInHeading - 180, 6371000);
const corner1 = computeDestinationPoint(topOfArrow, arrowPointLength, runInHeading - 135);
const corner2 = computeDestinationPoint(topOfArrow, arrowPointLength, runInHeading - 225);
const points = [
[
new mapkit.Coordinate(bottomOfArrow.latitude, bottomOfArrow.longitude),
new mapkit.Coordinate(topOfArrow.latitude, topOfArrow.longitude),
new mapkit.Coordinate(corner1.latitude, corner1.longitude),
],
[
new mapkit.Coordinate(topOfArrow.latitude, topOfArrow.longitude),
new mapkit.Coordinate(corner2.latitude, corner2.longitude),
],
];
const newRunInArrow = [
new mapkit.PolylineOverlay(points[0], {
style,
}),
new mapkit.PolylineOverlay(points[1], {
style,
}),
];
return newRunInArrow;
}