From 6f9e43165beccb32cf7e7891ef977ebde79b1f27 Mon Sep 17 00:00:00 2001 From: yunji Date: Fri, 17 May 2024 19:07:29 +0800 Subject: [PATCH] =?UTF-8?q?wip:=20=E5=A4=8D=E7=8E=B0=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=BA=E7=A9=BA=E7=9A=84=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/demos/bugfix/index.ts | 1 + examples/demos/bugfix/set-data-empty.ts | 81 +++++++++++++++++++++ packages/renderer/src/device/DeviceModel.ts | 6 +- 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 examples/demos/bugfix/set-data-empty.ts diff --git a/examples/demos/bugfix/index.ts b/examples/demos/bugfix/index.ts index 6673e5d22b..12009f5492 100644 --- a/examples/demos/bugfix/index.ts +++ b/examples/demos/bugfix/index.ts @@ -4,6 +4,7 @@ export { MapRender as event_legend } from './event_legend'; export { MapRender as mutiPolygon } from './muti-polygon'; export { MapRender as remove_muti_layer } from './remove-muti-layer'; export { MapRender as setData } from './set-data'; +export { MapRender as setDataEmpty } from './set-data-empty'; export { MapRender as size } from './size'; export { MapRender as text } from './text_offsets'; export { MapRender as tile_update } from './tile_update'; diff --git a/examples/demos/bugfix/set-data-empty.ts b/examples/demos/bugfix/set-data-empty.ts new file mode 100644 index 0000000000..aeb31a9590 --- /dev/null +++ b/examples/demos/bugfix/set-data-empty.ts @@ -0,0 +1,81 @@ +import { PointLayer, Scene } from '@antv/l7'; +import * as allMap from '@antv/l7-maps'; +import type { RenderDemoOptions } from '../../types'; + +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, + }), + }); + + fetch( + 'https://mdn.alipayobjects.com/afts/file/A*bcirT44OXmcAAAAAAAAAAAAADrd2AQ/new-housing-data-in-jzh.json', + ) + .then((res) => res.json()) + .then((data) => { + const layer = new PointLayer({ + autoFit: false, + }) + .source(data, { + parser: { + type: 'json', + x: '经度', + y: '纬度', + }, + }) + .scale('均价(元/平米)', { type: 'quantile' }) + .shape('circle') + .active(false) + .size('参考总价(万元)', [8, 16]) + .color('均价(元/平米)', ['#ffffcc', '#d9f0a3', '#addd8e', '#78c679', '#31a354', '#006837']) + .style({ + opacity: 0.8, + }); + + const highlightStrokeLayer = new PointLayer({ + autoFit: false, + }) + .source([], { + parser: { + type: 'json', + x: '经度', + y: '纬度', + }, + }) + .shape('circle') + .size(16) + .color('red') + .style({ + opacity: 0, + stroke: 'yellow', + strokeOpacity: 1, + strokeWidth: 2, + }); + + layer.once('inited', () => { + layer.fitBounds({ animate: false }); + }); + + scene.addLayer(layer); + scene.addLayer(highlightStrokeLayer); + + layer.on('mousemove', (event: any) => { + const { feature, featureId } = event; + const data = [feature]; + + const encodedData = layer.getEncodedData(); + const encodedFeature = encodedData.find((item) => item.id === featureId); + const featureSize = encodedFeature?.size as number; + highlightStrokeLayer.setData(data); + highlightStrokeLayer.size(featureSize); + }); + layer.on('mouseout', (event: any) => { + highlightStrokeLayer.setData([]); + }); + }); +} diff --git a/packages/renderer/src/device/DeviceModel.ts b/packages/renderer/src/device/DeviceModel.ts index 78c7ed5b40..04556542cd 100644 --- a/packages/renderer/src/device/DeviceModel.ts +++ b/packages/renderer/src/device/DeviceModel.ts @@ -132,12 +132,14 @@ export default class DeviceModel implements IModel { this.indexBuffer = (elements as DeviceElements).get(); } - const inputLayout = service.renderCache.createInputLayout({ + // const inputLayout = service.renderCache.createInputLayout({ + const inputLayout = device.createInputLayout({ vertexBufferDescriptors, indexBufferFormat: elements ? Format.U32_R : null, program: this.program, }); this.inputLayout = inputLayout; + console.log('inputLayout: ', inputLayout); this.pipeline = this.createPipeline(options); } @@ -364,7 +366,7 @@ export default class DeviceModel implements IModel { this.indexBuffer?.destroy(); this.bindings?.destroy(); // 不能进行销毁,删除 deleteVertexArray - // this.inputLayout.destroy(); + this.inputLayout.destroy(); this.pipeline.destroy(); this.destroyed = true; }