mirror of https://gitee.com/antv-l7/antv-l7
fix: 拾取操作 (#1405)
This commit is contained in:
parent
aed8e8cd6c
commit
f45c6a19d1
|
@ -67,6 +67,7 @@ export default () => {
|
||||||
stencil: true,
|
stencil: true,
|
||||||
map: new Map({
|
map: new Map({
|
||||||
center: [112, 30],
|
center: [112, 30],
|
||||||
|
|
||||||
// zoom: 12,
|
// zoom: 12,
|
||||||
zoom: 3,
|
zoom: 3,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -75,8 +75,8 @@ export default () => {
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((maskData) => {
|
.then((maskData) => {
|
||||||
const layer = new RasterLayer({
|
const layer = new RasterLayer({
|
||||||
// mask: true,
|
mask: true,
|
||||||
// maskfence: maskData,
|
maskfence: maskData,
|
||||||
});
|
});
|
||||||
|
|
||||||
const tileSource = new Source(
|
const tileSource = new Source(
|
||||||
|
|
|
@ -21,6 +21,7 @@ export default () => {
|
||||||
map: new Map({
|
map: new Map({
|
||||||
center: [60, 30],
|
center: [60, 30],
|
||||||
// zoom: 12,
|
// zoom: 12,
|
||||||
|
minZoom: 0,
|
||||||
zoom: 1,
|
zoom: 1,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
@ -51,6 +52,7 @@ export default () => {
|
||||||
zIndex: 1,
|
zIndex: 1,
|
||||||
})
|
})
|
||||||
.source(source)
|
.source(source)
|
||||||
|
.select(true)
|
||||||
.shape('fill')
|
.shape('fill')
|
||||||
.color('NAME_CHN', (NAME_CHN) => {
|
.color('NAME_CHN', (NAME_CHN) => {
|
||||||
const namestr = unicode2Char(NAME_CHN);
|
const namestr = unicode2Char(NAME_CHN);
|
||||||
|
|
|
@ -281,15 +281,16 @@ export default class PickingService implements IPickingService {
|
||||||
type === 'click' &&
|
type === 'click' &&
|
||||||
pickedColors?.toString() !== [0, 0, 0, 0].toString()
|
pickedColors?.toString() !== [0, 0, 0, 0].toString()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const selectedId = decodePickingColor(pickedColors);
|
const selectedId = decodePickingColor(pickedColors);
|
||||||
if (
|
if (
|
||||||
layer.getCurrentSelectedId() === null ||
|
layer.getCurrentSelectedId() === null ||
|
||||||
selectedId !== layer.getCurrentSelectedId()
|
selectedId !== layer.getCurrentSelectedId()
|
||||||
) {
|
) {
|
||||||
this.selectFeature(layer, pickedColors);
|
this.layerService.selectFeature(layer, pickedColors);
|
||||||
layer.setCurrentSelectedId(selectedId);
|
layer.setCurrentSelectedId(selectedId);
|
||||||
} else {
|
} else {
|
||||||
this.selectFeature(layer, new Uint8Array([0, 0, 0, 0])); // toggle select
|
this.layerService.selectFeature(layer, new Uint8Array([0, 0, 0, 0])); // toggle select
|
||||||
layer.setCurrentSelectedId(null);
|
layer.setCurrentSelectedId(null);
|
||||||
}
|
}
|
||||||
// if (!layer.isVector) {
|
// if (!layer.isVector) {
|
||||||
|
|
|
@ -237,18 +237,19 @@ export interface ITileLayerManager extends IBaseTileLayerManager{
|
||||||
|
|
||||||
export interface IBaseTileLayer {
|
export interface IBaseTileLayer {
|
||||||
sourceLayer: string;
|
sourceLayer: string;
|
||||||
pickRender(target: IInteractionTarget):void;
|
|
||||||
parent: ILayer;
|
parent: ILayer;
|
||||||
tileLayerManager: IBaseTileLayerManager;
|
tileLayerManager: ITileLayerManager;
|
||||||
tilesetManager: TilesetManager | undefined;
|
tilesetManager: TilesetManager | undefined;
|
||||||
|
pickRender(target: IInteractionTarget):void;
|
||||||
|
selectFeature(pickedColors: Uint8Array | undefined):void;
|
||||||
|
highlightPickedFeature(pickedColors: Uint8Array | undefined):void;
|
||||||
children: ILayer[];
|
children: ILayer[];
|
||||||
scaleField: any;
|
scaleField: any;
|
||||||
render(isPicking?: boolean): void;
|
render(isPicking?: boolean): void;
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
}
|
}
|
||||||
export interface ITileLayer extends IBaseTileLayer{
|
export interface ITileLayer extends IBaseTileLayer{
|
||||||
|
pickRender(target: IInteractionTarget):void;
|
||||||
tileLayerManager: ITileLayerManager;
|
|
||||||
pickLayers(target: IInteractionTarget): boolean;
|
pickLayers(target: IInteractionTarget): boolean;
|
||||||
clearPick(type: string): void;
|
clearPick(type: string): void;
|
||||||
clearPickState(): void;
|
clearPickState(): void;
|
||||||
|
@ -667,6 +668,8 @@ export interface ILayerService {
|
||||||
setEnableRender(flag: boolean): void;
|
setEnableRender(flag: boolean): void;
|
||||||
getOESTextureFloat(): boolean;
|
getOESTextureFloat(): boolean;
|
||||||
pickRender(layer: ILayer,target?: IInteractionTarget):void
|
pickRender(layer: ILayer,target?: IInteractionTarget):void
|
||||||
|
selectFeature(layer: ILayer, pickedColors: Uint8Array | undefined):void;
|
||||||
|
highlightPickedFeature(layer: ILayer, pickedColors: Uint8Array | undefined):void;
|
||||||
|
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,7 @@ export default class LayerService implements ILayerService {
|
||||||
.forEach((layer) => {
|
.forEach((layer) => {
|
||||||
this.layerList.push(layer);
|
this.layerList.push(layer);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
@ -226,6 +227,9 @@ export default class LayerService implements ILayerService {
|
||||||
public getShaderPickStat() {
|
public getShaderPickStat() {
|
||||||
return this.shaderPicking;
|
return this.shaderPicking;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For Pick
|
||||||
|
|
||||||
// 拾取绘制
|
// 拾取绘制
|
||||||
public pickRender(layer: ILayer,target: IInteractionTarget) {
|
public pickRender(layer: ILayer,target: IInteractionTarget) {
|
||||||
if(layer.tileLayer) {
|
if(layer.tileLayer) {
|
||||||
|
@ -248,6 +252,22 @@ export default class LayerService implements ILayerService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public selectFeature(layer: ILayer, pickedColors: Uint8Array | undefined) {
|
||||||
|
|
||||||
|
if(layer.tileLayer) {
|
||||||
|
return layer.tileLayer.selectFeature(pickedColors)
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
const [r, g, b] = pickedColors;
|
||||||
|
layer.hooks.beforeSelect.call([r, g, b]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public highlightPickedFeature(layer: ILayer,pickedColors: Uint8Array | undefined): void {
|
||||||
|
if(layer.tileLayer) {
|
||||||
|
return layer.tileLayer.highlightPickedFeature(pickedColors)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public clear() {
|
public clear() {
|
||||||
const color = rgb2arr(this.mapService.bgColor) as [
|
const color = rgb2arr(this.mapService.bgColor) as [
|
||||||
number,
|
number,
|
||||||
|
|
|
@ -1302,8 +1302,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
|
||||||
) {
|
) {
|
||||||
isPick = true;
|
isPick = true;
|
||||||
}
|
}
|
||||||
if (type === 'click')
|
|
||||||
console.log('enableSelect', type, this.isVisible(), enableSelect, isPick);
|
|
||||||
return this.isVisible() && isPick;
|
return this.isVisible() && isPick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ export class TileLayerService {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
get tiles():Tile[] {
|
get tiles():Tile[] {
|
||||||
return this.tiles;
|
return this._tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
hasTile(tileKey: string): boolean {
|
hasTile(tileKey: string): boolean {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ILayerService } from '@antv/l7-core';
|
import { ILayerService } from '@antv/l7-core';
|
||||||
import { TileLayerService } from './TileLayerService';
|
import { TileLayerService } from './TileLayerService';
|
||||||
import { ILayer, IInteractionTarget } from '@antv/l7-core';
|
import { IInteractionTarget } from '@antv/l7-core';
|
||||||
import Tile from '../tileFactory/Tile';
|
import Tile from '../tileFactory/Tile';
|
||||||
export interface ITilePickServiceOptions {
|
export interface ITilePickServiceOptions {
|
||||||
layerService: ILayerService;
|
layerService: ILayerService;
|
||||||
|
@ -20,10 +20,9 @@ export class TilePickService {
|
||||||
this.layerService.pickRender(pickLayer);
|
this.layerService.pickRender(pickLayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectFeature(layer: ILayer, pickedColors: Uint8Array | undefined) {
|
selectFeature(pickedColors: Uint8Array | undefined) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const [r, g, b] = pickedColors;
|
const [r, g, b] = pickedColors;
|
||||||
layer.hooks.beforeSelect.call([r, g, b]);
|
|
||||||
this.tileLayerService.tiles.map((tile: Tile) => {
|
this.tileLayerService.tiles.map((tile: Tile) => {
|
||||||
const layers = tile.getLayers();
|
const layers = tile.getLayers();
|
||||||
layers.forEach((layer) => {
|
layers.forEach((layer) => {
|
||||||
|
@ -31,10 +30,9 @@ export class TilePickService {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
highlightPickedFeature(layer: ILayer, pickedColors: Uint8Array | undefined) {
|
highlightPickedFeature(pickedColors: Uint8Array | undefined) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const [r, g, b] = pickedColors;
|
const [r, g, b] = pickedColors;
|
||||||
layer.hooks.beforeSelect.call([r, g, b]);
|
|
||||||
this.tileLayerService.tiles.map((tile: Tile) => {
|
this.tileLayerService.tiles.map((tile: Tile) => {
|
||||||
const layers = tile.getLayers();
|
const layers = tile.getLayers();
|
||||||
layers.forEach((layer) => {
|
layers.forEach((layer) => {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import TileModel from '../../models/tileModel';
|
||||||
|
|
||||||
export default class TileDebugLayer extends BaseLayer<IBaseLayerStyleOptions> {
|
export default class TileDebugLayer extends BaseLayer<IBaseLayerStyleOptions> {
|
||||||
public type: string = 'TileDebugLayer';
|
public type: string = 'TileDebugLayer';
|
||||||
|
public zIndex:number = 10000;
|
||||||
public defaultSourceConfig = {
|
public defaultSourceConfig = {
|
||||||
data: [],
|
data: [],
|
||||||
options: {
|
options: {
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import {
|
import {
|
||||||
IBaseTileLayer,
|
IBaseTileLayer,
|
||||||
ITileLayerOPtions,
|
ITileLayerOPtions,
|
||||||
IBaseTileLayerManager,
|
// IBaseTileLayerManager,
|
||||||
} from '@antv/l7-core';
|
} from '@antv/l7-core';
|
||||||
import { BaseMapTileLayerManager } from '../manager/mapLayerManager';
|
import { BaseMapTileLayerManager } from '../manager/mapLayerManager';
|
||||||
|
|
||||||
import { Base } from './base';
|
import { Base } from './base';
|
||||||
|
|
||||||
export class MapTileLayer extends Base implements IBaseTileLayer {
|
export class MapTileLayer extends Base implements IBaseTileLayer {
|
||||||
public tileLayerManager: IBaseTileLayerManager;
|
// public tileLayerManager: IBaseTileLayerManager;
|
||||||
constructor({
|
constructor({
|
||||||
parent,
|
parent,
|
||||||
rendererService,
|
rendererService,
|
||||||
|
|
|
@ -184,6 +184,13 @@ export class Base {
|
||||||
public pickRender(target: IInteractionTarget) {
|
public pickRender(target: IInteractionTarget) {
|
||||||
this.tilePickService.pickRender(target);
|
this.tilePickService.pickRender(target);
|
||||||
}
|
}
|
||||||
|
public selectFeature(pickedColors: Uint8Array | undefined) {
|
||||||
|
this.tilePickService.selectFeature(pickedColors)
|
||||||
|
}
|
||||||
|
|
||||||
|
public highlightPickedFeature(pickedColors: Uint8Array | undefined) {
|
||||||
|
this.tilePickService.highlightPickedFeature(pickedColors)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue