cesium 图层构建的那些事 (一)

今天我们来聊聊图层构建的那些事情,全程使用typescript来实现

这是设计

首先我先定义个图层元组Tuple,它是一个抽象类,它具备一些基础通用方法约束,比如显示隐藏,飞入,图层加载,回调等等


/**

在地图上展示的最小分类元祖
*/
export abstract class Tuple {
public abstract type: String;//类型
protected _show: boolean = true;
protected map: any = null;
public cesiumObj: any = null;//cesium的对象
protected isAdd2LoadCesium = false;//是否在addToMap中,同时加载cesium
protected loadCesiumObjEndCallBack: any = null;
private _successCallBack: Function | any = null;//成功回调函数,请调用_success方法
private _errorCallBack: Function | any = null;//失败回调函数,请调用_error方法

 
constructor() {
super();
this.callSuccess = this.callSuccess.bind(this);
this.callError = this.callError.bind(this);
}

 
//是否显示
set show(value: boolean) {
this._show = value;
this.cesiumObj && (this.cesiumObj.show = value);
}

 
get show(): boolean {
return this._show;
}

 
protected abstract _addToMap(map: any): void;//添加到指定viewer中
protected abstract _removeByMap(destroy?: boolean): void;//从viewer中移除
//飞到元祖上
protected abstract _flyTo(duration?: number, pitch?: number, heading?: number, range?: number, maximumHeight?: number): void;

 
protected callLoadEndCesiumObj() {
this.show = this._show;//证明cesiumObj已经加载完成
this.loadCesiumObjEndCallBack && this.loadCesiumObjEndCallBack(this.map);
this.loadCesiumObjEndCallBack = null;
}
//加载成功回调
protected callSuccess() {
this._addToMap(this.map);
this._successCallBack && this._successCallBack(this.cesiumObj);
this._errorCallBack = null;
this._successCallBack = null;
}

 
//加载失败回调
protected callError(data: any) {
this._errorCallBack && this._errorCallBack(data);
this._errorCallBack = null;
this._successCallBack = null;
this.loadCesiumObjEndCallBack = null;
}

 
/**

 更多参考 https://xiaozhuanlan.com/topic/1937024856
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值