-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: onMouseEnter
& onMouseLeave
trigger between joined layers (#1671)
#2126
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -786,14 +786,23 @@ export default class Mapbox { | |
} | ||
}; | ||
|
||
_uniqueLayersCount(features: MapboxGeoJSONFeature[] | null) { | ||
if (!features) { | ||
return 0; | ||
} | ||
return features.filter( | ||
(feature, index) => features.findIndex(f => f.layer.id === feature.layer.id) === index | ||
).length; | ||
} | ||
|
||
_updateHover(e: MapMouseEvent) { | ||
const {props} = this; | ||
const shouldTrackHoveredFeatures = | ||
props.interactiveLayerIds && (props.onMouseMove || props.onMouseEnter || props.onMouseLeave); | ||
|
||
if (shouldTrackHoveredFeatures) { | ||
const eventType = e.type; | ||
const wasHovering = this._hoveredFeatures?.length > 0; | ||
const hoveredLayersCount = this._uniqueLayersCount(this._hoveredFeatures); | ||
let features; | ||
if (eventType === 'mousemove') { | ||
try { | ||
|
@@ -806,14 +815,14 @@ export default class Mapbox { | |
} else { | ||
features = []; | ||
} | ||
const isHovering = features.length > 0; | ||
const hoveringLayersCount = this._uniqueLayersCount(features); | ||
|
||
if (!isHovering && wasHovering) { | ||
if (hoveringLayersCount < hoveredLayersCount) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct, though? What if the layer count is the same but one layer is replaced by another? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't know if it's ok to call pointEvents twice in one callback |
||
e.type = 'mouseleave'; | ||
this._onPointerEvent(e); | ||
} | ||
this._hoveredFeatures = features; | ||
if (isHovering && !wasHovering) { | ||
if (hoveringLayersCount > hoveredLayersCount) { | ||
e.type = 'mouseenter'; | ||
this._onPointerEvent(e); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very inefficient. Use
new Set(ids).size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done