mirror of https://gitee.com/antv-l7/antv-l7
fix: 修复拾取状态残留导致的拾取高亮错误 (#1105)
* fix: clear last pick state before pick * style: lint style
This commit is contained in:
parent
c5b3e22677
commit
a6ab68a12e
|
@ -48,6 +48,9 @@ export default class PickingService implements IPickingService {
|
||||||
|
|
||||||
private lastPickTime: number = new Date().getTime();
|
private lastPickTime: number = new Date().getTime();
|
||||||
|
|
||||||
|
// Tip: 记录当前拾取中的 layers
|
||||||
|
private pickedLayers: ILayer[] = [];
|
||||||
|
|
||||||
public init(id: string) {
|
public init(id: string) {
|
||||||
const {
|
const {
|
||||||
createTexture2D,
|
createTexture2D,
|
||||||
|
@ -274,6 +277,12 @@ export default class PickingService implements IPickingService {
|
||||||
|
|
||||||
layer.renderModels(true);
|
layer.renderModels(true);
|
||||||
layer.hooks.afterPickingEncode.call();
|
layer.hooks.afterPickingEncode.call();
|
||||||
|
|
||||||
|
// Tip: clear last picked layer state
|
||||||
|
this.pickedLayers.map((pickedlayer) => {
|
||||||
|
this.selectFeature(pickedlayer, new Uint8Array([0, 0, 0, 0]));
|
||||||
|
});
|
||||||
|
|
||||||
const isPicked = this.pickFromPickingFBO(layer, target);
|
const isPicked = this.pickFromPickingFBO(layer, target);
|
||||||
this.layerService.pickedLayerId = isPicked ? +layer.id : -1;
|
this.layerService.pickedLayerId = isPicked ? +layer.id : -1;
|
||||||
|
|
||||||
|
@ -355,6 +364,7 @@ export default class PickingService implements IPickingService {
|
||||||
// trigger onHover/Click callback on layer
|
// trigger onHover/Click callback on layer
|
||||||
isPicked = true;
|
isPicked = true;
|
||||||
layer.setCurrentPickId(pickedFeatureIdx);
|
layer.setCurrentPickId(pickedFeatureIdx);
|
||||||
|
this.pickedLayers = [layer];
|
||||||
this.triggerHoverOnLayer(layer, layerTarget); // 触发拾取事件
|
this.triggerHoverOnLayer(layer, layerTarget); // 触发拾取事件
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -377,6 +387,7 @@ export default class PickingService implements IPickingService {
|
||||||
});
|
});
|
||||||
this.triggerHoverOnLayer(layer, layerTarget);
|
this.triggerHoverOnLayer(layer, layerTarget);
|
||||||
layer.setCurrentPickId(null);
|
layer.setCurrentPickId(null);
|
||||||
|
this.pickedLayers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enableHighlight) {
|
if (enableHighlight) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default class Amap2demo_polygon extends React.Component {
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
const scene = new Scene({
|
const scene = new Scene({
|
||||||
id: 'map',
|
id: 'map',
|
||||||
map: new GaodeMapV2({
|
map: new GaodeMap({
|
||||||
pitch: 40,
|
pitch: 40,
|
||||||
center: [120, 30],
|
center: [120, 30],
|
||||||
zoom: 13,
|
zoom: 13,
|
||||||
|
@ -44,33 +44,59 @@ export default class Amap2demo_polygon extends React.Component {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const data2 = {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: [
|
||||||
|
{
|
||||||
|
type: 'Feature',
|
||||||
|
properties: {
|
||||||
|
testOpacity: 0.8,
|
||||||
|
},
|
||||||
|
geometry: {
|
||||||
|
type: 'Polygon',
|
||||||
|
coordinates: [
|
||||||
|
[
|
||||||
|
[113.8623046875 + 1, 30.031055426540206],
|
||||||
|
[116.3232421875 + 1, 30.031055426540206],
|
||||||
|
[116.3232421875 + 1, 31.090574094954192],
|
||||||
|
[113.8623046875 + 1, 31.090574094954192],
|
||||||
|
[113.8623046875 + 1, 30.031055426540206],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const layer = new PolygonLayer({
|
const layer = new PolygonLayer({
|
||||||
autoFit: true,
|
autoFit: true,
|
||||||
})
|
})
|
||||||
.source(data)
|
.source(data)
|
||||||
.shape('fill')
|
.shape('fill')
|
||||||
.color('red')
|
.color('red')
|
||||||
|
.active(true)
|
||||||
.style({
|
.style({
|
||||||
opacityLinear: {
|
// opacityLinear: {
|
||||||
enable: true,
|
// enable: true,
|
||||||
dir: 'in',
|
// dir: 'in',
|
||||||
},
|
// },
|
||||||
});
|
});
|
||||||
scene.addLayer(layer);
|
scene.addLayer(layer);
|
||||||
|
|
||||||
const layer2 = new PolygonLayer({
|
const layer2 = new PolygonLayer({
|
||||||
autoFit: true,
|
autoFit: true,
|
||||||
})
|
})
|
||||||
.source(data)
|
.source(data2)
|
||||||
.shape('fill')
|
.shape('fill')
|
||||||
.color('red')
|
.color('#ff0')
|
||||||
|
.active(true)
|
||||||
.style({
|
.style({
|
||||||
opacity: 0.4,
|
// opacity: 0.4,
|
||||||
// opacityLinear: {
|
// opacityLinear: {
|
||||||
// enable: true,
|
// enable: true,
|
||||||
// dir: 'out',
|
// dir: 'out',
|
||||||
// },
|
// },
|
||||||
raisingHeight: 50000,
|
// raisingHeight: 50000,
|
||||||
});
|
});
|
||||||
scene.addLayer(layer2);
|
scene.addLayer(layer2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue