mirror of https://gitee.com/antv-l7/antv-l7
Merge branch 'master' of https://github.com/antvis/L7
This commit is contained in:
commit
67ccab1e9b
|
@ -136,6 +136,8 @@ export interface ILayer {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
threeRenderService?: any;
|
threeRenderService?: any;
|
||||||
|
|
||||||
|
getShaderPickStat: () => boolean;
|
||||||
needPick(type: string): boolean;
|
needPick(type: string): boolean;
|
||||||
getLayerConfig(): Partial<ILayerConfig & ISceneConfig>;
|
getLayerConfig(): Partial<ILayerConfig & ISceneConfig>;
|
||||||
getContainer(): Container;
|
getContainer(): Container;
|
||||||
|
@ -373,6 +375,11 @@ export interface ILayerService {
|
||||||
clock: Clock;
|
clock: Clock;
|
||||||
alreadyInRendering: boolean;
|
alreadyInRendering: boolean;
|
||||||
sceneService?: any;
|
sceneService?: any;
|
||||||
|
|
||||||
|
// 控制着色器颜色拾取计算
|
||||||
|
enableShaderPick: () => void;
|
||||||
|
disableShaderPick: () => void;
|
||||||
|
getShaderPickStat: () => boolean;
|
||||||
add(layer: ILayer): void;
|
add(layer: ILayer): void;
|
||||||
initLayers(): void;
|
initLayers(): void;
|
||||||
startAnimate(): void;
|
startAnimate(): void;
|
||||||
|
@ -386,5 +393,6 @@ export interface ILayerService {
|
||||||
renderLayers(type?: string): void;
|
renderLayers(type?: string): void;
|
||||||
getOESTextureFloat(): boolean;
|
getOESTextureFloat(): boolean;
|
||||||
isMapDragging(): boolean;
|
isMapDragging(): boolean;
|
||||||
|
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@ export default class LayerService implements ILayerService {
|
||||||
|
|
||||||
private animateInstanceCount: number = 0;
|
private animateInstanceCount: number = 0;
|
||||||
|
|
||||||
|
// TODO: 是否开启 shader 中的颜色拾取计算
|
||||||
|
private shaderPicking: boolean = true;
|
||||||
|
|
||||||
@inject(TYPES.IRendererService)
|
@inject(TYPES.IRendererService)
|
||||||
private readonly renderService: IRendererService;
|
private readonly renderService: IRendererService;
|
||||||
|
|
||||||
|
@ -163,6 +166,19 @@ export default class LayerService implements ILayerService {
|
||||||
return this.mapService.dragging;
|
return this.mapService.dragging;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 控制着色器颜色拾取计算
|
||||||
|
public enableShaderPick() {
|
||||||
|
this.shaderPicking = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public disableShaderPick() {
|
||||||
|
this.shaderPicking = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getShaderPickStat() {
|
||||||
|
return this.shaderPicking;
|
||||||
|
}
|
||||||
|
|
||||||
private runRender() {
|
private runRender() {
|
||||||
this.renderLayers();
|
this.renderLayers();
|
||||||
this.layerRenderID = $window.requestAnimationFrame(
|
this.layerRenderID = $window.requestAnimationFrame(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
varying vec4 v_PickingResult;
|
varying vec4 v_PickingResult;
|
||||||
uniform vec4 u_HighlightColor : [0, 0, 0, 0];
|
uniform vec4 u_HighlightColor : [0, 0, 0, 0];
|
||||||
uniform float u_PickingStage : 0.0;
|
uniform float u_PickingStage : 0.0;
|
||||||
uniform float u_Dragging;
|
uniform float u_shaderPick;
|
||||||
|
|
||||||
#define PICKING_NONE 0.0
|
#define PICKING_NONE 0.0
|
||||||
#define PICKING_ENCODE 1.0
|
#define PICKING_ENCODE 1.0
|
||||||
|
@ -44,6 +44,11 @@ vec4 filterPickingColor(vec4 color) {
|
||||||
*/
|
*/
|
||||||
vec4 filterColor(vec4 color) {
|
vec4 filterColor(vec4 color) {
|
||||||
// TODO: 过滤多余的 shader 计算
|
// TODO: 过滤多余的 shader 计算
|
||||||
// if(u_Dragging > 0.0) return color; // 暂时去除 直接取消计算在选中时拖拽地图会有问题
|
// return color;
|
||||||
|
if(u_shaderPick < 0.5) {
|
||||||
|
return color; // 暂时去除 直接取消计算在选中时拖拽地图会有问题
|
||||||
|
} else {
|
||||||
return filterPickingColor(filterHighlightColor(color));
|
return filterPickingColor(filterHighlightColor(color));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ uniform vec4 u_HighlightColor : [0, 0, 0, 0];
|
||||||
uniform float u_PickingStage : 0.0;
|
uniform float u_PickingStage : 0.0;
|
||||||
uniform float u_PickingThreshold : 1.0;
|
uniform float u_PickingThreshold : 1.0;
|
||||||
uniform float u_PickingBuffer: 0.0;
|
uniform float u_PickingBuffer: 0.0;
|
||||||
|
uniform float u_shaderPick;
|
||||||
|
|
||||||
#define PICKING_NONE 0.0
|
#define PICKING_NONE 0.0
|
||||||
#define PICKING_ENCODE 1.0
|
#define PICKING_ENCODE 1.0
|
||||||
|
@ -20,6 +21,9 @@ bool isVertexPicked(vec3 vertexColor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPickingColor(vec3 pickingColor) {
|
void setPickingColor(vec3 pickingColor) {
|
||||||
|
if(u_shaderPick < 0.5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// compares only in highlight stage
|
// compares only in highlight stage
|
||||||
v_PickingResult.a = float((u_PickingStage == PICKING_HIGHLIGHT) && isVertexPicked(pickingColor));
|
v_PickingResult.a = float((u_PickingStage == PICKING_HIGHLIGHT) && isVertexPicked(pickingColor));
|
||||||
|
|
||||||
|
|
|
@ -1009,6 +1009,10 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getShaderPickStat() {
|
||||||
|
return this.layerService.getShaderPickStat();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 继承空方法
|
* 继承空方法
|
||||||
* @param time
|
* @param time
|
||||||
|
|
|
@ -38,5 +38,4 @@ void main() {
|
||||||
alpha = clamp(alpha, 0.0, 1.0);
|
alpha = clamp(alpha, 0.0, 1.0);
|
||||||
gl_FragColor.a *= alpha;
|
gl_FragColor.a *= alpha;
|
||||||
}
|
}
|
||||||
gl_FragColor = filterColor(gl_FragColor);
|
|
||||||
}
|
}
|
|
@ -101,5 +101,4 @@ void main() {
|
||||||
} else {
|
} else {
|
||||||
gl_Position = project_common_position_to_clipspace(vec4(curr.xy + offset, 0, 1.0));
|
gl_Position = project_common_position_to_clipspace(vec4(curr.xy + offset, 0, 1.0));
|
||||||
}
|
}
|
||||||
setPickingColor(a_PickingColor);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ export default class ShaderUniformPlugin implements ILayerPlugin {
|
||||||
// u_ModelMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
|
// u_ModelMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
|
||||||
u_PickingBuffer: layer.getLayerConfig().pickingBuffer || 0,
|
u_PickingBuffer: layer.getLayerConfig().pickingBuffer || 0,
|
||||||
// TODO: 当前地图是否在拖动
|
// TODO: 当前地图是否在拖动
|
||||||
u_Dragging: Number(this.mapService.dragging),
|
u_shaderPick: Number(layer.getShaderPickStat()),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { ILayer } from '@antv/l7-core';
|
import { ILayer } from '@antv/l7-core';
|
||||||
|
|
||||||
export default interface ILayerManager {
|
export default interface ILayerManager {
|
||||||
|
enableShaderPick: () => void;
|
||||||
|
diasbleShaderPick: () => void;
|
||||||
addLayer(layer: ILayer): void;
|
addLayer(layer: ILayer): void;
|
||||||
|
|
||||||
getLayers(): ILayer[];
|
getLayers(): ILayer[];
|
||||||
|
|
|
@ -51,6 +51,9 @@ import IPostProcessingPassPluggable from './IPostProcessingPassPluggable';
|
||||||
*/
|
*/
|
||||||
class Scene
|
class Scene
|
||||||
implements IPostProcessingPassPluggable, IMapController, ILayerManager {
|
implements IPostProcessingPassPluggable, IMapController, ILayerManager {
|
||||||
|
public get map() {
|
||||||
|
return this.mapService.map;
|
||||||
|
}
|
||||||
private sceneService: ISceneService;
|
private sceneService: ISceneService;
|
||||||
private mapService: IMapService<unknown>;
|
private mapService: IMapService<unknown>;
|
||||||
private controlService: IControlService;
|
private controlService: IControlService;
|
||||||
|
@ -153,10 +156,6 @@ class Scene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get map() {
|
|
||||||
return this.mapService.map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public setBgColor(color: string) {
|
public setBgColor(color: string) {
|
||||||
this.mapService.setBgColor(color);
|
this.mapService.setBgColor(color);
|
||||||
}
|
}
|
||||||
|
@ -401,6 +400,16 @@ class Scene
|
||||||
.to(constructor)
|
.to(constructor)
|
||||||
.whenTargetNamed(name);
|
.whenTargetNamed(name);
|
||||||
}
|
}
|
||||||
|
// 资源管理
|
||||||
|
|
||||||
|
// 控制 shader pick 计算
|
||||||
|
public enableShaderPick() {
|
||||||
|
this.layerService.enableShaderPick();
|
||||||
|
}
|
||||||
|
|
||||||
|
public diasbleShaderPick() {
|
||||||
|
this.layerService.disableShaderPick();
|
||||||
|
}
|
||||||
|
|
||||||
private initComponent(id: string | HTMLDivElement) {
|
private initComponent(id: string | HTMLDivElement) {
|
||||||
this.controlService.init(
|
this.controlService.init(
|
||||||
|
@ -419,7 +428,6 @@ class Scene
|
||||||
this.addControl(new Logo({ position: logoPosition }));
|
this.addControl(new Logo({ position: logoPosition }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 资源管理
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Scene };
|
export { Scene };
|
||||||
|
|
|
@ -21,7 +21,7 @@ export default class PointTest extends React.Component {
|
||||||
zoom: 5,
|
zoom: 5,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
scene.diasbleShaderPick();
|
||||||
let address =
|
let address =
|
||||||
'https://gw.alipayobjects.com/os/bmw-prod/3f2f9284-3fb1-4838-8baa-6ffd06738fcd.csv';
|
'https://gw.alipayobjects.com/os/bmw-prod/3f2f9284-3fb1-4838-8baa-6ffd06738fcd.csv';
|
||||||
fetch(address)
|
fetch(address)
|
||||||
|
@ -43,6 +43,27 @@ export default class PointTest extends React.Component {
|
||||||
.shape('arcmini')
|
.shape('arcmini')
|
||||||
.size(2)
|
.size(2)
|
||||||
.color('rgb(13,64,140)')
|
.color('rgb(13,64,140)')
|
||||||
|
.style({
|
||||||
|
segmentNumber: 30,
|
||||||
|
});
|
||||||
|
|
||||||
|
// lineLayer2
|
||||||
|
const lineLayer2 = new LineLayer({
|
||||||
|
// autoFit: true,
|
||||||
|
blend: 'normal',
|
||||||
|
})
|
||||||
|
.source(data, {
|
||||||
|
parser: {
|
||||||
|
type: 'csv',
|
||||||
|
x: 'f_lon',
|
||||||
|
y: 'f_lat',
|
||||||
|
x1: 't_lon',
|
||||||
|
y1: 't_lat',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.shape('arc')
|
||||||
|
.size(2)
|
||||||
|
.color('rgb(13,64,140)')
|
||||||
.style({
|
.style({
|
||||||
segmentNumber: 30,
|
segmentNumber: 30,
|
||||||
})
|
})
|
||||||
|
@ -52,9 +73,19 @@ export default class PointTest extends React.Component {
|
||||||
.active({
|
.active({
|
||||||
color: '#ff0',
|
color: '#ff0',
|
||||||
});
|
});
|
||||||
// .animate(true)
|
lineLayer2.hide();
|
||||||
|
// scene.addLayer(lineLayer2);
|
||||||
|
|
||||||
scene.addLayer(lineLayer);
|
scene.addLayer(lineLayer);
|
||||||
|
|
||||||
|
window.onmousedown = () => {
|
||||||
|
// lineLayer2.hide()
|
||||||
|
lineLayer.show();
|
||||||
|
};
|
||||||
|
window.onmouseup = () => {
|
||||||
|
// lineLayer2.show()
|
||||||
|
lineLayer.hide();
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,8 +145,9 @@ export default class PointTest extends React.Component {
|
||||||
// let address = 'https://gw.alipayobjects.com/os/bmw-prod/e76d89f4-aa69-4974-90b7-b236904a43b1.json' // 100
|
// let address = 'https://gw.alipayobjects.com/os/bmw-prod/e76d89f4-aa69-4974-90b7-b236904a43b1.json' // 100
|
||||||
// let address = 'https://gw.alipayobjects.com/os/bmw-prod/edc8219a-b095-4451-98e9-3e387e290087.json' // 10000
|
// let address = 'https://gw.alipayobjects.com/os/bmw-prod/edc8219a-b095-4451-98e9-3e387e290087.json' // 10000
|
||||||
// let address = 'https://gw.alipayobjects.com/os/bmw-prod/2c37f08b-3fe6-4c68-a699-dc15cfc217f1.json' // 50000
|
// let address = 'https://gw.alipayobjects.com/os/bmw-prod/2c37f08b-3fe6-4c68-a699-dc15cfc217f1.json' // 50000
|
||||||
|
// let address = 'https://gw.alipayobjects.com/os/bmw-prod/8adff753-64e6-4ffa-9e7b-1f3dc6f4fd76.json'; // 100000
|
||||||
let address =
|
let address =
|
||||||
'https://gw.alipayobjects.com/os/bmw-prod/8adff753-64e6-4ffa-9e7b-1f3dc6f4fd76.json'; // 100000
|
'https://gw.alipayobjects.com/os/bmw-prod/577a70fb-fc19-4582-83ed-7cddb7b77645.json'; // 20 0000
|
||||||
fetch(address)
|
fetch(address)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
@ -168,6 +169,7 @@ export default class PointTest extends React.Component {
|
||||||
// .animate(true)
|
// .animate(true)
|
||||||
// .active(true);
|
// .active(true);
|
||||||
|
|
||||||
|
scene.diasbleShaderPick();
|
||||||
scene.on('loaded', () => {
|
scene.on('loaded', () => {
|
||||||
scene.addLayer(layer);
|
scene.addLayer(layer);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue