|
| 1 | +<template> |
| 2 | + <slot /> |
| 3 | +</template> |
| 4 | +<script> |
| 5 | +import { LV95, WGS84 } from '@/utils/coordinateSystems' |
| 6 | +import { FeatureStyleColor, RED } from '@/utils/featureStyleUtils' |
| 7 | +import proj4 from 'proj4' |
| 8 | +import { CallbackProperty, Cartesian3, Color, Ellipsoid, Entity, HeightReference } from 'cesium' |
| 9 | +
|
| 10 | +export default { |
| 11 | + inject: ['getViewer'], |
| 12 | + props: { |
| 13 | + coordinates: { |
| 14 | + type: Array, |
| 15 | + default: null, |
| 16 | + }, |
| 17 | + trackingPointColor: { |
| 18 | + type: FeatureStyleColor, |
| 19 | + default: RED, |
| 20 | + }, |
| 21 | + }, |
| 22 | + watch: { |
| 23 | + coordinates(newCoordinates) { |
| 24 | + if (newCoordinates) { |
| 25 | + this.updatePosition() |
| 26 | + if (!this.pointAdded) this.addTrackingPoint() |
| 27 | + } else { |
| 28 | + this.removeTrackingPoint() |
| 29 | + } |
| 30 | + }, |
| 31 | + trackingPointColor(newColor) { |
| 32 | + this.pointFill = Color.fromCssColorString(newColor.fill) |
| 33 | + this.pointBorder = Color.fromCssColorString(newColor.border) |
| 34 | + this.getViewer()?.scene.requestRender() |
| 35 | + }, |
| 36 | + }, |
| 37 | + mounted() { |
| 38 | + this.pointAdded = false |
| 39 | + this.trackingPointPosition = new Cartesian3() |
| 40 | + this.pointFill = Color.fromCssColorString(this.trackingPointColor.fill) |
| 41 | + this.pointBorder = Color.fromCssColorString(this.trackingPointColor.border) |
| 42 | + this.trackingPoint = new Entity({ |
| 43 | + position: new CallbackProperty(() => this.trackingPointPosition, false), |
| 44 | + point: { |
| 45 | + show: true, |
| 46 | + color: new CallbackProperty(() => this.pointFill, false), |
| 47 | + outlineWidth: 5, |
| 48 | + outlineColor: new CallbackProperty(() => this.pointBorder, false), |
| 49 | + pixelSize: 15, |
| 50 | + heightReference: HeightReference.CLAMP_TO_GROUND, |
| 51 | + disableDepthTestDistance: Number.POSITIVE_INFINITY, |
| 52 | + }, |
| 53 | + }) |
| 54 | + if (this.coordinates) { |
| 55 | + this.updatePosition() |
| 56 | + this.addTrackingPoint() |
| 57 | + } |
| 58 | + }, |
| 59 | + unmounted() { |
| 60 | + this.removeTrackingPoint() |
| 61 | + }, |
| 62 | + methods: { |
| 63 | + addTrackingPoint() { |
| 64 | + this.pointAdded = true |
| 65 | + this.getViewer()?.entities.add(this.trackingPoint) |
| 66 | + }, |
| 67 | + removeTrackingPoint() { |
| 68 | + this.pointAdded = false |
| 69 | + this.getViewer()?.entities.remove(this.trackingPoint) |
| 70 | + }, |
| 71 | + updatePosition() { |
| 72 | + const wgs84Position = proj4(LV95.epsg, WGS84.epsg, this.coordinates) |
| 73 | + Cartesian3.fromDegrees( |
| 74 | + wgs84Position[0], |
| 75 | + wgs84Position[1], |
| 76 | + 0, |
| 77 | + Ellipsoid.WGS84, |
| 78 | + this.trackingPointPosition |
| 79 | + ) |
| 80 | + this.getViewer()?.scene.requestRender() |
| 81 | + }, |
| 82 | + }, |
| 83 | +} |
| 84 | +</script> |
0 commit comments