antv-l7/demos/raster/basic/demo/raster.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

import { RasterLayer, Scene } from '@antv/l7';
2019-11-16 22:22:13 +08:00
import * as GeoTIFF from 'geotiff';
2019-11-14 11:50:12 +08:00
const scene = new Scene({
id: 'map',
pitch: 0,
2019-11-16 22:22:13 +08:00
type: 'mapbox',
2019-11-14 11:50:12 +08:00
style: 'light',
center: [121.2680, 30.3628],
2019-11-16 22:22:13 +08:00
zoom: 3,
2019-11-14 11:50:12 +08:00
});
2019-11-15 15:43:59 +08:00
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,
};
}
2019-11-14 11:50:12 +08:00
async function addLayer() {
2019-11-15 15:43:59 +08:00
const tiffdata = await getTiffData();
2019-11-14 11:50:12 +08:00
const layer = new RasterLayer({});
layer
.source(tiffdata.data, {
parser: {
type: 'raster',
width: tiffdata.width,
height: tiffdata.height,
min: 0,
max: 8000,
extent: [73.482190241, 3.82501784112, 135.106618732, 57.6300459963],
},
})
.style({
2019-11-18 16:13:15 +08:00
heightRatio:100,
2019-11-14 11:50:12 +08:00
opacity: 0.8,
rampColors: {
2019-11-18 16:13:15 +08:00
colors: [ '#FF4818', '#F7B74A', '#FFF598', '#91EABC', '#2EA9A1', '#206C7C' ].reverse(),
positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0]
2019-11-14 11:50:12 +08:00
},
});
return layer;
}
2019-11-16 22:22:13 +08:00
scene.on('loaded', async () =>{
const layer = await addLayer();
scene.addLayer(layer);
scene.render();
2019-11-14 11:50:12 +08:00
})