gpt4 book ai didi

javascript - Angular Material 对话框 - AGM 贴图

转载 作者:行者123 更新时间:2023-11-28 00:23:41 26 4
gpt4 key购买 nike

我正在尝试创建一个 Material 对话框以使用 AGM( Angular 谷歌地图)捕获用户位置。我的主页上有一个工作示例,但是当对话框打开时,它只会在 map 应该显示的位置显示一个空白区域。当我更改 CSS 高度并且可以看到白色区域在增大/缩小时。

有人知道为什么吗?或者有什么我可以尝试的吗?

这是我的对话框 HTML...

<h1 mat-dialog-title>Where do you work?</h1>
<div mat-dialog-content>
<mat-form-field>
<input matInput placeholder="enter work location" autocorrect="off" autocapitalize="off" spellcheck="off" type="text" class="form-control" #search [formControl]="searchControl">
<agm-map id="capture-work-map" [latitude]="coordinates.lat" [longitude]="coordinates.lng" [zoom]="zoom">
<agm-marker [markerDraggable]="true" [latitude]="coordinates.lat" [longitude]="coordinates.lng"></agm-marker>
</agm-map>
</mat-form-field>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()">Cancel</button>
<button mat-button [mat-dialog-close]="coordinates" cdkFocusInitial>Update</button>
</div>

这是我的对话框 CSS...

#capture-work-map {
height: 300px;
}

TypeScript 对话框...

import {Component, ElementRef, Inject, OnInit, ViewChild} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material';
import {Coordinates} from '../model';
import {FormControl} from '@angular/forms';

@Component({
selector: 'app-work-dialog',
templateUrl: './work-dialog.component.html',
styleUrls: ['./work-dialog.component.css']
})
export class WorkDialogComponent implements OnInit {
@ViewChild('search') public searchElementRef: ElementRef;
public searchControl: FormControl;
private coordinates: Coordinates;
constructor(
public dialogRef: MatDialogRef<WorkDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: Coordinates
) {}

ngOnInit() {}

onNoClick() {
this.dialogRef.close();
}
}

触发对话框打开的 TypeScript...

captureWorkLocation() {
this.ngZone.run(() =>
this.dialog.open(WorkDialogComponent, {
width: '90vh', height: '90vh',
data: this.user.work
}).afterClosed().subscribe(result => {
this.user.work = result;
})
);
}

最佳答案

如果未定义纬度/经度,则不会加载 map 。这些值最初是未设置的,因此我硬编码了一个初始值并正确显示了 map 。

关于javascript - Angular Material 对话框 - AGM 贴图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54753904/

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