Filter invalid NMC wind placeholders from map labels

This commit is contained in:
2569718930@qq.com
2026-04-07 13:02:45 +08:00
parent 22621f5d9c
commit 0bb3b573e1
2 changed files with 16 additions and 4 deletions
+7 -2
View File
@@ -78,6 +78,11 @@ function createMarkerIcon(
}
function buildNearbyIconHtml(detail: CityDetail, station: NearbyStation) {
const sanitizeWindText = (value?: string | null) => {
const text = String(value || "").trim();
if (!text || text === "9999") return "";
return text;
};
const symbol = detail.temp_symbol || "°C";
const rawLabel =
station.station_label ||
@@ -92,8 +97,8 @@ function buildNearbyIconHtml(detail: CityDetail, station: NearbyStation) {
? String(rawLabel).replace(/\s*\(NMC\)$/i, "区域实况 (NMC)")
: rawLabel;
let windHtml = "";
const windDirectionText = String(station.wind_direction_text || "").trim();
const windPowerText = String(station.wind_power_text || "").trim();
const windDirectionText = sanitizeWindText(station.wind_direction_text);
const windPowerText = sanitizeWindText(station.wind_power_text);
if (station.wind_dir != null) {
const rotation = (Number(station.wind_dir) + 180) % 360;
+9 -2
View File
@@ -45,6 +45,13 @@ NMC_CITY_REFERENCES: Dict[str, Dict[str, Any]] = {
class NmcSourceMixin:
@staticmethod
def _nmc_optional_text(value: Any) -> Optional[str]:
text = str(value or "").strip()
if text in ("", "9999"):
return None
return text
@staticmethod
def _nmc_optional_float(value: Any) -> Optional[float]:
if value in (None, "", "9999", 9999, 9999.0):
@@ -138,8 +145,8 @@ class NmcSourceMixin:
"rain": self._nmc_optional_float(weather.get("rain")),
"airpressure": self._nmc_optional_float(weather.get("airpressure")),
"wx_desc": weather.get("info"),
"wind_direction": (payload.get("wind") or {}).get("direct"),
"wind_power": (payload.get("wind") or {}).get("power"),
"wind_direction": self._nmc_optional_text((payload.get("wind") or {}).get("direct")),
"wind_power": self._nmc_optional_text((payload.get("wind") or {}).get("power")),
},
}
with self._nmc_cache_lock: