Skip to content
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

feat: 新增 Popup 支持更新 className 和 style #2457

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-ligers-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/l7-component': patch
---

popup 更新支持 className 和 style
1 change: 1 addition & 0 deletions examples/demos/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { MapRender as control } from './control';
export { MapRender as layerPopup } from './layerPopup';
export { MapRender as marker } from './marker';
export { MapRender as popup } from './popup';
export { MapRender as swipe } from './swipe';
36 changes: 36 additions & 0 deletions examples/demos/components/popup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Popup, Scene } from '@antv/l7';
import * as allMap from '@antv/l7-maps';
import type { RenderDemoOptions } from '../../types';

export function MapRender(options: RenderDemoOptions) {
const scene = new Scene({
id: 'map',
renderer: options.renderer,
map: new allMap.GaodeMap({
style: 'light',
center: [121.435159, 31.256971],
zoom: 14.89,
minZoom: 10,
}),
});
scene.on('loaded', () => {
const popup = new Popup({
lngLat: {
lng: 121.435159,
lat: 31.256971,
},
html: '<div>123456</div>',
className: String(Math.random()),
style: `z-index: ${String(Math.random())}`,
});

setInterval(() => {
popup.setOptions({
className: String(Math.random()),
style: `z-index: ${String(Math.floor(Math.random() * 100))}`,
});
}, 2000);

scene.addPopup(popup);
});
}
12 changes: 10 additions & 2 deletions packages/component/src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export default class Popup<O extends IPopupOption = IPopupOption>

public setOptions(option: Partial<O>) {
this.show();
const { className: oldClassName } = this.popupOption;
this.popupOption = {
...this.popupOption,
...option,
Expand All @@ -182,8 +183,6 @@ export default class Popup<O extends IPopupOption = IPopupOption>
'maxWidth',
'anchor',
'stopPropagation',
'className',
'style',
'lngLat',
'offsets',
])
Expand Down Expand Up @@ -216,6 +215,15 @@ export default class Popup<O extends IPopupOption = IPopupOption>
} else if (this.checkUpdateOption(option, ['text']) && option.text) {
this.setText(option.text);
}
if (this.checkUpdateOption(option, ['className'])) {
if (oldClassName) {
this.container.classList.remove(oldClassName ?? '');
}
this.container.classList.add(option.className ?? '');
}
if (this.checkUpdateOption(option, ['style'])) {
DOM.addStyle(this.container, option.style ?? '');
}
if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
this.setLnglat(option.lngLat);
}
Expand Down
Loading