Skip to content

Commit

Permalink
fix picking bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoji Chen committed Apr 29, 2019
1 parent 647e4c5 commit 5caf7f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions modules/core/src/lib/deck-picker.js
Expand Up @@ -102,8 +102,7 @@ export default class DeckPicker {
}

// Returns a new picking info object by assuming the last picked object is still picked
getLastPickedObject({x, y, layers, viewports}) {
const lastPickedInfo = this.lastPickedInfo.info;
getLastPickedObject({x, y, layers, viewports}, lastPickedInfo = this.lastPickedInfo.info) {
const lastPickedLayerId = lastPickedInfo && lastPickedInfo.layer && lastPickedInfo.layer.id;
const layer = lastPickedLayerId ? layers.find(l => l.id === lastPickedLayerId) : null;
const coordinate = viewports[0] && viewports[0].unproject([x, y]);
Expand Down
32 changes: 16 additions & 16 deletions modules/core/src/lib/deck.js
Expand Up @@ -128,6 +128,7 @@ export default class Deck {

this._needsRedraw = true;
this._pickRequest = {};
this._pickedInfo = null;

this.viewState = props.initialViewState || null; // Internal view state if no callback is supplied
this.interactiveState = {
Expand Down Expand Up @@ -163,6 +164,7 @@ export default class Deck {
finalize() {
this.animationLoop.stop();
this.animationLoop = null;
this._pickedInfo = null;

if (this.layerManager) {
this.layerManager.finalize();
Expand Down Expand Up @@ -465,7 +467,7 @@ export default class Deck {
// The `pointermove` event may fire multiple times in between two animation frames,
// it's a waste of time to run picking without rerender. Instead we save the last pick
// request and only do it once on the next animation frame.
_requestPick({event, callback, mode, immediate}) {
_requestPick({event, callback, mode}) {
const {_pickRequest} = this;
if (event.type === 'pointerleave') {
_pickRequest.x = -1;
Expand All @@ -486,10 +488,6 @@ export default class Deck {
_pickRequest.callback = callback;
_pickRequest.event = event;
_pickRequest.mode = mode;

if (immediate) {
this._pickAndCallback();
}
}

// Actually run picking
Expand Down Expand Up @@ -705,12 +703,15 @@ export default class Deck {

// Reuse last picked object
const layers = this.layerManager.getLayers();
const info = this.deckPicker.getLastPickedObject({
x: pos.x,
y: pos.y,
layers,
viewports: this.getViewports(pos)
});
const info = this.deckPicker.getLastPickedObject(
{
x: pos.x,
y: pos.y,
layers,
viewports: this.getViewports(pos)
},
this._pickedInfo
);

const {layer} = info;
const layerHandler =
Expand All @@ -727,11 +728,10 @@ export default class Deck {
}

_onPointerDown(event) {
this._requestPick({
callback: null,
event,
mode: 'hover',
immediate: true
const pos = event.offsetCenter;
this._pickedInfo = this.pickObject({
x: pos.x,
y: pos.y
});
}

Expand Down

0 comments on commit 5caf7f1

Please sign in to comment.