mirror of https://gitee.com/antv-l7/antv-l7
fix: source empty err (#1332)
* fix: 修复 featureScale 错误 * style: lint style * fix: remove featureScalePlugin async * fix: fix empty source bug * style: lint style Co-authored-by: shihui <yiqianyao.yqy@alibaba-inc.com>
This commit is contained in:
parent
1081a15e11
commit
5225675cbe
|
@ -0,0 +1,2 @@
|
||||||
|
### earth
|
||||||
|
<code src="./earth.tsx"></code>
|
|
@ -0,0 +1,66 @@
|
||||||
|
// @ts-ignore
|
||||||
|
import { Scene, Earth, EarthLayer } from '@antv/l7';
|
||||||
|
|
||||||
|
import React, { useEffect } from 'react';
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
useEffect(() => {
|
||||||
|
const scene = new Scene({
|
||||||
|
id: 'map',
|
||||||
|
map: new Earth({
|
||||||
|
center: [120, 30],
|
||||||
|
pitch: 0,
|
||||||
|
zoom: 3,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const earthlayer = new EarthLayer()
|
||||||
|
.source(
|
||||||
|
'https://gw.alipayobjects.com/mdn/rms_23a451/afts/img/A*3-3NSpqRqUoAAAAAAAAAAAAAARQnAQ',
|
||||||
|
{
|
||||||
|
parser: {
|
||||||
|
type: 'image',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.shape('base')
|
||||||
|
.style({
|
||||||
|
globelOtions: {
|
||||||
|
ambientRatio: 0.6, // 环境光
|
||||||
|
diffuseRatio: 0.4, // 漫反射
|
||||||
|
specularRatio: 0.1, // 高光反射
|
||||||
|
// earthTime: 4.0
|
||||||
|
earthTime: 0.1,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.animate(true);
|
||||||
|
// earthlayer.setEarthTime(4.0)
|
||||||
|
|
||||||
|
const atomLayer = new EarthLayer()
|
||||||
|
.color('#2E8AE6')
|
||||||
|
.shape('atomSphere')
|
||||||
|
.style({
|
||||||
|
opacity: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
const bloomLayer = new EarthLayer().color('#fff').shape('bloomSphere');
|
||||||
|
|
||||||
|
scene.on('loaded', () => {
|
||||||
|
scene.addLayer(earthlayer);
|
||||||
|
|
||||||
|
scene.addLayer(atomLayer);
|
||||||
|
scene.addLayer(bloomLayer);
|
||||||
|
|
||||||
|
earthlayer.setEarthTime(4.0);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
id="map"
|
||||||
|
style={{
|
||||||
|
height: '500px',
|
||||||
|
position: 'relative',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,2 @@
|
||||||
|
### sprite
|
||||||
|
<code src="./sprite.tsx"></code>
|
|
@ -0,0 +1,60 @@
|
||||||
|
// @ts-ignore
|
||||||
|
import { Scene, GeometryLayer } from '@antv/l7';
|
||||||
|
// @ts-ignore
|
||||||
|
import { GaodeMap } from '@antv/l7-maps';
|
||||||
|
import React, { useEffect } from 'react';
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
useEffect(() => {
|
||||||
|
const scene = new Scene({
|
||||||
|
id: 'map',
|
||||||
|
map: new GaodeMap({
|
||||||
|
// map: new GaodeMapV2({
|
||||||
|
// map: new Mapbox({
|
||||||
|
pitch: 40,
|
||||||
|
style: 'dark',
|
||||||
|
center: [120, 30],
|
||||||
|
zoom: 6,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
scene.on('loaded', () => {
|
||||||
|
const layer = new GeometryLayer()
|
||||||
|
// .source([{x: 0, y: 0}], {parser: {type: 'json', x: 'x', y: 'y'}})
|
||||||
|
.shape('sprite')
|
||||||
|
.size(20)
|
||||||
|
.style({
|
||||||
|
// opacity: 0.3,
|
||||||
|
mapTexture:
|
||||||
|
'https://gw.alipayobjects.com/mdn/rms_816329/afts/img/A*zLQwQKBSagYAAAAAAAAAAAAAARQnAQ', // snow
|
||||||
|
// mapTexture: 'https://gw.alipayobjects.com/mdn/rms_816329/afts/img/A*w2SFSZJp4nIAAAAAAAAAAAAAARQnAQ', // rain
|
||||||
|
// mapTexture: 'https://gw.alipayobjects.com/mdn/rms_816329/afts/img/A*bq1cS7ADjR4AAAAAAAAAAAAAARQnAQ', // blub
|
||||||
|
center: [120, 30],
|
||||||
|
// spriteAnimate: 'up',
|
||||||
|
spriteCount: 60,
|
||||||
|
spriteRadius: 10,
|
||||||
|
spriteTop: 2500000,
|
||||||
|
spriteUpdate: 10000,
|
||||||
|
spriteScale: 0.8,
|
||||||
|
|
||||||
|
// spriteTop: 1000,
|
||||||
|
// spriteUpdate: 5,
|
||||||
|
// spriteBottom: -10,
|
||||||
|
// spriteScale: 0.6,
|
||||||
|
})
|
||||||
|
.active(true)
|
||||||
|
.color('#f00');
|
||||||
|
|
||||||
|
scene.addLayer(layer);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
id="map"
|
||||||
|
style={{
|
||||||
|
height: '500px',
|
||||||
|
position: 'relative',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
|
@ -269,6 +269,7 @@ export interface ILayer {
|
||||||
data: any[],
|
data: any[],
|
||||||
options: ISourceCFG | undefined,
|
options: ISourceCFG | undefined,
|
||||||
},
|
},
|
||||||
|
encodeDataLength: number;
|
||||||
pickedFeatureID: number | null;
|
pickedFeatureID: number | null;
|
||||||
hooks: {
|
hooks: {
|
||||||
init: SyncBailHook;
|
init: SyncBailHook;
|
||||||
|
|
|
@ -6,6 +6,16 @@ export default class GeometryLayer extends BaseLayer<
|
||||||
IGeometryLayerStyleOptions
|
IGeometryLayerStyleOptions
|
||||||
> {
|
> {
|
||||||
public type: string = 'GeometryLayer';
|
public type: string = 'GeometryLayer';
|
||||||
|
public defaultSourceConfig = {
|
||||||
|
data: [{ x: 0, y: 0 }],
|
||||||
|
options: {
|
||||||
|
parser: {
|
||||||
|
type: 'json',
|
||||||
|
x: 'x',
|
||||||
|
y: 'y',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
public buildModels() {
|
public buildModels() {
|
||||||
const modelType = this.getModelType();
|
const modelType = this.getModelType();
|
||||||
this.layerModel = new GeometryModels[modelType](this);
|
this.layerModel = new GeometryModels[modelType](this);
|
||||||
|
|
|
@ -77,6 +77,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
public selectedFeatureID: number | null = null;
|
public selectedFeatureID: number | null = null;
|
||||||
public styleNeedUpdate: boolean = false;
|
public styleNeedUpdate: boolean = false;
|
||||||
public rendering: boolean;
|
public rendering: boolean;
|
||||||
|
public forceRender: boolean = false;
|
||||||
public clusterZoom: number = 0; // 聚合等级标记
|
public clusterZoom: number = 0; // 聚合等级标记
|
||||||
public layerType?: string | undefined;
|
public layerType?: string | undefined;
|
||||||
public triangulation?: Triangulation | undefined;
|
public triangulation?: Triangulation | undefined;
|
||||||
|
@ -84,7 +85,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
public defaultSourceConfig: {
|
public defaultSourceConfig: {
|
||||||
data: any[];
|
data: any[];
|
||||||
options: ISourceCFG | undefined;
|
options: ISourceCFG | undefined;
|
||||||
}={
|
} = {
|
||||||
data: [],
|
data: [],
|
||||||
options: {
|
options: {
|
||||||
parser: {
|
parser: {
|
||||||
|
@ -93,7 +94,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public dataState: IDataState = {
|
public dataState: IDataState = {
|
||||||
dataSourceNeedUpdate: false,
|
dataSourceNeedUpdate: false,
|
||||||
dataMappingNeedUpdate: false,
|
dataMappingNeedUpdate: false,
|
||||||
|
@ -696,10 +696,9 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
this.tileLayer.render();
|
this.tileLayer.render();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
// TODO: this.getEncodedData().length !== 0 这个判断是为了解决在 2.5.x 引入数据纹理后产生的 空数据渲染导致 texture 超出上限问题
|
if (this.encodeDataLength <= 0 && !this.forceRender) return this;
|
||||||
if (this.getEncodedData() && this.getEncodedData().length !== 0) {
|
// Tip: this.getEncodedData().length !== 0 这个判断是为了解决在 2.5.x 引入数据纹理后产生的 空数据渲染导致 texture 超出上限问题
|
||||||
this.renderModels();
|
this.renderModels();
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,7 +706,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
* renderMultiPass 专门用于渲染支持 multipass 的 layer
|
* renderMultiPass 专门用于渲染支持 multipass 的 layer
|
||||||
*/
|
*/
|
||||||
public async renderMultiPass() {
|
public async renderMultiPass() {
|
||||||
if (this.getEncodedData() && this.getEncodedData().length !== 0) {
|
if (this.encodeDataLength <= 0 && !this.forceRender) return;
|
||||||
if (this.multiPassRenderer && this.multiPassRenderer.getRenderFlag()) {
|
if (this.multiPassRenderer && this.multiPassRenderer.getRenderFlag()) {
|
||||||
// multi render 开始执行 multiPassRender 的渲染流程
|
// multi render 开始执行 multiPassRender 的渲染流程
|
||||||
await this.multiPassRenderer.render();
|
await this.multiPassRenderer.render();
|
||||||
|
@ -718,7 +717,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
this.renderModels();
|
this.renderModels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public active(options: IActiveOption | boolean) {
|
public active(options: IActiveOption | boolean) {
|
||||||
const activeOption: Partial<ILayerConfig> = {};
|
const activeOption: Partial<ILayerConfig> = {};
|
||||||
|
@ -1078,8 +1076,10 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
return this.scaleOptions;
|
return this.scaleOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public encodeDataLength: number = 0;
|
||||||
public setEncodedData(encodedData: IEncodeFeature[]) {
|
public setEncodedData(encodedData: IEncodeFeature[]) {
|
||||||
this.encodedData = encodedData;
|
this.encodedData = encodedData;
|
||||||
|
this.encodeDataLength = encodedData.length;
|
||||||
}
|
}
|
||||||
public getEncodedData() {
|
public getEncodedData() {
|
||||||
return this.encodedData;
|
return this.encodedData;
|
||||||
|
@ -1294,7 +1294,8 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
|
|
||||||
public renderModels(isPicking?: boolean) {
|
public renderModels(isPicking?: boolean) {
|
||||||
// TODO: this.getEncodedData().length > 0 这个判断是为了解决在 2.5.x 引入数据纹理后产生的 空数据渲染导致 texture 超出上限问题
|
// TODO: this.getEncodedData().length > 0 这个判断是为了解决在 2.5.x 引入数据纹理后产生的 空数据渲染导致 texture 超出上限问题
|
||||||
if (this.getEncodedData() && this.getEncodedData().length > 0) {
|
if (this.encodeDataLength <= 0 && !this.forceRender) return this;
|
||||||
|
|
||||||
if (this.layerModelNeedUpdate && this.layerModel) {
|
if (this.layerModelNeedUpdate && this.layerModel) {
|
||||||
this.layerModel.buildModels((models: IModel[]) => {
|
this.layerModel.buildModels((models: IModel[]) => {
|
||||||
this.models = models;
|
this.models = models;
|
||||||
|
@ -1314,7 +1315,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
isPicking,
|
isPicking,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ export default class ThreeJSLayer
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
public forceRender: boolean = true;
|
||||||
|
|
||||||
public setUpdate(callback: () => void) {
|
public setUpdate(callback: () => void) {
|
||||||
this.update = callback;
|
this.update = callback;
|
||||||
|
@ -168,6 +169,7 @@ export default class ThreeJSLayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public renderModels() {
|
public renderModels() {
|
||||||
|
if (!this.threeRenderService) return this;
|
||||||
if (this.isUpdate && this.update) {
|
if (this.isUpdate && this.update) {
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue