Skip to content

Commit

Permalink
[fix]boxSelect选择mvt不生效
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Jun 21, 2024
1 parent 2dfc53f commit 512406f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/core/src/services/interaction/IPickingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ILayerPickService {
* @param target 触发对象
*/
pickRender(target: IInteractionTarget): void;
pickBoxSelectTiles(box: [number, number, number, number], map:any): void;
/**
* 为图层设置选中对象
* @param pickedColors
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/services/interaction/PickingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ export default class PickingService implements IPickingService {
stencil: 0,
depth: 1,
});
layer.hooks.beforePickingEncode.call();
layer.renderModels({
ispick: true,
});
layer.hooks.afterPickingEncode.call();
layer.layerPickService.pickBoxSelectTiles(box, this.mapService.map);
const features = this.pickBox(layer, box);
cb(features);
});
Expand Down
7 changes: 7 additions & 0 deletions packages/layers/src/tile/service/TileLayerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export class TileLayerService {
);
}

public getVisibleTileByBox(minLngLat: ILngLat, maxLngLat: ILngLat): ITile[] | [] {
// 加载完成 & 可见 & 鼠标选中
return this.layerTiles.filter(
(tile) => tile.isLoaded && tile.visible && tile.boxInBounds(minLngLat, maxLngLat),
);
}

public removeTile(tileKey: string) {
const index = this.layerTiles.findIndex((t) => t.key === tileKey);
const tile = this.layerTiles.splice(index, 1);
Expand Down
13 changes: 13 additions & 0 deletions packages/layers/src/tile/service/TilePickService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { decodePickingColor, encodePickingColor } from '@antv/l7-utils';
import { TileLayerService } from './TileLayerService';
import { TileSourceService } from './TileSourceService';

export interface ITilePickServiceOptions {
layerService: ILayerService;
tileLayerService: TileLayerService;
Expand Down Expand Up @@ -43,6 +44,18 @@ export class TilePickService implements ITilePickService {
pickLayer?.layerPickService.pickRender(target);
}
}
public pickBoxSelectTiles(box:[number, number, number, number], map: any) {
const [x, y, x1, y1]= box;
const minLngLat = map.unproject({x, y});
const maxLngLat = map.unproject({x:x1, y:y1})
console.log(minLngLat, maxLngLat)
const tiles = this.tileLayerService.getVisibleTileByBox(minLngLat, maxLngLat);
tiles.forEach(tile=>{
// TODO 多图层拾取
const pickLayer = tile.getMainLayer();
pickLayer?.layerPickService.pickRender(minLngLat);
})
}

public pick(layer: ILayer, target: IInteractionTarget) {
const container = this.parent.getContainer();
Expand Down
12 changes: 12 additions & 0 deletions packages/layers/src/tile/tileFactory/Tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export default abstract class Tile implements ITile {
return lng >= minLng && lng <= maxLng && lat >= minLat && lat <= maxLat;
}

public boxInBounds(minLnglat: ILngLat, maxLngLat: ILngLat): boolean {
const [ leftLng, leftLat, rightLng, rightLat] = this.sourceTile.bounds;
const { lng: minLng, lat: minLat } = minLnglat;
const { lng: maxLng, lat: maxLat } = maxLngLat;
const inner = leftLng >= minLng && rightLng <= maxLng && leftLat >= minLat && rightLat <= maxLat;
const left = leftLng <= minLng && rightLng >= minLng;
const right = leftLng <= maxLng && rightLng >= maxLng;
const top = leftLat <= minLat && rightLat >= minLat;
const bottom = leftLat <= maxLat && rightLat >= maxLat;
return inner || left || right || top || bottom;
}

protected getLayerOptions() {
const options = this.parent.getLayerConfig();
return {
Expand Down

0 comments on commit 512406f

Please sign in to comment.