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

fix: device 渲染模式下 setData 时不生效 #2447

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 examples/demos/bugfix/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { MapRender as color } from './color';
export { MapRender as event_legend } from './event_legend';
export { MapRender as polygon } from './polygon';
export { MapRender as remove_muti_layer } from './remove-muti-layer';
export { MapRender as setData } from './set-data';
export { MapRender as size } from './size';
export { MapRender as text } from './text_offsets';
export { MapRender as tile_update } from './tile_update';
Expand Down
76 changes: 0 additions & 76 deletions examples/demos/bugfix/polygon.ts

This file was deleted.

94 changes: 94 additions & 0 deletions examples/demos/bugfix/set-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { PolygonLayer, Scene } from '@antv/l7';
import * as allMap from '@antv/l7-maps';
import type { RenderDemoOptions } from '../../types';

const data1 = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
base_height: 100,
},
geometry: {
type: 'Polygon',
coordinates: [
[
[119.948198, 30.339818],
[120.344273, 30.513865],
[120.414729, 30.288859],
[120.346177, 30.160522],
[120.100535, 30.041909],
[119.906306, 30.094644],
[119.845646, 30.175339],
[119.81137, 30.244454],
[119.807562, 30.352965],
[119.948198, 30.339818],
],
],
},
},
],
};

const data2 = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
base_height: 200,
},
geometry: {
type: 'Polygon',
coordinates: [
[
[119.948198, 30.339818],
[120.344273, 30.513865],
[120.414729, 30.288859],
[121.346177, 30.160522],
[120.100535, 30.041909],
[119.906306, 30.094644],
[119.845646, 30.175339],
[119.81137, 30.244454],
[119.807562, 30.352965],
[119.948198, 30.339818],
],
],
},
},
],
};

export function MapRender(options: RenderDemoOptions) {
const scene = new Scene({
id: 'map',
renderer: options.renderer,
map: new allMap[options.map]({
style: 'light',
center: [120.100535, 30.041909],
zoom: 14.83,
}),
});

scene.on('loaded', () => {
const layer = new PolygonLayer({
autoFit: false,
})
.source(data1)
.shape('fill')
.active(true)
.color('red');

layer.once('inited', () => {
layer.fitBounds({ animate: false });
});

scene.addLayer(layer);

setTimeout(() => {
console.log('setData: ');
layer.setData(data2);
}, 2000);
});
}
5 changes: 3 additions & 2 deletions packages/renderer/src/device/DeviceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class DeviceModel implements IModel {
this.indexBuffer = (elements as DeviceElements).get();
}

const inputLayout = service.renderCache.createInputLayout({
const inputLayout = device.createInputLayout({
vertexBufferDescriptors,
indexBufferFormat: elements ? Format.U32_R : null,
program: this.program,
Expand Down Expand Up @@ -346,7 +346,8 @@ export default class DeviceModel implements IModel {
}

destroy() {
this.program.destroy();
// 不销毁,方便后续重复使用
// this.program.destroy();
this.vertexBuffers?.forEach((buffer) => buffer.destroy());
this.indexBuffer?.destroy();
this.bindings?.destroy();
Expand Down
Loading