gpt4 book ai didi

angular-google-maps - 为 agm snazzy-info-window 设置信息窗口偏移量

转载 作者:行者123 更新时间:2023-12-03 23:14:04 27 4
gpt4 key购买 nike

我正在使用 agm 和 agm snazzy-info 窗口。由于我使用的标记很小,信息窗口离标记太远。
看着时髦的信息窗口文档 -
https://github.com/atmist/snazzy-info-window#offset似乎他们让您设置与标记的偏移量。好像 agm snazzy-info-window 隐藏了这个选项,见 https://angular-maps.com/api-docs/agm-snazzy-info-window/ .

有没有办法使用 agm snazzy-info 窗口控制偏移量?

最佳答案

确实, offset property根据 angular-google-maps repository未通过 AgmSnazzyInfoWindow 暴露成分。规避此限制的一种选择是引入扩展 AgmSnazzyInfoWindow 的自定义组件。组件并支持指定 offset属性,例如:

import {
Component,
AfterViewInit,
Input
} from "@angular/core";
import { AgmSnazzyInfoWindow } from "@agm/snazzy-info-window";

@Component({
// tslint:disable-next-line:component-selector
selector: 'my-info-window',
template:
"<div #outerWrapper><div #viewContainer></div></div><ng-content></ng-content>"
})
export class MyInfoWindowComponent extends AgmSnazzyInfoWindow
implements AfterViewInit {

/**
* A custom padding size around the content of the info window.
*/
@Input() offset: {top: string, left: string};

ngAfterViewInit() {
super.ngAfterViewInit();
this._snazzyInfoWindowInitialized.then(() => {
this._nativeSnazzyInfoWindow._opts.offset = this.offset;
});
}
}

现在可以像这样指定偏移量:
<agm-map [latitude]="center.lat" [longitude]="center.lng">
<agm-marker [latitude]="center.lat" [longitude]="center.lng">
<my-info-window
[offset]="{
top: '-60px',
left: '0px'
}"
>
<ng-template>
Phoenix
</ng-template>
</my-info-window>
</agm-marker>
</agm-map>

Here is a demo

关于angular-google-maps - 为 agm snazzy-info-window 设置信息窗口偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54081063/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com