Filter invalid NMC wind placeholders from map labels
This commit is contained in:
@@ -78,6 +78,11 @@ function createMarkerIcon(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildNearbyIconHtml(detail: CityDetail, station: NearbyStation) {
|
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 symbol = detail.temp_symbol || "°C";
|
||||||
const rawLabel =
|
const rawLabel =
|
||||||
station.station_label ||
|
station.station_label ||
|
||||||
@@ -92,8 +97,8 @@ function buildNearbyIconHtml(detail: CityDetail, station: NearbyStation) {
|
|||||||
? String(rawLabel).replace(/\s*\(NMC\)$/i, "区域实况 (NMC)")
|
? String(rawLabel).replace(/\s*\(NMC\)$/i, "区域实况 (NMC)")
|
||||||
: rawLabel;
|
: rawLabel;
|
||||||
let windHtml = "";
|
let windHtml = "";
|
||||||
const windDirectionText = String(station.wind_direction_text || "").trim();
|
const windDirectionText = sanitizeWindText(station.wind_direction_text);
|
||||||
const windPowerText = String(station.wind_power_text || "").trim();
|
const windPowerText = sanitizeWindText(station.wind_power_text);
|
||||||
|
|
||||||
if (station.wind_dir != null) {
|
if (station.wind_dir != null) {
|
||||||
const rotation = (Number(station.wind_dir) + 180) % 360;
|
const rotation = (Number(station.wind_dir) + 180) % 360;
|
||||||
|
|||||||
@@ -45,6 +45,13 @@ NMC_CITY_REFERENCES: Dict[str, Dict[str, Any]] = {
|
|||||||
|
|
||||||
|
|
||||||
class NmcSourceMixin:
|
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
|
@staticmethod
|
||||||
def _nmc_optional_float(value: Any) -> Optional[float]:
|
def _nmc_optional_float(value: Any) -> Optional[float]:
|
||||||
if value in (None, "", "9999", 9999, 9999.0):
|
if value in (None, "", "9999", 9999, 9999.0):
|
||||||
@@ -138,8 +145,8 @@ class NmcSourceMixin:
|
|||||||
"rain": self._nmc_optional_float(weather.get("rain")),
|
"rain": self._nmc_optional_float(weather.get("rain")),
|
||||||
"airpressure": self._nmc_optional_float(weather.get("airpressure")),
|
"airpressure": self._nmc_optional_float(weather.get("airpressure")),
|
||||||
"wx_desc": weather.get("info"),
|
"wx_desc": weather.get("info"),
|
||||||
"wind_direction": (payload.get("wind") or {}).get("direct"),
|
"wind_direction": self._nmc_optional_text((payload.get("wind") or {}).get("direct")),
|
||||||
"wind_power": (payload.get("wind") or {}).get("power"),
|
"wind_power": self._nmc_optional_text((payload.get("wind") or {}).get("power")),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
with self._nmc_cache_lock:
|
with self._nmc_cache_lock:
|
||||||
|
|||||||
Reference in New Issue
Block a user