@dde-earth/plugin-tiff-loader
Version:
93 lines (90 loc) • 2.54 kB
JavaScript
import { LayerItem } from 'dde-earth';
import { TIFFImageryProvider } from 'tiff-imagery-provider';
import { defaultRenderOptions, basicRenderOptions } from './constant.js';
class TIFFLayerItem extends LayerItem {
defaultRenderOptions = defaultRenderOptions;
get show() {
return this.instance?.show ?? false;
}
set show(val) {
if (this.instance)
this.instance.show = val;
}
async init(data) {
const options = { ...data, renderOptions: data.renderOptions };
if (options.url)
delete options.url;
const imageryProvider = await TIFFImageryProvider.fromUrl(
data.url,
options
);
const layer = this.earth.viewer.imageryLayers.addImageryProvider(
imageryProvider
);
TIFFLayerItem.basicRender(layer, data.renderOptions);
return layer;
}
remove() {
if (this.instance) {
return this.earth.viewer.imageryLayers.remove(this.instance);
}
return false;
}
zoomTo() {
if (this.instance) {
this.earth.viewer.flyTo(this.instance, {
duration: 1
});
}
}
static basicRender(layer, options = {}) {
if (layer) {
Object.entries(options).map(([name, value]) => {
if (Object.keys(basicRenderOptions).includes(name) && Object.prototype.hasOwnProperty.call(layer, name)) {
layer[name] = value;
}
});
}
}
async render(options) {
if (Object.keys(options).some(
(name) => !Object.keys(basicRenderOptions).includes(name)
)) {
if (this.instance) {
const newOptions = {
...this.data,
renderOptions: {
...this.data.renderOptions,
...options
}
};
if (newOptions.url)
delete newOptions.url;
const imageryProvider = await TIFFImageryProvider.fromUrl(
this.data.url,
newOptions
);
const index = this.earth.viewer.imageryLayers.indexOf(this.instance);
const bool = this.earth.viewer.imageryLayers.remove(
this.instance,
true
);
if (bool) {
const layer = this.earth.viewer.imageryLayers.addImageryProvider(
imageryProvider,
index
);
this._instance = layer;
}
}
}
TIFFLayerItem.basicRender(this.instance, options);
this._renderOptions = {
...this._renderOptions,
...options
};
this.earth.viewer.scene.requestRender();
}
}
export { TIFFLayerItem };
//# sourceMappingURL=TIFFLayerItem.js.map