Drop 10 non-null assertions from MapCanvas zoom-layer loops
Replace `zoomLayers[c]![t]!` patterns with explicit null-guard `continue` branches. The dimensions (2×5) are still initialized the same way; the narrowing just makes the linter happy without changing runtime behavior. Warning count: 65 → 55.
This commit is contained in:
@@ -211,9 +211,12 @@ export const MapCanvas: FC<MapCanvasProps> = ({
|
||||
|
||||
for (let c = 0; c < 2; c++) {
|
||||
const countryType = c === 0 ? "ru" : "other";
|
||||
const tierLayers = zoomLayers[c];
|
||||
if (!tierLayers) continue;
|
||||
for (let t = 0; t < 5; t++) {
|
||||
const tier = t + 2;
|
||||
const layer = zoomLayers[c]![t]!;
|
||||
const layer = tierLayers[t];
|
||||
if (!layer) continue;
|
||||
const inRange = tier <= currentZoom;
|
||||
const hiddenByIntl = intl && countryType === "ru";
|
||||
const hiddenByDom = dom && countryType === "other";
|
||||
@@ -276,9 +279,10 @@ export const MapCanvas: FC<MapCanvasProps> = ({
|
||||
|
||||
const segments: L.LatLng[] = [];
|
||||
for (let i = 0; i < resolved.length - 1; i++) {
|
||||
const from = resolved[i]!.getLatLng();
|
||||
const to = resolved[i + 1]!.getLatLng();
|
||||
const arc = buildGreatCircleArc(from, to);
|
||||
const src = resolved[i];
|
||||
const dst = resolved[i + 1];
|
||||
if (!src || !dst) continue;
|
||||
const arc = buildGreatCircleArc(src.getLatLng(), dst.getLatLng());
|
||||
segments.push(...(i === 0 ? arc : arc.slice(1)));
|
||||
}
|
||||
|
||||
@@ -318,8 +322,10 @@ export const MapCanvas: FC<MapCanvasProps> = ({
|
||||
// zoom + toggles.
|
||||
const zoomLayers: L.LayerGroup[][] = [[], []];
|
||||
for (let c = 0; c < 2; c++) {
|
||||
const tierLayers = zoomLayers[c];
|
||||
if (!tierLayers) continue;
|
||||
for (let t = 0; t < 5; t++) {
|
||||
zoomLayers[c]![t] = L.layerGroup();
|
||||
tierLayers[t] = L.layerGroup();
|
||||
}
|
||||
}
|
||||
zoomLayersRef.current = zoomLayers;
|
||||
@@ -358,9 +364,9 @@ export const MapCanvas: FC<MapCanvasProps> = ({
|
||||
// Clear everything before re-adding.
|
||||
flatLayer.clearLayers();
|
||||
highlightLayer.clearLayers();
|
||||
for (let c = 0; c < 2; c++) {
|
||||
for (let t = 0; t < 5; t++) {
|
||||
zoomLayers[c]![t]!.clearLayers();
|
||||
for (const tierLayers of zoomLayers) {
|
||||
for (const layer of tierLayers) {
|
||||
layer.clearLayers();
|
||||
}
|
||||
}
|
||||
markerIndexRef.current = new Map();
|
||||
@@ -395,10 +401,11 @@ export const MapCanvas: FC<MapCanvasProps> = ({
|
||||
marker.addTo(highlightLayer);
|
||||
} else if (isCategorized) {
|
||||
const countryIdx = m.countryType === "ru" ? 0 : 1;
|
||||
const rawTier = m.zoomLevel!;
|
||||
const rawTier = m.zoomLevel ?? 6;
|
||||
const tier = rawTier >= 2 && rawTier <= 6 ? rawTier : 6;
|
||||
const tierIdx = tier - 2;
|
||||
marker.addTo(zoomLayers[countryIdx]![tierIdx]!);
|
||||
const target = zoomLayers[countryIdx]?.[tierIdx];
|
||||
if (target) marker.addTo(target);
|
||||
} else {
|
||||
marker.addTo(flatLayer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user