UNPKG

@dde-earth/plugin-tiff-loader

Version:

92 lines (89 loc) 2.55 kB
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(options = {}) { if (this.instance) { this.earth.viewer.flyTo(this.instance, { duration: 1, ...options }); } } 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) { this._renderOptions = { ...this._renderOptions, ...options }; if (Object.keys(options).some( (name) => !Object.keys(basicRenderOptions).includes(name) )) { const newOptions = { ...this.data, renderOptions: this._renderOptions }; if (this.instance) { 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, this._renderOptions); this.earth.viewer.scene.requestRender(); return this.instance; } } export { TIFFLayerItem }; //# sourceMappingURL=TIFFLayerItem.js.map