144 lines
2.9 KiB
JavaScript
144 lines
2.9 KiB
JavaScript
|
|
import BaseLayer3D from "./baselayer3d";
|
||
|
|
|
||
|
|
export default class FeatureLayer3D extends BaseLayer3D {
|
||
|
|
constructor(props) {
|
||
|
|
super(props);
|
||
|
|
|
||
|
|
this._loading = false;
|
||
|
|
this.rowKey = props.rowKey;
|
||
|
|
|
||
|
|
// this.highlights = this.getHighlightMap();
|
||
|
|
this._viewer = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
_updateVisible() {
|
||
|
|
if (!this._entities) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (const ent of this._entities) {
|
||
|
|
if (ent.__props) {
|
||
|
|
const needShow = this._isRecordVisible(ent.__props);
|
||
|
|
if (ent.show != needShow) {
|
||
|
|
ent.show = needShow;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
_isRecordVisible(record) {
|
||
|
|
// return !!(this.isVisible() || this.highlights[record[this.rowKey]]);
|
||
|
|
return !!(this.isVisible());
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
setVisible(val) {
|
||
|
|
super.setVisible(val);
|
||
|
|
|
||
|
|
this._updateVisible();
|
||
|
|
// 这里修改是否显示图层
|
||
|
|
this._viewer.entities.values.forEach((layer) => {
|
||
|
|
if(this.rowKey===layer._name){
|
||
|
|
layer.show = val
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
dataPromise() {
|
||
|
|
return Promise.resolve([]);
|
||
|
|
}
|
||
|
|
|
||
|
|
addFeature(record) {
|
||
|
|
console.error('method addFeature not impl', record);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 读取数据并设置数据源
|
||
|
|
*/
|
||
|
|
loadData() {
|
||
|
|
if (this._loading) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this._loading = true;
|
||
|
|
this.dataPromise().then((data) => {
|
||
|
|
this._loading = false;
|
||
|
|
this.setData(data);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
beforeSetData() { }
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 设置数据源
|
||
|
|
* @param {*} records
|
||
|
|
*/
|
||
|
|
setData(records) {
|
||
|
|
const viewer = this._viewer;
|
||
|
|
if (!viewer || !viewer.dataSourceDisplay?.defaultDataSource) {
|
||
|
|
console.log('viewer null');
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.beforeSetData();
|
||
|
|
|
||
|
|
viewer.entities.suspendEvents();
|
||
|
|
try {
|
||
|
|
if (Array.isArray(this._entities) && this._entities.length > 0) {
|
||
|
|
for (const ent of this._entities) {
|
||
|
|
viewer.entities.remove(ent);
|
||
|
|
}
|
||
|
|
this._entities = undefined;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Array.isArray(records)) {
|
||
|
|
this._entities = [];
|
||
|
|
for (const record of records) {
|
||
|
|
const ents = this.addFeature(record);
|
||
|
|
this._appendEntities(ents);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
console.log(e);
|
||
|
|
} finally {
|
||
|
|
viewer.entities.resumeEvents();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
onAdd(viewer) {
|
||
|
|
super.onAdd(viewer);
|
||
|
|
this._viewer = viewer;
|
||
|
|
this.loadData();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// 辅助函数,根据需要继承
|
||
|
|
refreshFeatureEntity(ent) { }
|
||
|
|
|
||
|
|
// 辅助函数
|
||
|
|
refreshFeatureEntities() {
|
||
|
|
const viewer = this._viewer;
|
||
|
|
if (!viewer) {
|
||
|
|
console.error('viewer null');
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
//console.log(this.highlights, this._setting);
|
||
|
|
viewer.entities.suspendEvents();
|
||
|
|
try {
|
||
|
|
if (Array.isArray(this._entities) && this._entities.length > 0) {
|
||
|
|
for (const ent of this._entities) {
|
||
|
|
this.refreshFeatureEntity(ent)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
this._updateVisible();
|
||
|
|
} catch (e) {
|
||
|
|
console.log(e);
|
||
|
|
} finally {
|
||
|
|
viewer.entities.resumeEvents();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|