-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(layers): add girdheatmap add raster imagelayer
- Loading branch information
Showing
14 changed files
with
469 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { AttributeType, gl, IEncodeFeature, ILayer } from '@l7/core'; | ||
import BaseLayer from '../core/BaseLayer'; | ||
import { HeatmapGridTriangulation } from '../core/triangulation'; | ||
import heatmapGridFrag from './shaders/hexagon_frag.glsl'; | ||
import heatmapGridVert from './shaders/hexagon_vert.glsl'; | ||
interface IHeatMapLayerStyleOptions { | ||
opacity: number; | ||
coverage: number; | ||
} | ||
export default class HeatMapGrid extends BaseLayer<IHeatMapLayerStyleOptions> { | ||
public name: string = 'PointLayer'; | ||
|
||
protected getConfigSchema() { | ||
return { | ||
properties: { | ||
opacity: { | ||
type: 'number', | ||
minimum: 0, | ||
maximum: 1, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
protected renderModels() { | ||
const { opacity, coverage } = this.getStyleOptions(); | ||
this.models.forEach((model) => | ||
model.draw({ | ||
uniforms: { | ||
u_Opacity: opacity || 1.0, | ||
u_coverage: coverage || 1.0, | ||
u_radius: [ | ||
this.getSource().data.xOffset, | ||
this.getSource().data.yOffset, | ||
], | ||
}, | ||
}), | ||
); | ||
return this; | ||
} | ||
|
||
protected buildModels() { | ||
this.registerBuiltinAttributes(this); | ||
this.models = [ | ||
this.buildLayerModel({ | ||
moduleName: 'pointExtrude', | ||
vertexShader: heatmapGridVert, | ||
fragmentShader: heatmapGridFrag, | ||
triangulation: HeatmapGridTriangulation, | ||
blend: { | ||
enable: true, | ||
func: { | ||
srcRGB: gl.SRC_ALPHA, | ||
srcAlpha: 1, | ||
dstRGB: gl.ONE_MINUS_SRC_ALPHA, | ||
dstAlpha: 1, | ||
}, | ||
}, | ||
}), | ||
]; | ||
} | ||
|
||
private registerBuiltinAttributes(layer: ILayer) { | ||
// point layer size; | ||
layer.styleAttributeService.registerStyleAttribute({ | ||
name: 'size', | ||
type: AttributeType.Attribute, | ||
descriptor: { | ||
name: 'a_Size', | ||
buffer: { | ||
// give the WebGL driver a hint that this buffer may change | ||
usage: gl.DYNAMIC_DRAW, | ||
data: [], | ||
type: gl.FLOAT, | ||
}, | ||
size: 3, | ||
update: ( | ||
feature: IEncodeFeature, | ||
featureIdx: number, | ||
vertex: number[], | ||
attributeIdx: number, | ||
) => { | ||
const { size } = feature; | ||
return Array.isArray(size) ? [size[0]] : [size as number]; | ||
}, | ||
}, | ||
}); | ||
|
||
// point layer size; | ||
layer.styleAttributeService.registerStyleAttribute({ | ||
name: 'normal', | ||
type: AttributeType.Attribute, | ||
descriptor: { | ||
name: 'a_Normal', | ||
buffer: { | ||
// give the WebGL driver a hint that this buffer may change | ||
usage: gl.STATIC_DRAW, | ||
data: [], | ||
type: gl.FLOAT, | ||
}, | ||
size: 3, | ||
update: ( | ||
feature: IEncodeFeature, | ||
featureIdx: number, | ||
vertex: number[], | ||
attributeIdx: number, | ||
normal: number[], | ||
) => { | ||
return normal; | ||
}, | ||
}, | ||
}); | ||
layer.styleAttributeService.registerStyleAttribute({ | ||
name: 'pos', // 顶点经纬度位置 | ||
type: AttributeType.Attribute, | ||
descriptor: { | ||
name: 'a_Pos', | ||
buffer: { | ||
// give the WebGL driver a hint that this buffer may change | ||
usage: gl.DYNAMIC_DRAW, | ||
data: [], | ||
type: gl.FLOAT, | ||
}, | ||
size: 3, | ||
update: (feature: IEncodeFeature, featureIdx: number) => { | ||
const coordinates = feature.coordinates as number[]; | ||
return [coordinates[0], coordinates[1], 0]; | ||
}, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
precision highp float; | ||
varying vec4 v_color; | ||
uniform float u_opacity: 0.1; | ||
uniform float u_Opacity: 0.1; | ||
void main() { | ||
gl_FragColor = v_color; | ||
gl_FragColor.a *= u_opacity; | ||
} | ||
gl_FragColor.a *= u_Opacity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
precision highp float; | ||
attribute vec3 a_Position; | ||
attribute vec3 a_miter; | ||
attribute float a_size; | ||
attribute vec4 a_color; | ||
attribute vec3 a_Pos; | ||
attribute float a_Size; | ||
attribute vec4 a_Color; | ||
uniform vec2 u_radius; | ||
uniform float u_coverage: 1.; | ||
uniform float u_angle: 0; | ||
uniform mat4 u_ModelMatrix; | ||
varying vec4 v_color; | ||
#pragma include "projection" | ||
void main() { | ||
v_color = a_color; | ||
v_color = a_Color; | ||
mat2 rotationMatrix = mat2(cos(u_angle), sin(u_angle), -sin(u_angle), cos(u_angle)); | ||
vec2 offset =(vec2(a_miter.xy * u_radius * u_coverage * rotationMatrix)); | ||
vec4 project_pos = project_position(vec4(a_Position.xy + offset, 0, 1.0)); | ||
vec2 offset =(vec2(a_Position.xy * u_radius * u_coverage * rotationMatrix)); | ||
vec4 project_pos = project_position(vec4(a_Pos.xy + offset, 0, 1.0)); | ||
gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy, 0., 1.0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.