fix: line opacity & text stroke opacity

This commit is contained in:
thinkinggis 2020-02-07 21:11:58 +08:00
parent 0865890c79
commit d8464855a3
12 changed files with 919 additions and 761 deletions

View File

@ -62,7 +62,7 @@
"eslint": "^6.6.0", "eslint": "^6.6.0",
"eslint-config-egg": "^7.5.1", "eslint-config-egg": "^7.5.1",
"eslint-plugin-html": "^6.0.0", "eslint-plugin-html": "^6.0.0",
"gatsby": "^2.17.7", "gatsby": "2.19.5",
"gatsby-plugin-google-analytics": "^2.1.27", "gatsby-plugin-google-analytics": "^2.1.27",
"gatsby-remark-prettier": "^1.0.0", "gatsby-remark-prettier": "^1.0.0",
"geotiff": "^1.0.0-beta.6", "geotiff": "^1.0.0-beta.6",
@ -119,7 +119,7 @@
"scripts": { "scripts": {
"start": "yarn run site:clean && yarn run site:develop", "start": "yarn run site:clean && yarn run site:develop",
"site:develop": "cross-env BABEL_ENV=site gatsby develop --open -H 0.0.0.0", "site:develop": "cross-env BABEL_ENV=site gatsby develop --open -H 0.0.0.0",
"site:build": "yarn run site:clean && cross-env BABEL_ENV=site gatsby build --prefix-paths", "site:build": "yarn run site:clean && cross-env BABEL_ENV=site gatsby build --prefix-paths --no-uglify",
"site:clean": "gatsby clean", "site:clean": "gatsby clean",
"site:deploy": "yarn run site:build && gh-pages -d public", "site:deploy": "yarn run site:build && gh-pages -d public",
"site:publish": "gh-pages -d public", "site:publish": "gh-pages -d public",

View File

@ -72,6 +72,7 @@ export default class LayerService implements ILayerService {
// //
this.alreadyInRendering = true; this.alreadyInRendering = true;
this.clear(); this.clear();
this.updateRenderOrder();
this.layers this.layers
.filter((layer) => layer.inited) .filter((layer) => layer.inited)
.filter((layer) => layer.isVisible()) .filter((layer) => layer.isVisible())

View File

@ -173,6 +173,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
constructor(config: Partial<ILayerConfig & ChildLayerStyleOptions> = {}) { constructor(config: Partial<ILayerConfig & ChildLayerStyleOptions> = {}) {
super(); super();
this.name = config.name || this.id; this.name = config.name || this.id;
this.zIndex = config.zIndex || 0;
this.rawConfig = config; this.rawConfig = config;
} }

View File

@ -24,17 +24,17 @@ uniform vec4 u_aimate: [ 0, 2., 1.0, 0.2 ];
void main() { void main() {
gl_FragColor = v_color; gl_FragColor = v_color;
// anti-alias // anti-alias
float blur = 1.- smoothstep(u_blur, 1., length(v_normal.xy)) * u_opacity; float blur = 1.- smoothstep(u_blur, 1., length(v_normal.xy));
// gl_FragColor.a *= blur; gl_FragColor.a *= blur * u_opacity;
if(u_aimate.x == Animate) { if(u_aimate.x == Animate) {
float alpha =1.0 - fract( mod(1.0- v_distance_ratio, u_aimate.z)* (1.0/ u_aimate.z) + u_time / u_aimate.y); float alpha =1.0 - fract( mod(1.0- v_distance_ratio, u_aimate.z)* (1.0/ u_aimate.z) + u_time / u_aimate.y);
alpha = (alpha + u_aimate.w -1.0) / u_aimate.w; alpha = (alpha + u_aimate.w -1.0) / u_aimate.w;
gl_FragColor.a *= alpha * blur; gl_FragColor.a *= alpha;
} }
// dash line // dash line
if(u_line_type == LineTypeDash) { if(u_line_type == LineTypeDash) {
gl_FragColor.a *= blur * (1.0- step(v_dash_array.x, mod(v_distance_ratio, v_dash_array.x +v_dash_array.y))); gl_FragColor.a *=(1.0- step(v_dash_array.x, mod(v_distance_ratio, v_dash_array.x +v_dash_array.y)));
} }
gl_FragColor = filterColor(gl_FragColor); gl_FragColor = filterColor(gl_FragColor);

View File

@ -89,13 +89,16 @@ export default class TextModel extends BaseModel {
const { const {
fontWeight = 800, fontWeight = 800,
fontFamily = 'sans-serif', fontFamily = 'sans-serif',
opacity = 1.0,
stroke = '#fff', stroke = '#fff',
strokeWidth = 0, strokeWidth = 0,
strokeOpacity = 1,
} = this.layer.getLayerConfig() as IPointTextLayerStyleOptions; } = this.layer.getLayerConfig() as IPointTextLayerStyleOptions;
this.updateTexture(); this.updateTexture();
const { canvas } = this.fontService; const { canvas } = this.fontService;
return { return {
u_opacity: 1.0, u_opacity: opacity,
u_stroke_opacity: strokeOpacity,
u_sdf_map: this.texture, u_sdf_map: this.texture,
u_stroke: rgb2arr(stroke), u_stroke: rgb2arr(stroke),
u_halo_blur: 0.5, u_halo_blur: 0.5,

View File

@ -4,6 +4,7 @@ uniform sampler2D u_sdf_map;
uniform float u_gamma_scale : 0.5; uniform float u_gamma_scale : 0.5;
uniform float u_font_size : 24; uniform float u_font_size : 24;
uniform float u_opacity : 1.0; uniform float u_opacity : 1.0;
uniform float u_stroke_opacity: 1.0;
uniform vec4 u_stroke : [0, 0, 0, 1]; uniform vec4 u_stroke : [0, 0, 0, 1];
uniform float u_strokeWidth : 2.0; uniform float u_strokeWidth : 2.0;
uniform float u_halo_blur : 0.5; uniform float u_halo_blur : 0.5;
@ -27,6 +28,6 @@ void main() {
highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);
gl_FragColor = mix(v_color * u_opacity, u_stroke, smoothstep(0., 0.5, 1. - dist)) * alpha; gl_FragColor = mix(v_color * u_opacity, u_stroke * u_stroke_opacity, smoothstep(0., 0.5, 1. - dist)) * alpha;
gl_FragColor = filterColor(gl_FragColor); gl_FragColor = filterColor(gl_FragColor);
} }

View File

@ -42,7 +42,7 @@ export default class Arc2DLineDemo extends React.Component {
trailLength: 0.4, trailLength: 0.4,
}) })
.style({ .style({
opacity: 0.6, opacity: 0.1,
}); });
scene.addLayer(lineLayer); scene.addLayer(lineLayer);
scene.render(); scene.render();

View File

@ -53,6 +53,7 @@ export default class ArcLineDemo extends React.Component {
}) })
.style({ .style({
lineType: 'dash', lineType: 'dash',
opacity: 0.5,
}); });
scene.addLayer(lineLayer); scene.addLayer(lineLayer);
scene.render(); scene.render();

View File

@ -36,13 +36,16 @@ export default class LineDemo extends React.Component {
.shape('line') .shape('line')
.active(true) .active(true)
.color('color', (v) => { .color('color', (v) => {
return `rgb(${v[0]})`; return `rgb(${v})`;
}) })
.animate({ .animate({
enable: true, enable: true,
interval: 0.5, interval: 0.5,
trailLength: 0.4, trailLength: 0.4,
duration: 4, duration: 4,
})
.style({
opacity: 1.0,
}); });
scene.addLayer(lineLayer); scene.addLayer(lineLayer);

View File

@ -65,8 +65,9 @@ export default class TextLayerDemo extends React.Component {
const styleOptions = { const styleOptions = {
textAnchor: 'center', textAnchor: 'center',
strokeWidth: 1, strokeWidth: 1,
opacity: 1,
}; };
const rasterFolder = gui.addFolder('栅格可视化'); const rasterFolder = gui.addFolder('文本可视化');
rasterFolder rasterFolder
.add(styleOptions, 'textAnchor', [ .add(styleOptions, 'textAnchor', [
'center', 'center',
@ -85,6 +86,23 @@ export default class TextLayerDemo extends React.Component {
}); });
scene.render(); scene.render();
}); });
rasterFolder
.add(styleOptions, 'strokeWidth', 0, 10)
.onChange((strokeWidth: number) => {
pointLayer.style({
strokeWidth,
});
scene.render();
});
rasterFolder
.add(styleOptions, 'opacity', 0, 1)
.onChange((opacity: number) => {
pointLayer.style({
opacity,
});
scene.render();
});
// }); // });
} }

View File

@ -43,7 +43,8 @@ export default class DashLineDemo extends React.Component {
].reverse(), ].reverse(),
) )
.style({ .style({
lineType: 'dash', // lineType: 'dash',
opacity: 0.5,
}); });
scene.addLayer(lineLayer); scene.addLayer(lineLayer);

1627
yarn.lock

File diff suppressed because it is too large Load Diff