|
| 1 | +import { |
| 2 | + Ion, |
| 3 | + Cartesian3, |
| 4 | + Color, |
| 5 | + HeightReference, |
| 6 | + HorizontalOrigin, |
| 7 | +} from 'cesium'; |
| 8 | +import SosGetResult from 'osh-js/core/datasource/sos/SosGetResult.datasource.js'; |
| 9 | +import CesiumView from 'osh-js/core/ui/view/map/CesiumView.js'; |
| 10 | +import PointMarkerLayer from 'osh-js/core/ui/layer/PointMarkerLayer.js'; |
| 11 | +import {Mode} from "../../../source/core/datasource/Mode"; |
| 12 | + |
| 13 | +Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI1ODY0NTkzNS02NzI0LTQwNDktODk4Zi0zZDJjOWI2NTdmYTMiLCJpZCI6MTA1N' + |
| 14 | + 'zQsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1NTY4NzI1ODJ9.IbAajOLYnsoyKy1BOd7fY1p6GH-wwNVMdMduA2IzGjA'; |
| 15 | +window.CESIUM_BASE_URL = './'; |
| 16 | + |
| 17 | +// create piAware data sources |
| 18 | +let locationDataSource = new SosGetResult('piaware-location', { |
| 19 | + protocol: 'ws', |
| 20 | + service: 'SOS', |
| 21 | + endpointUrl: '76.187.247.4:8181/sensorhub/sos', |
| 22 | + // endpointUrl: 'localhost:8181/sensorhub/sos', |
| 23 | + offeringID: 'urn:osh:sensor:aviation:PiAware', |
| 24 | + observedProperty: 'http://sensorml.com/ont/swe/property/Location', |
| 25 | + mode: Mode.REAL_TIME, |
| 26 | + responseFormat: 'application/json', |
| 27 | +}); |
| 28 | + |
| 29 | +let trackDataSource = new SosGetResult('piaware-track', { |
| 30 | + protocol: 'ws', |
| 31 | + service: 'SOS', |
| 32 | + endpointUrl: '76.187.247.4:8181/sensorhub/sos', |
| 33 | + // endpointUrl: 'localhost:8181/sensorhub/sos', |
| 34 | + offeringID: 'urn:osh:sensor:aviation:PiAware', |
| 35 | + observedProperty: 'http://sensorml.com/ont/swe/property/Track', |
| 36 | + responseFormat: 'application/json', |
| 37 | + mode: Mode.REAL_TIME |
| 38 | +}); |
| 39 | + |
| 40 | +function hover(markerId, billboard, event) { |
| 41 | + console.log('[Hover]: '+markerId + ',' + billboard + ',' + event); |
| 42 | +} |
| 43 | + |
| 44 | +// style it with a moving point marker |
| 45 | +const locs = new Map(); |
| 46 | +const headings = new Map(); |
| 47 | +const planes = new Map(); |
| 48 | +// const flights = new Map(); |
| 49 | + |
| 50 | +let pointMarker = new PointMarkerLayer({ |
| 51 | + dataSourceIds: [locationDataSource.id, trackDataSource.id], |
| 52 | + getMarkerId: (rec) => rec.hexIdent, |
| 53 | + // filter: (rec) => rec.hexIdent === 'urn:osh:sensor:aviation:A3980F', |
| 54 | + allowBillboardRotation: true, |
| 55 | + onHover: (markerId, billboard, event) => hover(markerId, billboard, event) , |
| 56 | + getLocation: { |
| 57 | + dataSourceIds: [locationDataSource.getId()], |
| 58 | + handler: function(rec, timestamp, options, instance) { |
| 59 | + return { |
| 60 | + x: rec.location.lon, |
| 61 | + y: rec.location.lat, |
| 62 | + z: rec.location.alt |
| 63 | + }; |
| 64 | + } |
| 65 | + }, |
| 66 | + getOrientation: { |
| 67 | + dataSourceIds: [trackDataSource.getId()], |
| 68 | + handler: function(rec, timestamp, options, instance) { |
| 69 | + return { |
| 70 | + heading: 360 - rec.track |
| 71 | + }; |
| 72 | + } |
| 73 | + }, |
| 74 | + icon: 'images/icons8-airplane-64.png', |
| 75 | + iconAnchor: [16, 40] |
| 76 | +}); |
| 77 | + |
| 78 | +// create Cesium view |
| 79 | +let cesiumView = new CesiumView({ |
| 80 | + container: 'cesium-container', |
| 81 | + allowBillboardRotation: true, |
| 82 | + layers: [pointMarker] |
| 83 | +}); |
| 84 | + |
| 85 | +// ABIA Airport icon |
| 86 | +cesiumView.viewer.entities.add({ |
| 87 | + position: Cartesian3.fromDegrees(-97.6664, 30.1975), |
| 88 | + billboard: { |
| 89 | + image: "images/icons8-airport-50.png", |
| 90 | + heightReference: HeightReference.CLAMP_TO_GROUND, |
| 91 | + disableDepthTestDistance: Number.POSITIVE_INFINITY, |
| 92 | + }, |
| 93 | + }); |
| 94 | + |
| 95 | + |
| 96 | +console.log('connecting to datasources'); |
| 97 | + |
| 98 | +// start streaming |
| 99 | + locationDataSource.connect(); |
| 100 | + trackDataSource.connect(); |
0 commit comments