我正在尝试比较两个对象数组,每个数组使用 lodash 的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;
}
