|
|
@ -5,9 +5,10 @@ import { Vector as VectorLayer } from 'ol/layer' |
|
|
|
import { Vector as VectorSource } from 'ol/source' |
|
|
|
import { Feature } from 'ol' |
|
|
|
import { Polygon, Point } from 'ol/geom' |
|
|
|
import { Style, Stroke, Fill, Circle, Text } from 'ol/style' |
|
|
|
import { Style, Stroke, Fill, Text } from 'ol/style' |
|
|
|
import { fromLonLat } from 'ol/proj' |
|
|
|
import type { FenceData, MarkerData } from '../types/map.types' |
|
|
|
import { FENCE_STATUS, FENCE_TYPE } from '../types/map.types' |
|
|
|
|
|
|
|
export class FenceService { |
|
|
|
private fenceLayer: VectorLayer<VectorSource> | null = null |
|
|
@ -25,7 +26,7 @@ export class FenceService { |
|
|
|
|
|
|
|
fences.forEach((fence) => { |
|
|
|
// 创建围栏多边形特征
|
|
|
|
const coordinates = fence.fenceRange.map((coord) => fromLonLat(coord)) |
|
|
|
const coordinates = fence.fenceRange?.map((coord) => fromLonLat(coord)) || [] |
|
|
|
|
|
|
|
// 确保围栏是闭合的
|
|
|
|
if (coordinates.length > 0) { |
|
|
@ -71,17 +72,18 @@ export class FenceService { |
|
|
|
let strokeWidth = 2 |
|
|
|
|
|
|
|
// 根据围栏状态设置样式
|
|
|
|
// 状态:0-禁用(绿色),1-启用(橙色),2-告警(红色)
|
|
|
|
switch (fence.status) { |
|
|
|
case 0: |
|
|
|
case FENCE_STATUS.DISABLED: |
|
|
|
strokeColor = '#67c23a' |
|
|
|
fillColor = 'rgba(103, 194, 58, 0.1)' |
|
|
|
break |
|
|
|
case 1: |
|
|
|
case FENCE_STATUS.ENABLED: |
|
|
|
strokeColor = '#e6a23c' |
|
|
|
fillColor = 'rgba(230, 162, 60, 0.15)' |
|
|
|
strokeWidth = 3 |
|
|
|
break |
|
|
|
case 2: |
|
|
|
case FENCE_STATUS.ALARM: // 告警状态
|
|
|
|
strokeColor = '#f56c6c' |
|
|
|
fillColor = 'rgba(245, 108, 108, 0.2)' |
|
|
|
strokeWidth = 4 |
|
|
@ -89,7 +91,8 @@ export class FenceService { |
|
|
|
} |
|
|
|
|
|
|
|
// 根据围栏类型调整样式
|
|
|
|
const lineDash = fence.type === 1 ? [10, 5] : undefined |
|
|
|
// 类型:1-超出(虚线),2-进入(实线)
|
|
|
|
const lineDash = fence.type === FENCE_TYPE.EXCEED ? [10, 5] : undefined |
|
|
|
|
|
|
|
return new Style({ |
|
|
|
stroke: new Stroke({ |
|
|
@ -200,7 +203,7 @@ export class FenceService { |
|
|
|
source.clear() |
|
|
|
|
|
|
|
fences.forEach((fence) => { |
|
|
|
const coordinates = fence.fenceRange.map((coord) => fromLonLat(coord)) |
|
|
|
const coordinates = fence.fenceRange?.map((coord) => fromLonLat(coord)) || [] |
|
|
|
|
|
|
|
if (coordinates.length > 0) { |
|
|
|
const lastCoord = coordinates[coordinates.length - 1] |
|
|
@ -243,7 +246,7 @@ export class FenceService { |
|
|
|
const fences = fenceId ? this.fenceData.filter((fence) => fence.id === fenceId) : this.fenceData |
|
|
|
|
|
|
|
for (const fence of fences) { |
|
|
|
if (this.pointInPolygon(point, fence.fenceRange)) { |
|
|
|
if (this.pointInPolygon(point, fence.fenceRange || [])) { |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
@ -276,8 +279,8 @@ export class FenceService { |
|
|
|
const fenceIds: string[] = [] |
|
|
|
|
|
|
|
for (const fence of this.fenceData) { |
|
|
|
if (this.pointInPolygon(marker.coordinates, fence.fenceRange)) { |
|
|
|
fenceIds.push(fence.id) |
|
|
|
if (this.pointInPolygon(marker.coordinates, fence.fenceRange || [])) { |
|
|
|
fenceIds.push(fence.id || '') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -290,7 +293,7 @@ export class FenceService { |
|
|
|
/** |
|
|
|
* 更新围栏状态 |
|
|
|
*/ |
|
|
|
updateFenceStatus(fenceId: string, status: number): void { |
|
|
|
updateFenceStatus(fenceId: string | undefined, status: number): void { |
|
|
|
const fence = this.fenceData.find((f) => f.id === fenceId) |
|
|
|
if (fence) { |
|
|
|
fence.status = status |
|
|
@ -301,7 +304,7 @@ export class FenceService { |
|
|
|
if (source) { |
|
|
|
const features = source.getFeatures() |
|
|
|
const fenceFeature = features.find( |
|
|
|
(feature) => feature.get('type') === 'fence' && feature.get('fenceId') === fenceId |
|
|
|
(feature) => feature.get('type') === 'fence' && feature.get('fenceId') === fenceId && fenceId |
|
|
|
) |
|
|
|
if (fenceFeature) { |
|
|
|
fenceFeature.setStyle(this.createFenceStyle(fence)) |
|
|
|