Skip to content

Commit

Permalink
fix: 修复 LayerPopup trigger & items 导致的 Bug (#2075)
Browse files Browse the repository at this point in the history
* fix: 修复 LayerPopup trigger 切换时的问题

* fix: 修复 layerPopup items 为空的问题
  • Loading branch information
heiyexing authored Nov 21, 2023
1 parent 8a3193e commit c135340
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
23 changes: 23 additions & 0 deletions dev-demos/component/popup/layerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,29 @@ const Demo: FunctionComponent = () => {

return (
<>
<div>
<button
onClick={() => {
popup?.setOptions({
trigger:
popup?.getOptions().trigger === 'click' ? 'hover' : 'click',
});
console.log(popup?.getOptions().trigger);
}}
>
切换
</button>

<button
onClick={() => {
popup?.setOptions({
items: [],
});
}}
>
清空 items
</button>
</div>
<div
id="map"
style={{
Expand Down
16 changes: 10 additions & 6 deletions packages/component/src/popup/layerPopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,26 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
public setOptions(option: Partial<ILayerPopupOption>) {
this.unbindLayerEvent();
const newOption = { ...option };
const trigger = option.trigger || this.popupOption.trigger;
if (newOption.items?.length === 0 && trigger === 'hover') {
newOption.followCursor = false;
}
const trigger = newOption.trigger || this.popupOption.trigger;
const items = newOption.items || this.popupOption.items;
const isEmptyItems = items?.length === 0;
newOption.followCursor = trigger === 'hover' && !isEmptyItems;

super.setOptions(newOption);
this.bindLayerEvent();
if (isEmptyItems) {
this.hide();
}
return this;
}

protected getDefault(option: Partial<ILayerPopupOption>): ILayerPopupOption {
const isClickTrigger = option.trigger === 'click';
const isHoverTrigger = option.trigger === 'hover';

return {
...super.getDefault(option),
trigger: 'hover',
followCursor: !isClickTrigger,
followCursor: isHoverTrigger,
lngLat: {
lng: 0,
lat: 0,
Expand Down

0 comments on commit c135340

Please sign in to comment.