fix: text update color

This commit is contained in:
thinkinggis 2020-02-14 15:59:03 +08:00
parent b39a32f9e9
commit 091a4b6a15
3 changed files with 34 additions and 11 deletions

View File

@ -64,7 +64,13 @@ export default class DataMappingPlugin implements ILayerPlugin {
if (filter?.needRemapping) { if (filter?.needRemapping) {
layer.setEncodedData(this.mapping(attributes, filterData)); layer.setEncodedData(this.mapping(attributes, filterData));
} else { } else {
layer.setEncodedData(this.mapping(attributesToRemapping, filterData)); layer.setEncodedData(
this.mapping(
attributesToRemapping,
filterData,
layer.getEncodedData(),
),
);
} }
this.logger.debug('remapping finished'); this.logger.debug('remapping finished');
@ -99,11 +105,14 @@ export default class DataMappingPlugin implements ILayerPlugin {
private mapping( private mapping(
attributes: IStyleAttribute[], attributes: IStyleAttribute[],
data: IParseDataItem[], data: IParseDataItem[],
predata?: IEncodeFeature[],
): IEncodeFeature[] { ): IEncodeFeature[] {
return data.map((record: IParseDataItem) => { return data.map((record: IParseDataItem, i) => {
const preRecord = predata ? predata[i] : {};
const encodeRecord: IEncodeFeature = { const encodeRecord: IEncodeFeature = {
id: record._id, id: record._id,
coordinates: record.coordinates, coordinates: record.coordinates,
...preRecord,
}; };
attributes attributes
.filter((attribute) => attribute.scale !== undefined) .filter((attribute) => attribute.scale !== undefined)

View File

@ -86,6 +86,13 @@ export default class TextModel extends BaseModel {
private extent: [[number, number], [number, number]]; private extent: [[number, number], [number, number]];
private textureHeight: number = 0; private textureHeight: number = 0;
private preTextStyle: Partial<IPointTextLayerStyleOptions> = {}; private preTextStyle: Partial<IPointTextLayerStyleOptions> = {};
private glyphInfoMap: {
[key: string]: {
shaping: any;
glyphQuads: IGlyphQuad[];
centroid: number[];
};
} = {};
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
const { const {
@ -284,7 +291,7 @@ export default class TextModel extends BaseModel {
} = this.layer.getLayerConfig() as IPointTextLayerStyleOptions; } = this.layer.getLayerConfig() as IPointTextLayerStyleOptions;
const data = this.layer.getEncodedData(); const data = this.layer.getEncodedData();
this.glyphInfo = data.map((feature: IEncodeFeature) => { this.glyphInfo = data.map((feature: IEncodeFeature) => {
const { shape = '', coordinates } = feature; const { shape = '', coordinates, id } = feature;
const shaping = shapeText( const shaping = shapeText(
shape.toString(), shape.toString(),
mapping, mapping,
@ -298,6 +305,13 @@ export default class TextModel extends BaseModel {
feature.shaping = shaping; feature.shaping = shaping;
feature.glyphQuads = glyphQuads; feature.glyphQuads = glyphQuads;
feature.centroid = calculteCentroid(coordinates); feature.centroid = calculteCentroid(coordinates);
if (id) {
this.glyphInfoMap[id] = {
shaping,
glyphQuads,
centroid: calculteCentroid(coordinates),
};
}
return feature; return feature;
}); });
} }

View File

@ -39,15 +39,15 @@ export default class TextLayerDemo extends React.Component {
y: 'w', y: 'w',
}, },
}) })
// .shape('m', 'text') .shape('m', 'text')
.shape('circle') // .shape('circle')
.size(12) .size(12)
.filter('t', (t) => { .filter('t', (t) => {
return t > 14; return t > 14;
}) })
.color('red') .color('red')
.style({ .style({
// textAllowOverlap: true, textAllowOverlap: true,
// fontWeight: 200, // fontWeight: 200,
// textAnchor: 'center', // 文本相对锚点的位置 center|left|right|top|bottom|top-left // textAnchor: 'center', // 文本相对锚点的位置 center|left|right|top|bottom|top-left
// textOffset: [0, 0], // 文本相对锚点的偏移量 [水平, 垂直] // textOffset: [0, 0], // 文本相对锚点的偏移量 [水平, 垂直]
@ -90,12 +90,12 @@ export default class TextLayerDemo extends React.Component {
}); });
rasterFolder rasterFolder
.add(styleOptions, 'strokeWidth', 0, 1000) .add(styleOptions, 'strokeWidth', 0, 10)
.onChange((strokeWidth: number) => { .onChange((strokeWidth: number) => {
// pointLayer.filter('t', (t: number) => { pointLayer.filter('t', (t: number) => {
// return t > strokeWidth; return t > strokeWidth;
// }); });
pointLayer.setData(pointsData.list.slice(0, strokeWidth)); // pointLayer.setData(pointsData.list.slice(0, strokeWidth));
scene.render(); scene.render();
}); });
rasterFolder rasterFolder