123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- ; (function (Cesium) {
- checkSkyScenery(Cesium);
- function singleModelBindClick(viewer, options) {
- var t = {
- heading: 0,
- pitch: 0,
- roll: 0,
- info: null,
- }
- if (options.url != undefined) {
- if (typeof options.url != "string") {
- throw "url parameter error"
- }
- } else {
- throw "url cannot be empty"
- }
- if (options.lon != undefined) {
- if (typeof options.lon != "number") {
- throw "lon parameter error"
- }
- } else {
- throw "lon cannot be empty"
- }
- if (options.lat != undefined) {
- if (typeof options.lat != "number") {
- throw "lat parameter error"
- }
- } else {
- throw "lat cannot be empty"
- }
- if (options.height != undefined) {
- if (typeof options.height != "number") {
- throw "height parameter error"
- }
- } else {
- throw "height cannot be empty"
- }
-
- var option = Object.assign(t, options)
- if (viewer.viewerType != "SkyScenery") throw "viewer is error";
- this.viewer = viewer;
- var position = Cesium.Cartesian3.fromDegrees(option.lon, option.lat, option.height);
- var heading = Cesium.Math.toRadians(0);
- var pitch = Cesium.Math.toRadians(0);
- var roll = Cesium.Math.toRadians(0);
- var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
- var orientation = Cesium.Transforms.headingPitchRollQuaternion(
- position,
- hpr
- );
- var id = guid();
- this.id = id
- viewer.entities.add({
- id: id,
- info: option.info,
- position: position,
- orientation: orientation,
- model: {
- uri: option.url // "http://122.228.28.40:10092/proxy/sxt.gltf?servertype=CA_ZH_IOT_SXT&token=65463DEE-620A-0ED5-2385-17ECD07CD351",
- },
- });
- }
- singleModelBindClick.prototype.openClick = function (callback) {
- var that = this;
- var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
- handler.setInputAction(function (click) {
- var pick = viewer.scene.pick(click.position);
- if (Cesium.defined(pick) && (pick.id.id === that.id)) {
- console.log(pick.id.info)
- if (callback) callback(pick.id.info);
- }
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
- this.handler = handler;
- }
- singleModelBindClick.prototype.closeClick = function () {
- if (this.handler) {
- this.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
- this.handler = null
- delete this.handler
- }
- }
- function guid() {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
- var r = Math.random() * 16 | 0,
- v = c == 'x' ? r : (r & 0x3 | 0x8);
- return v.toString(16);
- });
- }
- Cesium.singleModelBindClick = singleModelBindClick
- }(SkyScenery));
|