mirror of https://gitee.com/antv-l7/antv-l7
93 lines
2.1 KiB
TypeScript
93 lines
2.1 KiB
TypeScript
|
// @ts-nocheck
|
||
|
// @ts-ignore
|
||
|
import { Scene, Source } from '@antv/l7';
|
||
|
import { ImageLayer, RasterLayer } from '@antv/l7-layers';
|
||
|
import { GaodeMap } from '@antv/l7-maps';
|
||
|
import * as React from 'react';
|
||
|
import * as GeoTIFF from 'geotiff';
|
||
|
|
||
|
async function getTiffData() {
|
||
|
const response = await fetch(
|
||
|
'https://gw.alipayobjects.com/os/rmsportal/XKgkjjGaAzRyKupCBiYW.dat',
|
||
|
);
|
||
|
const arrayBuffer = await response.arrayBuffer();
|
||
|
const tiff = await GeoTIFF.fromArrayBuffer(arrayBuffer);
|
||
|
const image = await tiff.getImage();
|
||
|
const width = image.getWidth();
|
||
|
const height = image.getHeight();
|
||
|
const values = await image.readRasters();
|
||
|
return {
|
||
|
data: values[0],
|
||
|
width,
|
||
|
height,
|
||
|
min: 0,
|
||
|
max: 8000,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export default class Demo extends React.Component {
|
||
|
public async componentDidMount() {
|
||
|
const scene = new Scene({
|
||
|
id: 'map',
|
||
|
map: new GaodeMap({
|
||
|
center: [121.268, 30.3628],
|
||
|
zoom: 3,
|
||
|
}),
|
||
|
});
|
||
|
|
||
|
async function addLayer() {
|
||
|
const tiffdata = await getTiffData();
|
||
|
|
||
|
const layer = new RasterLayer({});
|
||
|
layer
|
||
|
.source(tiffdata.data, {
|
||
|
parser: {
|
||
|
type: 'raster',
|
||
|
width: tiffdata.width,
|
||
|
height: tiffdata.height,
|
||
|
min: 0,
|
||
|
max: 80,
|
||
|
extent: [73.482190241, 3.82501784112, 135.106618732, 57.6300459963],
|
||
|
},
|
||
|
})
|
||
|
.style({
|
||
|
heightRatio: 100,
|
||
|
opacity: 0.8,
|
||
|
rampColors: {
|
||
|
colors: [
|
||
|
'#FF4818',
|
||
|
'#F7B74A',
|
||
|
'#FFF598',
|
||
|
'#91EABC',
|
||
|
'#2EA9A1',
|
||
|
'#206C7C',
|
||
|
].reverse(),
|
||
|
positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0],
|
||
|
},
|
||
|
});
|
||
|
return layer;
|
||
|
}
|
||
|
|
||
|
const layer = await addLayer();
|
||
|
|
||
|
scene.on('loaded', () => {
|
||
|
scene.addLayer(layer);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public render() {
|
||
|
return (
|
||
|
<div
|
||
|
id="map"
|
||
|
style={{
|
||
|
position: 'absolute',
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
right: 0,
|
||
|
bottom: 0,
|
||
|
}}
|
||
|
></div>
|
||
|
);
|
||
|
}
|
||
|
}
|