Skip to content

Commit

Permalink
fix: 修复 Multi 数据获取问题
Browse files Browse the repository at this point in the history
  • Loading branch information
heiyexing committed Feb 1, 2024
1 parent 53e87a9 commit 6509355
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/drawer/line-drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ export class LineDrawer extends LineMode<ILineDrawerOptions> {
}
}

getData(): ILineFeature[] {
return joinMultiFeatures(this.getLineData());
getData(getOriginData = false): ILineFeature[] {
const lines = this.getLineData();
if (getOriginData) {
return lines;
}
return joinMultiFeatures(lines);
}

getRenderTypes(): IRenderType[] {
Expand Down
8 changes: 6 additions & 2 deletions src/drawer/point-drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ export class PointDrawer extends PointMode<IPointDrawerOptions> {
);
}

getData() {
return joinMultiFeatures(this.getPointData());
getData(getOriginData = false) {
const points = this.getPointData();
if (getOriginData) {
return points;
}
return joinMultiFeatures(points);
}

onPointCreate(e: ILayerMouseEvent<IPointFeature>): IPointFeature | undefined {
Expand Down
13 changes: 7 additions & 6 deletions src/mode/base-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export abstract class BaseMode<
/**
* 获取数据
*/
abstract getData(): Feature[];
abstract getData(getOriginData?: boolean): Feature[];

/**
* 获取主图层实例
Expand Down Expand Up @@ -263,7 +263,8 @@ export abstract class BaseMode<
let previousSelectFeature: Feature | null = null;
const onSourceChange = () => {
const newSelectFeature =
this.getData().find((feature) => feature.properties?.isActive) || null;
this.getData(true).find((feature) => feature.properties?.isActive) ||
null;
if (
previousSelectFeature?.properties?.id !==
newSelectFeature?.properties?.id
Expand Down Expand Up @@ -395,7 +396,7 @@ export abstract class BaseMode<
// 传入 Feature 或者 id 获取当前数据中的目标 Feature
getTargetFeature(
target: Feature | string | null | undefined,
data = this.getData(),
data = this.getData(true),
) {
let targetFeature: IBaseFeature | null = null;
if (target) {
Expand Down Expand Up @@ -425,7 +426,7 @@ export abstract class BaseMode<
* 删除当前active的绘制物
*/
removeActiveFeature() {
const activeItem = this.getData().find((item) => {
const activeItem = this.getData(true).find((item) => {
const { isActive, isDraw } = item.properties ?? {};
return isActive || isDraw;
});
Expand All @@ -440,7 +441,7 @@ export abstract class BaseMode<
* @param target
*/
removeFeature(target: Feature | string) {
const data = this.getData();
const data = this.getData(true);
const targetFeature = this.getTargetFeature(target);
if (targetFeature) {
this.setData(
Expand All @@ -455,7 +456,7 @@ export abstract class BaseMode<
* 矫正正在绘制Feature的虚线部分(Drawer中都是在onSceneMouseMove中进行绘制)
*/
correctDrawItem() {
const drawItem = this.getData().find((item) => item.properties?.isDraw);
const drawItem = this.getData(true).find((item) => item.properties?.isDraw);
// 如果当前有正在绘制的元素,需要将虚线部分与鼠标位置表现一致,而非history保存时的虚线位置
if (drawItem) {
this.onSceneMouseMove({
Expand Down
8 changes: 6 additions & 2 deletions src/mode/polygon-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ export abstract class PolygonMode<
return ['polygon', 'line', 'dashLine', 'midPoint', 'point', 'text'];
}

getData(): IPolygonFeature[] {
return joinMultiFeatures(this.getPolygonData());
getData(getOriginData = false): IPolygonFeature[] {
const polygons = this.getPolygonData();
if (getOriginData) {
return polygons;
}
return joinMultiFeatures(polygons);
}

getMainLayer() {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/adsorb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ export const getAdsorbPosition: ({
const { data: adsorbData, pointAdsorbPixel, lineAdsorbPixel } = adsorbOptions;
let features: AdsorbTargetFeature[] = [];
if (adsorbData === 'allDrawData') {
features = BaseMode.instances.map((draw) => draw.getData()).flat();
features = BaseMode.instances.map((draw) => draw.getData(true)).flat();
} else if (adsorbData === 'drawData') {
features = draw.getData();
features = draw.getData(true);
} else if (adsorbData instanceof Function) {
features = adsorbData(position);
} else {
Expand Down

0 comments on commit 6509355

Please sign in to comment.