Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raster Layer 迁移到 Device API #2128

Merged
merged 7 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-demos/features/point/pointFillImage.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default () => {
})
.shape('marker')
.size(36)
.active(true)
// .active(true)
.style({
rotation: 90
})
Expand Down
24 changes: 13 additions & 11 deletions dev-demos/raster/image/demos/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default () => {

const scene = new Scene({
id: 'map',
renderer: 'device',
map: new GaodeMap({
style: 'light',
center: [ 121.268, 30.3628 ],
Expand All @@ -18,17 +19,17 @@ export default () => {
});

scene.on('loaded', () => {
const url1 =
'https://tiles{1-3}.geovisearth.com/base/v1/img/{z}/{x}/{y}?format=webp&tmsIds=w&token=b2a0cfc132cd60b61391b9dd63c15711eadb9b38a9943e3f98160d5710aef788';
const layer1 = new RasterLayer({
zIndex: 0,
}).source(url1, {
parser: {
type: 'rasterTile',
tileSize: 256,
},
});
scene.addLayer(layer1);
// const url1 =
// 'https://tiles{1-3}.geovisearth.com/base/v1/img/{z}/{x}/{y}?format=webp&tmsIds=w&token=b2a0cfc132cd60b61391b9dd63c15711eadb9b38a9943e3f98160d5710aef788';
// const layer1 = new RasterLayer({
// zIndex: 0,
// }).source(url1, {
// parser: {
// type: 'rasterTile',
// tileSize: 256,
// },
// });
// scene.addLayer(layer1);
const layer = new ImageLayer({});

layer.source(
Expand All @@ -41,6 +42,7 @@ export default () => {
}
);
scene.addLayer(layer);
// scene.startAnimate();


})
Expand Down
2 changes: 1 addition & 1 deletion dev-demos/raster/image/image.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
group:
path: 'image'
path: 'image-device'
title: 图片
---
### 图片图层
Expand Down
8 changes: 5 additions & 3 deletions dev-demos/raster/multiband/lc_08/rgb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default () => {
useEffect(() => {
const scene = new Scene({
id: 'map',

renderer:'device',
map: new Map({
center: [130.5, 47],
zoom: 2,
Expand All @@ -33,8 +33,8 @@ export default () => {
).json();
const layer = new RasterLayer({
zIndex: 10,
mask: true,
maskfence: maskData,
// mask: true,
// maskfence: maskData,
});
layer
.source(
Expand Down Expand Up @@ -78,6 +78,8 @@ export default () => {
.style({
opacity: 1,
});

scene.startAnimate();
scene.addLayer(layer);
});
}, []);
Expand Down
156 changes: 84 additions & 72 deletions dev-demos/raster/single/demos/light.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { RasterLayer, Scene } from '@antv/l7';
// @ts-ignore
import { Map } from '@antv/l7-maps';
import React, { useEffect } from 'react';
import * as GeoTIFF from 'geotiff';
import React, { useEffect } from 'react';

async function getTiffData() {
const response = await fetch(
Expand All @@ -16,79 +16,91 @@ async function getTiffData() {
export default () => {
useEffect(() => {
const scene = new Scene({
id: 'map',
map: new Map({
center: [ 105, 37.5 ],
zoom: 2.5
})
});
scene.on('loaded', () => {
addLayer();
id: 'map',
renderer: 'device',
map: new Map({
center: [105, 37.5],
zoom: 2.5,
}),
});
scene.on('loaded', () => {
addLayer();
});
async function getTiffData() {
const response = await fetch(
'https://gw.alipayobjects.com/zos/antvdemo/assets/light_clip/lightF182013.tiff',
);
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,
};
}

async function addLayer() {
const tiffdata = await getTiffData();

const layer = new RasterLayer({
zIndex: 2,
visible: true,
});
async function getTiffData() {
const response = await fetch(
'https://gw.alipayobjects.com/zos/antvdemo/assets/light_clip/lightF182013.tiff'
);
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
};
}

async function addLayer() {
const tiffdata = await getTiffData();

const layer = new RasterLayer({
zIndex: 2,
visible:false,
});
layer
.source(tiffdata.data, {
parser: {
type: 'raster',
width: tiffdata.width,
height: tiffdata.height,
extent: [ 73.4821902409999979, 3.8150178409999995, 135.1066187319999869, 57.6300459959999998 ]
}
})
.style({
clampLow: false,
clampHigh: false,
domain: [ 0, 90 ],
nodataValue: 0,
rampColors: {
// type:'quantize',
// colors:['#1b9e77','#d95f02','#7570b3','#e7298a','#66a61e','#e6ab02'],
colors: [ 'rgba(92,58,16,0)', 'rgba(92,58,16,0)', '#fabd08', '#f1e93f', '#f1ff8f', '#fcfff7' ],
positions: [ 0, 0.05, 0.1, 0.25, 0.5, 1.0 ]
}
});
const raster = new RasterLayer({
zIndex: 2,
maskLayers: [layer],
visible: true,
enableMask: true,
}).source(
'https://tiles{1-3}.geovisearth.com/base/v1/img/{z}/{x}/{y}?format=webp&tmsIds=w&token=b2a0cfc132cd60b61391b9dd63c15711eadb9b38a9943e3f98160d5710aef788',
{
parser: {
type: 'rasterTile',
tileSize: 256,
},
},
).style({
opacity: 1
layer
.source(tiffdata.data, {
parser: {
type: 'raster',
width: tiffdata.width,
height: tiffdata.height,
extent: [
73.4821902409999979, 3.8150178409999995, 135.1066187319999869,
57.6300459959999998,
],
},
})
.style({
clampLow: false,
clampHigh: false,
domain: [0, 90],
nodataValue: 0,
rampColors: {
// type:'quantize',
// colors:['#1b9e77','#d95f02','#7570b3','#e7298a','#66a61e','#e6ab02'],
colors: [
'rgba(92,58,16,0)',
'rgba(92,58,16,0)',
'#fabd08',
'#f1e93f',
'#f1ff8f',
'#fcfff7',
],
positions: [0, 0.05, 0.1, 0.25, 0.5, 1.0],
},
});
scene.addLayer(raster);
scene.addLayer(layer);
}
// const raster = new RasterLayer({
// zIndex: 2,
// maskLayers: [layer],
// visible: true,
// enableMask: true,
// }).source(
// 'https://tiles{1-3}.geovisearth.com/base/v1/img/{z}/{x}/{y}?format=webp&tmsIds=w&token=b2a0cfc132cd60b61391b9dd63c15711eadb9b38a9943e3f98160d5710aef788',
// {
// parser: {
// type: 'rasterTile',
// tileSize: 256,
// },
// },
// ).style({
// opacity: 1
// });
// scene.addLayer(raster);
scene.addLayer(layer);
scene.startAnimate();
}
}, []);
return (
<div
Expand Down
50 changes: 31 additions & 19 deletions dev-demos/raster/single/demos/rasterFile.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-ignore
import { RasterLayer, Scene, PolygonLayer } from '@antv/l7';
import { RasterLayer, Scene } from '@antv/l7';
// @ts-ignore
import { GaodeMap, Map } from '@antv/l7-maps';
import React, { useEffect } from 'react';
import { Map } from '@antv/l7-maps';
import * as GeoTIFF from 'geotiff';
import React, { useEffect } from 'react';

async function getTiffData() {
const response = await fetch(
Expand All @@ -17,26 +17,28 @@ export default () => {
useEffect(() => {
const scene = new Scene({
id: 'map',
renderer: 'device',
map: new Map({
center: [121.268, 30.3628],
zoom: 3,
}),
});

scene.on('loaded', async () => {
const maskdata = await (
await fetch(
'https://gw.alipayobjects.com/os/bmw-prod/fccd80c0-2611-49f9-9a9f-e2a4dd12226f.json',
)
).json();

const maskdata = await (await fetch(
'https://gw.alipayobjects.com/os/bmw-prod/fccd80c0-2611-49f9-9a9f-e2a4dd12226f.json',
)).json();

const p = new PolygonLayer({
visible: false,
zIndex: 1
})
.source(maskdata)
.shape('fill')
.color('blue')
scene.addLayer(p)
// const p = new PolygonLayer({
// visible: false,
// zIndex: 1,
// })
// .source(maskdata)
// .shape('fill')
// .color('blue');
// scene.addLayer(p);

const tiffdata = await getTiffData();
const tiff = await GeoTIFF.fromArrayBuffer(tiffdata);
Expand All @@ -46,9 +48,8 @@ export default () => {
const values = await image.readRasters();

const layer = new RasterLayer({
maskLayers: [p],
}
);
// maskLayers: [p],
});
layer
.source(values[0], {
parser: {
Expand All @@ -65,12 +66,23 @@ export default () => {
domain: [0, 10000],
rampColors: {
type: 'custom',
colors: ['#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#f7f7f7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac'],
colors: [
'#b2182b',
'#d6604d',
'#f4a582',
'#fddbc7',
'#f7f7f7',
'#d1e5f0',
'#92c5de',
'#4393c3',
'#2166ac',
],
positions: [0, 50, 200, 500, 2000, 3000, 4000, 5000, 8000, 10000],
},
});

scene.addLayer(layer);
scene.startAnimate();
});
}, []);
return (
Expand Down
5 changes: 4 additions & 1 deletion packages/layers/src/core/BaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,12 @@ ${uniforms.join('\n')}
if (Array.isArray(value)) {
uniformsArray.push(...value);
uniformsLength += value.length;
} else if (typeof value === 'number') { // 排除纹理
} else if (typeof value === 'number' ) { // 排除纹理
uniformsArray.push(value);
uniformsLength += 1;
} else if(typeof value ==='boolean') {
uniformsArray.push(Number(value));
uniformsLength += 1;
}
})

Expand Down
Loading
Loading