function finiteCoordinate(value) { if (value === null || value === undefined || value === '') return null const coordinate = Number(value) return Number.isFinite(coordinate) ? coordinate : null } function featureIdentity(feature, properties) { return { id: properties.id ?? feature.id, featureId: feature.id, type: properties.facilityType || properties.type || '', name: properties.facilityName || properties.name || properties.pipeName || properties.facilityTypeName || '供水设施', code: properties.facilityCode || properties.code || properties.pipeCode || '-', status: properties.status, road: properties.road || properties.address || properties.location || '', raw: feature } } export function buildFacilityMapModel(collection = {}) { const points = [] const lines = [] for (const feature of Array.isArray(collection.features) ? collection.features : []) { const properties = feature.properties || {} const identity = featureIdentity(feature, properties) const coordinates = feature.geometry?.coordinates if (feature.geometry?.type === 'Point' && Array.isArray(coordinates)) { const lng = finiteCoordinate(coordinates[0]) const lat = finiteCoordinate(coordinates[1]) if (lng === null || lat === null) continue points.push({ ...identity, address: properties.address || properties.location || '', lng, lat }) } if (feature.geometry?.type === 'LineString' && Array.isArray(coordinates) && coordinates.length >= 2) { const linePoints = coordinates.map(pair => ({ lng: finiteCoordinate(pair?.[0]), lat: finiteCoordinate(pair?.[1]) })) if (linePoints.some(point => point.lng === null || point.lat === null)) continue lines.push({ ...identity, type: identity.type || 'pipe', material: properties.pipeMaterial, diameter: properties.pipeDiameter, startPoint: properties.startPoint, endPoint: properties.endPoint, layingYear: properties.layingYear, length: properties.pipeLength, points: linePoints }) } } return { points, lines } } export function filterFacilityMapModel(model = {}, enabledTypes = {}) { const points = (model.points || []).filter(item => enabledTypes[item.type] !== false) const lines = (model.lines || []).filter(item => enabledTypes[item.type] !== false) return { points, lines, isEmpty: points.length === 0 && lines.length === 0 } } export function findFacilityFeature(model = {}, keyword = '') { const normalized = String(keyword).trim().toLocaleLowerCase() if (!normalized) return null const items = [ ...(model.points || []).map(item => ({ ...item, kind: 'point' })), ...(model.lines || []).map(item => { const first = item.points[0] const last = item.points[item.points.length - 1] const midpoint = { lng: Number(((first.lng + last.lng) / 2).toFixed(8)), lat: Number(((first.lat + last.lat) / 2).toFixed(8)) } return { ...item, kind: 'pipeline', lng: midpoint.lng, lat: midpoint.lat } }) ] return items.find(item => [item.name, item.code, item.road] .some(value => String(value || '').toLocaleLowerCase().includes(normalized))) || null } const facilityDetailLabels = { id: '系统编号', sourceId: '水源地编号', sourceName: '水源地名称', sourceType: '水源地类型', unit: '所属单位', address: '详细地址', location: '位置描述', longitude: '经度', latitude: '纬度', waterType: '水源类型', protectionLevel: '保护等级', waterQualityLevel: '水质等级', protectionScope: '保护范围', reportTime: '上报时间', status: '运行状态', plantCode: '水厂编号', plantName: '水厂名称', waterSourceType: '水源类型', designCapacity: '设计供水能力', currentCapacity: '实际供水能力', treatmentProcess: '处理工艺', commissionDate: '投运日期', waterQualityStandard: '水质执行标准', stationCode: '泵站编号', stationName: '泵站名称', stationType: '设施类型', pumpCount: '水泵数量', designFlow: '设计流量', designHead: '设计扬程', powerCapacity: '装机容量', userCode: '用水户编号', userName: '用水户名称', userType: '用水户类型', contactPerson: '联系人', contactPhone: '联系电话', meterNumber: '水表编号', initialReading: '初始读数', currentReading: '当前读数', annualWaterConsumption: '年用水量', networkId: '管网系统编号', networkCode: '管网编号', networkName: '管网名称', networkLevel: '管网等级', networkType: '业务归属', managementUnit: '管养单位', material: '管道材质', diameter: '管径', length: '管道长度', buildDate: '建设日期', buildYear: '建设年份', principal: '负责人', remark: '备注', delFlag: '删除标志', createBy: '创建人', createTime: '创建时间', updateBy: '更新人', updateTime: '更新时间' } const facilityStatusLabels = { source: { 0: '正常', 1: '异常' }, plant: { 0: '正常', 1: '停产' }, pumpStation: { 0: '正常', 1: '故障停运', 2: '检修中' }, pipe: { 0: '正常', 1: '停用' }, user: { 0: '正常', 1: '欠费', 2: '停用' } } function formatFacilityDetailValue(key, value, facilityType) { if (key === 'status') { return facilityStatusLabels[facilityType]?.[String(value)] ?? value } if (key === 'stationType') { return { water_supply: '供水泵站', drainage: '排水泵站' }[value] ?? value } if (key === 'networkType') { return { 0: '燃气', 1: '排水', 2: '供水' }[String(value)] ?? value } if (key === 'delFlag') { return { 0: '正常', 2: '已删除' }[String(value)] ?? value } return value } export function formatFacilityDetail(detail = {}, facilityType = '') { if (!detail || typeof detail !== 'object') return [] return Object.entries(detail) .filter(([key, value]) => key in facilityDetailLabels && value !== null && value !== undefined && value !== '') .map(([key, value]) => ({ label: facilityDetailLabels[key], value: formatFacilityDetailValue(key, value, facilityType) })) }