From 13ef54123245c3354c2276fff72aa93b82d1d2c5 Mon Sep 17 00:00:00 2001 From: thinkinggis Date: Thu, 26 Dec 2019 00:16:33 +0800 Subject: [PATCH] fix: layer style storkeColor->stroke --- build/rollup.config.js | 3 ++- packages/core/src/utils/vertex-compression.ts | 8 ++++---- packages/layers/src/core/BaseLayer.ts | 2 +- packages/layers/src/core/interface.ts | 7 +------ .../layers/src/plugins/ConfigSchemaValidationPlugin.ts | 4 ++-- packages/layers/src/point/index.ts | 2 +- packages/layers/src/point/models/fill.ts | 6 +++--- packages/layers/src/point/models/normal.ts | 6 +++--- packages/layers/src/point/shaders/fill_vert.glsl | 2 +- stories/Layers/components/data_update.tsx | 2 +- 10 files changed, 19 insertions(+), 23 deletions(-) diff --git a/build/rollup.config.js b/build/rollup.config.js index 4f1db7e8c7..74a5fe46f3 100644 --- a/build/rollup.config.js +++ b/build/rollup.config.js @@ -73,7 +73,8 @@ module.exports = [ 'isFunction', 'cloneDeep', 'isString', - 'isNumber' + 'isNumber', + 'merge' ] } }), diff --git a/packages/core/src/utils/vertex-compression.ts b/packages/core/src/utils/vertex-compression.ts index 1930d4531b..6f319b619b 100644 --- a/packages/core/src/utils/vertex-compression.ts +++ b/packages/core/src/utils/vertex-compression.ts @@ -14,7 +14,7 @@ export interface ICircleVertex { color: number[]; radius: number; opacity: number; - strokeColor: number[]; + stroke: number[]; strokeWidth: number; strokeOpacity: number; } @@ -68,7 +68,7 @@ export function packCircleVertex( tileY, shape, opacity, // packed buffer1 - strokeColor, + stroke, strokeWidth, strokeOpacity, // packed buffer2 } = props; @@ -81,8 +81,8 @@ export function packCircleVertex( packUint8ToFloat(color[2], color[3]), ]; const packedStrokeColor: [number, number] = [ - packUint8ToFloat(strokeColor[0], strokeColor[1]), - packUint8ToFloat(strokeColor[2], strokeColor[3]), + packUint8ToFloat(stroke[0], stroke[1]), + packUint8ToFloat(stroke[2], stroke[3]), ]; [ diff --git a/packages/layers/src/core/BaseLayer.ts b/packages/layers/src/core/BaseLayer.ts index 596f80a9f5..251469c731 100644 --- a/packages/layers/src/core/BaseLayer.ts +++ b/packages/layers/src/core/BaseLayer.ts @@ -55,7 +55,7 @@ let layerIdCounter = 0; export default class BaseLayer extends EventEmitter implements ILayer { public id: string = `${layerIdCounter++}`; - public name: string; + public name: string = `${layerIdCounter++}`; public type: string; public visible: boolean = true; public zIndex: number = 0; diff --git a/packages/layers/src/core/interface.ts b/packages/layers/src/core/interface.ts index 49e83cdd49..ef6d574a62 100644 --- a/packages/layers/src/core/interface.ts +++ b/packages/layers/src/core/interface.ts @@ -1,4 +1,4 @@ -export const enum lineStyleType { +export enum lineStyleType { 'solid' = 0.0, 'dash' = 1.0, } @@ -9,8 +9,3 @@ export interface ILineLayerStyleOptions { dashArray?: [number, number]; segmentNumber: number; } - -export const lineStyleObj: { [key: string]: number } = { - solid: 0.0, - dash: 1.0, -}; diff --git a/packages/layers/src/plugins/ConfigSchemaValidationPlugin.ts b/packages/layers/src/plugins/ConfigSchemaValidationPlugin.ts index da74dd38f3..0943149f53 100644 --- a/packages/layers/src/plugins/ConfigSchemaValidationPlugin.ts +++ b/packages/layers/src/plugins/ConfigSchemaValidationPlugin.ts @@ -21,12 +21,12 @@ export default class ConfigSchemaValidationPlugin implements ILayerPlugin { public apply(layer: ILayer) { layer.hooks.init.tap('ConfigSchemaValidationPlugin', () => { this.configService.registerLayerConfigSchemaValidator( - layer.name, + layer.name as string, layer.getConfigSchemaForValidation(), ); const { valid, errorText } = this.configService.validateLayerConfig( - layer.name, + layer.name as string, layer.getLayerConfig(), ); diff --git a/packages/layers/src/point/index.ts b/packages/layers/src/point/index.ts index 232d05edde..9ea48d5fe7 100644 --- a/packages/layers/src/point/index.ts +++ b/packages/layers/src/point/index.ts @@ -4,7 +4,7 @@ import PointModels, { PointType } from './models/index'; interface IPointLayerStyleOptions { opacity: number; strokeWidth: number; - strokeColor: string; + stroke: string; } export default class PointLayer extends BaseLayer { public type: string = 'PointLayer'; diff --git a/packages/layers/src/point/models/fill.ts b/packages/layers/src/point/models/fill.ts index 0b068eb6ca..b4f8fc548e 100644 --- a/packages/layers/src/point/models/fill.ts +++ b/packages/layers/src/point/models/fill.ts @@ -15,19 +15,19 @@ import pointFillVert from '../shaders/fill_vert.glsl'; interface IPointLayerStyleOptions { opacity: number; strokeWidth: number; - strokeColor: string; + stroke: string; } export default class FillModel extends BaseModel { public getUninforms(): IModelUniform { const { opacity = 1, - strokeColor = 'rgb(0,0,0,0)', + stroke = 'rgb(0,0,0,0)', strokeWidth = 1, } = this.layer.getLayerConfig() as IPointLayerStyleOptions; return { u_opacity: opacity, u_stroke_width: strokeWidth, - u_stroke_color: rgb2arr(strokeColor), + u_stroke_color: rgb2arr(stroke), }; } diff --git a/packages/layers/src/point/models/normal.ts b/packages/layers/src/point/models/normal.ts index 4dd82398a9..c0ef21654e 100644 --- a/packages/layers/src/point/models/normal.ts +++ b/packages/layers/src/point/models/normal.ts @@ -16,7 +16,7 @@ import normalVert from '../shaders/normal_vert.glsl'; interface IPointLayerStyleOptions { opacity: number; strokeWidth: number; - strokeColor: string; + stroke: string; } export function PointTriangulation(feature: IEncodeFeature) { const coordinates = feature.coordinates as number[]; @@ -36,13 +36,13 @@ export default class NormalModel extends BaseModel { public getUninforms(): IModelUniform { const { opacity = 1, - strokeColor = 'rgb(0,0,0,0)', + stroke = 'rgb(0,0,0,0)', strokeWidth = 1, } = this.layer.getLayerConfig() as IPointLayerStyleOptions; return { u_opacity: opacity, u_stroke_width: strokeWidth, - u_stroke_color: rgb2arr(strokeColor), + u_stroke_color: rgb2arr(stroke), }; } public buildModels(): IModel[] { diff --git a/packages/layers/src/point/shaders/fill_vert.glsl b/packages/layers/src/point/shaders/fill_vert.glsl index 6c02c62349..80cfc15b18 100644 --- a/packages/layers/src/point/shaders/fill_vert.glsl +++ b/packages/layers/src/point/shaders/fill_vert.glsl @@ -34,7 +34,7 @@ void main() { float antialiasblur = 1.0 / (a_Size + u_stroke_width); // construct point coords - v_data = vec4(extrude, antialiasblur, ); + v_data = vec4(extrude, antialiasblur,shape_type); setPickingColor(a_PickingColor); } diff --git a/stories/Layers/components/data_update.tsx b/stories/Layers/components/data_update.tsx index 26e22e90db..9146b89291 100644 --- a/stories/Layers/components/data_update.tsx +++ b/stories/Layers/components/data_update.tsx @@ -48,7 +48,7 @@ export default class DataUpdate extends React.Component { .active(false) .color('#2F54EB') .style({ - strokeColor: '#fff', + stroke: '#fff', strokeWidth: 2, opacity: 1, });