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: 缩放控件 zoom 新增 showZoom 配置,用于控制是否展示 zoom 数值 #1786

Merged
merged 1 commit into from
Aug 21, 2023
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
6 changes: 5 additions & 1 deletion dev-demos/component/control/zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const Demo: FunctionComponent = () => {
});

newScene.on('loaded', () => {
const newControl = new Zoom();
const newControl = new Zoom({
showZoom: true,
});
newScene.addControl(newControl);
setControl(newControl);
});
Expand All @@ -32,6 +34,7 @@ const Demo: FunctionComponent = () => {
zoomInTitle: 'in',
zoomOutText: '减',
zoomOutTitle: 'out',
showZoom: undefined,
});
}}
>
Expand All @@ -44,6 +47,7 @@ const Demo: FunctionComponent = () => {
zoomInTitle: undefined,
zoomOutText: undefined,
zoomOutTitle: undefined,
showZoom: true,
});
}}
>
Expand Down
21 changes: 19 additions & 2 deletions packages/component/src/control/zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IZoomControlOption extends IControlOption {
zoomInTitle: string;
zoomOutText: DOM.ELType | string;
zoomOutTitle: string;
showZoom: boolean;
}

export { Zoom };
Expand All @@ -16,6 +17,7 @@ export default class Zoom extends Control<IZoomControlOption> {
private disabled: boolean;
private zoomInButton: HTMLElement;
private zoomOutButton: HTMLElement;
private zoomNumDiv: HTMLElement;

public getDefault(option: Partial<IZoomControlOption>) {
return {
Expand All @@ -26,6 +28,7 @@ export default class Zoom extends Control<IZoomControlOption> {
zoomInTitle: 'Zoom in',
zoomOutText: createL7Icon('l7-icon-narrow'),
zoomOutTitle: 'Zoom out',
showZoom: false,
};
}
public setOptions(newOptions: Partial<IZoomControlOption>) {
Expand All @@ -36,6 +39,7 @@ export default class Zoom extends Control<IZoomControlOption> {
'zoomInTitle',
'zoomOutText',
'zoomOutTitle',
'showZoom',
])
) {
this.resetButtonGroup(this.container);
Expand Down Expand Up @@ -94,6 +98,14 @@ export default class Zoom extends Control<IZoomControlOption> {
container,
this.zoomIn,
);
if (this.controlOption.showZoom) {
this.zoomNumDiv = this.createButton(
'0',
'',
'l7-button-control l7-control-zoom__number',
container,
);
}
this.zoomOutButton = this.createButton(
this.controlOption.zoomOutText,
this.controlOption.zoomOutTitle,
Expand All @@ -109,7 +121,7 @@ export default class Zoom extends Control<IZoomControlOption> {
tile: string,
className: string,
container: HTMLElement,
fn: (...arg: any[]) => any,
fn?: (...arg: any[]) => any,
) {
const link = DOM.create('button', className, container) as HTMLLinkElement;
if (typeof html === 'string') {
Expand All @@ -118,7 +130,9 @@ export default class Zoom extends Control<IZoomControlOption> {
link.append(html);
}
link.title = tile;
link.addEventListener('click', fn);
if (fn) {
link.addEventListener('click', fn);
}
return link;
}

Expand All @@ -129,6 +143,9 @@ export default class Zoom extends Control<IZoomControlOption> {
if (this.disabled || mapsService.getZoom() <= mapsService.getMinZoom()) {
this.zoomOutButton.setAttribute('disabled', 'true');
}
if (this.controlOption.showZoom && this.zoomNumDiv) {
this.zoomNumDiv.innerText = String(Math.floor(mapsService.getZoom()));
}
if (this.disabled || mapsService.getZoom() >= mapsService.getMaxZoom()) {
this.zoomInButton.setAttribute('disabled', 'true');
}
Expand Down
20 changes: 14 additions & 6 deletions packages/component/src/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,29 @@
min-width: 130px;
}
.l7-control-zoom {
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.15);
border-radius: 2px;
overflow: hidden;
border-radius: 2px;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.15);
}
.l7-control-zoom .l7-button-control {
box-shadow: 0 0 0;
border-radius: 0;
font-size: 16px;
border-bottom: 1px solid #f0f0f0;
border-radius: 0;
box-shadow: 0 0 0;
}
.l7-control-zoom .l7-button-control .l7-iconfont {
width: 14px;
height: 14px;
}
.l7-control-zoom .l7-button-control:first-child {
border-bottom: 1px solid #f0f0f0;
.l7-control-zoom .l7-button-control:last-child {
border-bottom: 0;
}
.l7-control-zoom .l7-control-zoom__number {
color: #595959;
padding: 0;
}
.l7-control-zoom .l7-control-zoom__number:hover {
background-color: #fff;
}
.l7-control-scale {
display: flex;
Expand Down
20 changes: 14 additions & 6 deletions packages/component/src/css/zoom.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
@zoom-icon-size: 14px;

.l7-control-zoom {
box-shadow: @l7-control-shadow;
border-radius: @l7-btn-control-border-radius;
overflow: hidden;
border-radius: @l7-btn-control-border-radius;
box-shadow: @l7-control-shadow;
.l7-button-control {
box-shadow: 0 0 0;
border-radius: 0;
font-size: @l7-btn-icon-size;
border-bottom: 1px solid @l7-btn-border-color;
border-radius: 0;
box-shadow: 0 0 0;
.l7-iconfont {
width: @zoom-icon-size;
height: @zoom-icon-size;
}
&:first-child {
border-bottom: 1px solid @l7-btn-border-color;
&:last-child {
border-bottom: 0;
}
}
& &__number {
color: @l7-control-font-color;
padding: 0;
&:hover {
background-color: @l7-btn-control-bg-color;
}
}
}
13 changes: 7 additions & 6 deletions packages/site/docs/api/component/control/zoom.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ scene.on('loaded', () => {

## 配置

| 名称 | 说明 | 类型 |
| ------------ | ----------------------- | ------------------------- |
| zoomInText | 放大按钮的展示内容 | `Element` \| `string` |
| zoomInTitle | 放大按钮的 `title` 属性 | `string` |
| zoomOutText | 缩小按钮的展示内容 | `Element` \| `string` |
| zoomOutTitle | 缩小按钮的 `title` 属性 | `string` |
| 名称 | 说明 | 类型 |
| ------------ | -------------------------------------------- | --------------------- |
| zoomInText | 放大按钮的展示内容 | `Element` \| `string` |
| zoomInTitle | 放大按钮的 `title` 属性 | `string` |
| zoomOutText | 缩小按钮的展示内容 | `Element` \| `string` |
| zoomOutTitle | 缩小按钮的 `title` 属性 | `string` |
| showZoom | 是否展示地图当前实时 zoom 数值,默认向下取整 | `boolean` |

<embed src="@/docs/common/control/api.md"></embed>

Expand Down
Loading