@dde-earth/plugin-tiff-loader
Version:
95 lines (91 loc) • 2.61 kB
JavaScript
'use strict';
var ddeEarth = require('dde-earth');
var tiffImageryProvider = require('tiff-imagery-provider');
var index = require('./index-aeb7c4bf.js');
class TIFFLayerItem extends ddeEarth.LayerItem {
defaultRenderOptions = index.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.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(index.basicRenderOptions).includes(name) && Object.prototype.hasOwnProperty.call(layer, name)) {
layer[name] = value;
}
});
}
}
async render(options) {
if (Object.keys(options).some(
(name) => !Object.keys(index.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.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();
}
}
exports.TIFFLayerItem = TIFFLayerItem;
//# sourceMappingURL=TIFFLayerItem-0701ac28.js.map