From 564b20bb1821d5c7b77361b65c632234893f629e Mon Sep 17 00:00:00 2001
From: jinglun-cloud <jinglun2019@foxmail.com>
Date: 星期三, 06 五月 2026 08:42:46 +0800
Subject: [PATCH] 简化默认设备长宽逻辑
---
src/main/webapp/static/js/basMap/mapTrackGeometry.js | 109 ++++++++++++++----------------------------------------
1 files changed, 29 insertions(+), 80 deletions(-)
diff --git a/src/main/webapp/static/js/basMap/mapTrackGeometry.js b/src/main/webapp/static/js/basMap/mapTrackGeometry.js
index 6545496..f7ad23b 100644
--- a/src/main/webapp/static/js/basMap/mapTrackGeometry.js
+++ b/src/main/webapp/static/js/basMap/mapTrackGeometry.js
@@ -67,7 +67,13 @@
}
function safeParseJson(text) {
- if (!text || typeof text !== 'string') {
+ if (!text) {
+ return null;
+ }
+ if (typeof text === 'object') {
+ return text;
+ }
+ if (typeof text !== 'string') {
return null;
}
try {
@@ -75,38 +81,6 @@
} catch (e) {
return null;
}
- }
-
- /** @param {string|object|null|undefined} raw */
- function parseDeviceFormValue(raw) {
- if (!raw) {
- return null;
- }
- if (typeof raw === 'object') {
- return raw;
- }
- return safeParseJson(raw);
- }
-
- /**
- * 璁惧闀垮锛氭湁 `deviceLength`/`deviceWidth` 鍒欑敤鍍忕礌鍊硷紝鍚﹀垯鐢ㄨ建閬撹嚜鍔ㄥ昂瀵搞��
- * @param {object|null|undefined} item
- * @param {number} fallbackAlong
- * @param {number} fallbackAcross
- * @returns {{ along: number, across: number }}
- */
- function normalizeDeviceSizeOverride(item, fallbackAlong, fallbackAcross) {
- if (!item) {
- return { along: fallbackAlong, across: fallbackAcross };
- }
- var overrideAlong = Math.round(Number(item.deviceLength));
- var overrideAcross = Math.round(Number(item.deviceWidth));
- var along = isFinite(overrideAlong) && overrideAlong > 0 ? overrideAlong : fallbackAlong;
- var across = isFinite(overrideAcross) && overrideAcross > 0 ? overrideAcross : fallbackAcross;
- return {
- along: Math.max(2, along),
- across: Math.max(2, across)
- };
}
function getNormalizeAngle(angle, startAngle, endAngle) {
@@ -241,28 +215,9 @@
var ANNULUS_INSET_MIN_PIXELS = 5;
/**
- * 鐩寸嚎杞ㄩ亾涓婅澶囧浘鏍囧儚绱犲昂瀵革紙娌胯建閬撴柟鍚� 脳 鍨傜洿杞ㄩ亾鏂瑰悜锛夈��
- * 涓� drawCrnDeviceGraphics / drawRgvDeviceGraphics 鐨� width銆乭eight 璇箟涓�鑷达紝涓嶅啀鍦ㄥ埆澶勫仛銆屽啀涔� 2銆嶃��
- * @param {{ width: number, height: number }} rect 杞ㄩ亾澶栨帴鐭╁舰
- * @param {"crn"|"dualCrn"|"rgv"} trackType
- * @returns {{ along: number, across: number }}
- */
- function getDevicePixelBoxForTrack(rect, trackType) {
- var shortLen = Math.min(rect.width, rect.height);
- var across = shortLen;
- var along = shortLen * 2;
- along = Math.round(along * TRACK_DEVICE_BOX_SCALE);
- across = Math.round(across * TRACK_DEVICE_BOX_SCALE);
- return {
- along: Math.max(2, along),
- across: Math.max(2, across)
- };
- }
-
- /**
* 杞ㄩ亾涓婅澶囥�岃嚜鍔ㄣ�嶅儚绱犲昂瀵革紙娌胯建閬撴柟鍚� 脳 鍨傜洿杞ㄩ亾鏂瑰悜锛夈��
- * - 鐩寸嚎杞ㄩ亾锛氭潵鑷� getDevicePixelBoxForTrack
- * - 鐜┛锛氭寜鍘嗗彶閫昏緫缂╂斁鍒� shortLength 鐨� 15%
+ * 鐩寸嚎杞ㄩ亾锛氱煭杈� 脳 TRACK_DEVICE_BOX_SCALE 涓� across锛宎long 涓哄叾 2 鍊嶏紙涓� drawCrnDeviceGraphics / drawRgvDeviceGraphics 涓�鑷达級銆�
+ * 鐜┛锛氬厛鎸夊悓涓婂緱鍒板熀鍑嗙洅锛屽啀缂╂斁鍒扮煭杈圭殑 15%銆�
* @param {{ type: string, width: number, height: number, pathList?: any[] }} rect
* @returns {{ along: number, across: number } | null}
*/
@@ -275,23 +230,24 @@
if (!isFinite(rectW) || !isFinite(rectH) || rectW <= 0 || rectH <= 0) {
return null;
}
+ var shortLen = Math.min(rectW, rectH);
+ var across = Math.round(shortLen * TRACK_DEVICE_BOX_SCALE);
+ var along = Math.round(shortLen * 2 * TRACK_DEVICE_BOX_SCALE);
if (rect.type === 'annulus') {
- var shortLength = Math.min(rectW, rectH);
- var box = getDevicePixelBoxForTrack({ width: shortLength, height: shortLength }, 'rgv');
- var scale = (shortLength * 0.15) / box.across;
+ var scale = (shortLen * 0.15) / across;
return {
- along: Math.max(2, Math.round(box.along * scale)),
- across: Math.max(2, Math.round(box.across * scale))
+ along: Math.max(2, Math.round(along * scale)),
+ across: Math.max(2, Math.round(across * scale))
};
}
- return getDevicePixelBoxForTrack({ width: rectW, height: rectH }, rect.type);
+ return { along, across };
}
function getDeviceInfo(rect) {
var isHorizontal = rect.width > rect.height;
var longLength = isHorizontal ? rect.width : rect.height;
var shortLength = isHorizontal ? rect.height : rect.width;
- var deviceForm = parseDeviceFormValue(rect.value);
+ var deviceForm = safeParseJson(rect.value);
if (!deviceForm || !deviceForm.deviceList || deviceForm.deviceList.length === 0) {
return deviceForm;
}
@@ -302,7 +258,6 @@
return deviceForm;
}
var allDistance = getAllDistance(pathList);
- var autoBox = getAutoTrackDeviceBox(rect);
var ab = annulusBandContext(rect, rect.shape || 'rect');
deviceForm.deviceList.forEach(function (item) {
var deltaDistance = (allDistance * item.progress) / 100;
@@ -323,35 +278,30 @@
ab.inset,
ab.refInside
);
- var fallbackAlong = autoBox ? autoBox.along : Math.max(2, Math.round(shortLength * 0.3));
- var fallbackAcross = autoBox ? autoBox.across : Math.max(2, Math.round(shortLength * 0.15));
- var size = normalizeDeviceSizeOverride(item, fallbackAlong, fallbackAcross);
- var width = size.along;
- var height = size.across;
+
item.x = centered.x;
item.y = centered.y;
item.path = moved.path;
- item.width = width;
- item.height = height;
+ item.width = item.deviceLength;
+ item.height = item.deviceWidth;
});
return deviceForm;
}
- var box = getAutoTrackDeviceBox(rect) || getDevicePixelBoxForTrack(rect, rect.type);
+ // 绾挎杞ㄩ亾
deviceForm.deviceList.forEach(function (item) {
- var size = normalizeDeviceSizeOverride(item, box.along, box.across);
- var inset = (shortLength - size.across) / 2;
+ var inset = (shortLength - item.deviceLength) / 2;
var distance = (item.progress * (longLength - 2 * shortLength)) / 100;
if (isHorizontal) {
item.x = rect.x + distance;
item.y = rect.y + inset;
- item.width = size.along;
- item.height = size.across;
+ item.width = item.deviceLength;
+ item.height = item.deviceWidth;
} else {
item.x = rect.x + inset;
item.y = rect.y + distance;
- item.width = size.across;
- item.height = size.along;
+ item.width = item.deviceLength;
+ item.height = item.deviceWidth;
}
});
return deviceForm;
@@ -618,7 +568,7 @@
// var shortLen = Math.min(Number(sprite.width) || 0, Number(sprite.height) || 0);
// var fallbackAlong = box ? box.along : Math.max(2, Math.round(shortLen * 0.3));
// var fallbackAcross = box ? box.across : Math.max(2, Math.round(shortLen * 0.15));
- // var form = parseDeviceFormValue(sprite && sprite.value);
+ // var form = safeParseJson(sprite && sprite.value);
// var across = fallbackAcross;
// console.log('fallbackAcross', across);
// if (form && form.deviceList && form.deviceList.length) {
@@ -1134,8 +1084,8 @@
/**
* 鍫嗗灈鏈� / 鍙屽伐浣嶈澶囧浘鏍囷紙涓� MapCanvas#createCrnTexture / createCrnTextureColoredDevice 涓�鑷达級
* @param {PIXI.Graphics} g
- * @param {number} deviceWidth 鍥炬爣鎬诲锛堝儚绱狅紝涓� getDevicePixelBoxForTrack.along 涓�鑷达級
- * @param {number} deviceHeight 鍥炬爣鎬婚珮锛堜笌 getDevicePixelBoxForTrack.across 涓�鑷达級
+ * @param {number} deviceWidth 鍥炬爣鎬诲锛堝儚绱狅紝涓� getAutoTrackDeviceBox.along 涓�鑷达級
+ * @param {number} deviceHeight 鍥炬爣鎬婚珮锛堜笌 getAutoTrackDeviceBox.across 涓�鑷达級
* @param {number} bodyColor 椹鹃┒鑸卞~鍏呰壊
*/
function drawCrnDeviceGraphics(g, deviceWidth, deviceHeight, bodyColor) {
@@ -1213,7 +1163,6 @@
getPositionAfterMove: getPositionAfterMove,
getAllDistance: getAllDistance,
getDeviceInfo: getDeviceInfo,
- getDevicePixelBoxForTrack: getDevicePixelBoxForTrack,
getAutoTrackDeviceBox: getAutoTrackDeviceBox,
getLShapePointList: getLShapePointList,
getIsStillHalf: getIsStillHalf,
--
Gitblit v1.9.1