|
|
|
@ -1,7 +1,5 @@ |
|
|
|
|
import Feature from 'ol/Feature'; |
|
|
|
|
import Map from 'ol/Map'; |
|
|
|
|
import { Coordinate } from 'ol/coordinate'; |
|
|
|
|
import { MultiLineString } from 'ol/geom'; |
|
|
|
|
import Point from 'ol/geom/Point'; |
|
|
|
|
import { Group as LayerGroup } from 'ol/layer'; |
|
|
|
|
import VectorImage from 'ol/layer/VectorImage'; |
|
|
|
@ -16,9 +14,7 @@ import { |
|
|
|
|
MapLayerOptions, |
|
|
|
|
PanelData, |
|
|
|
|
GrafanaTheme2, |
|
|
|
|
EventBus, |
|
|
|
|
DataHoverEvent, |
|
|
|
|
DataHoverClearEvent, |
|
|
|
|
EventBus |
|
|
|
|
} from '@grafana/data'; |
|
|
|
|
|
|
|
|
|
export enum ShowTime { |
|
|
|
@ -74,8 +70,6 @@ export const dayNightLayer: MapLayerRegistryItem<DayNightConfig> = { |
|
|
|
|
// DayNight source
|
|
|
|
|
const source = new DayNight({}); |
|
|
|
|
const sourceMethods = Object.getPrototypeOf(source); |
|
|
|
|
const sourceLine = new DayNight({}); |
|
|
|
|
const sourceLineMethods = Object.getPrototypeOf(sourceLine); |
|
|
|
|
|
|
|
|
|
// Night polygon
|
|
|
|
|
const vectorLayer = new VectorImage({ |
|
|
|
@ -160,44 +154,6 @@ export const dayNightLayer: MapLayerRegistryItem<DayNightConfig> = { |
|
|
|
|
// Crosshair sharing subscriptions
|
|
|
|
|
const subscriptions = new Subscription(); |
|
|
|
|
|
|
|
|
|
if (false) { |
|
|
|
|
subscriptions.add( |
|
|
|
|
eventBus.subscribe(DataHoverEvent, (event) => { |
|
|
|
|
const time = event.payload?.point?.time; |
|
|
|
|
if (time) { |
|
|
|
|
const lineTime = new Date(time); |
|
|
|
|
const nightLinePoints = sourceLine.getCoordinates(lineTime.toString(), 'line'); |
|
|
|
|
nightLineLayer.getSource()?.clear(); |
|
|
|
|
const lineStringArray: Coordinate[][] = []; |
|
|
|
|
for (let l = 0; l < nightLinePoints.length - 1; l++) { |
|
|
|
|
const x1: number = Object.values(nightLinePoints[l])[0]; |
|
|
|
|
const y1: number = Object.values(nightLinePoints[l])[1]; |
|
|
|
|
const x2: number = Object.values(nightLinePoints[l + 1])[0]; |
|
|
|
|
const y2: number = Object.values(nightLinePoints[l + 1])[1]; |
|
|
|
|
const lineString = [fromLonLat([x1, y1]), fromLonLat([x2, y2])]; |
|
|
|
|
lineStringArray.push(lineString); |
|
|
|
|
} |
|
|
|
|
nightLineLayer.getSource()?.addFeature( |
|
|
|
|
new Feature({ |
|
|
|
|
geometry: new MultiLineString(lineStringArray), |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
let sunLinePos: number[] = []; |
|
|
|
|
sunLinePos = sourceLineMethods.getSunPosition(lineTime); |
|
|
|
|
sunLineFeature.getGeometry()?.setCoordinates(fromLonLat(sunLinePos)); |
|
|
|
|
sunLineFeature.setStyle([sunLineStyle, sunLineStyleDash]); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
subscriptions.add( |
|
|
|
|
eventBus.subscribe(DataHoverClearEvent, (event) => { |
|
|
|
|
nightLineLayer.getSource()?.clear(); |
|
|
|
|
sunLineFeature.setStyle(new Style({})); |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
init: () => layer, |
|
|
|
|