如何在 AGM Angular 7 中设置标记标签的背景颜色?
How to set background color of marker label in AGM Angular 7?
<agm-map style="text-shadow: 0px 0px 8.2px yellow; color: red;" [latitude]='latitude'
[longitude]='longitude' (mapClick)="onChoseLocation($event)" [zoom]=15 [usePanning]="true">
<agm-marker *ngFor="let vehicle of data1;" [agmFitBounds]="true"
[latitude]='vehicle.lat' [longitude]='vehicle.lng'
[iconUrl]="{ url: './assets/images/cars.png', scaledSize: { width: 45, height: 45, rotation: vehicle.angle, anchor : {x:19, y:19} }}"
[label]="{color: 'blue', fontWeight: 'bold', fontSize: '12px', backgroundColor:'red', text: vehicle.name}">
<agm-polyline *ngFor="let initialdata of vehicleDetail">
<agm-polyline-point [latitude]="initialdata.lat" [longitude]="initialdata.lng">
</agm-polyline-point>
<agm-polyline-point *ngIf="(vehicle.id == id)" [latitude]="vehicle.lat" [longitude]="vehicle.lng">
</agm-polyline-point>
</agm-polyline>
<agm-info-window [disableAutoPan]="true" #infoWindow [isOpen]="true">
<small>
Name: <small>{{vehicle.name}}</small> <br>
Speed: <small>{{vehicle.speed}} km/h </small><br>
<!-- Lng: <small>{{vehicle.lng}}</small> <br> -->
Status: <small>{{vehicle.status}}</small>
</small>
<div>
<a (click)="onClickInfoView({id:m.id})" class="btn btn-attention pull-right"></a>
</div>
</agm-info-window>
</agm-marker>
</agm-map>
我使用背景颜色 属性 那样,但它不起作用....
[label]="{color: 'blue', fontWeight: 'bold', fontSize: '12px', backgroundColor:'red', text: vehicle.name}"
我也想设置 marginttop 但它不起作用。
名称显示在图片上方....但我想要名称将图片和背景颜色设为红色。
您可以使用 labelOrigin:{x:12,y:27} 属性 for [iconUrl] 来更改标签位置。
像这样:
[iconUrl]="{ url: './assets/images/cars.png', scaledSize: { width: 45, height: 45, rotation: vehicle.angle, anchor : {x:19, y:19} }, 标签原点:{x:12,y:27}}
在您的 styles.css
中添加以下样式以更改背景颜色。
.gm-style div[aria-hidden="true"]{
background-color: white !important;
padding: 5px;
border-radius: 5px;
}
<agm-map style="text-shadow: 0px 0px 8.2px yellow; color: red;" [latitude]='latitude'
[longitude]='longitude' (mapClick)="onChoseLocation($event)" [zoom]=15 [usePanning]="true">
<agm-marker *ngFor="let vehicle of data1;" [agmFitBounds]="true"
[latitude]='vehicle.lat' [longitude]='vehicle.lng'
[iconUrl]="{ url: './assets/images/cars.png', scaledSize: { width: 45, height: 45, rotation: vehicle.angle, anchor : {x:19, y:19} }}"
[label]="{color: 'blue', fontWeight: 'bold', fontSize: '12px', backgroundColor:'red', text: vehicle.name}">
<agm-polyline *ngFor="let initialdata of vehicleDetail">
<agm-polyline-point [latitude]="initialdata.lat" [longitude]="initialdata.lng">
</agm-polyline-point>
<agm-polyline-point *ngIf="(vehicle.id == id)" [latitude]="vehicle.lat" [longitude]="vehicle.lng">
</agm-polyline-point>
</agm-polyline>
<agm-info-window [disableAutoPan]="true" #infoWindow [isOpen]="true">
<small>
Name: <small>{{vehicle.name}}</small> <br>
Speed: <small>{{vehicle.speed}} km/h </small><br>
<!-- Lng: <small>{{vehicle.lng}}</small> <br> -->
Status: <small>{{vehicle.status}}</small>
</small>
<div>
<a (click)="onClickInfoView({id:m.id})" class="btn btn-attention pull-right"></a>
</div>
</agm-info-window>
</agm-marker>
</agm-map>
我使用背景颜色 属性 那样,但它不起作用....
[label]="{color: 'blue', fontWeight: 'bold', fontSize: '12px', backgroundColor:'red', text: vehicle.name}"
我也想设置 marginttop 但它不起作用。
名称显示在图片上方....但我想要名称将图片和背景颜色设为红色。
您可以使用 labelOrigin:{x:12,y:27} 属性 for [iconUrl] 来更改标签位置。 像这样: [iconUrl]="{ url: './assets/images/cars.png', scaledSize: { width: 45, height: 45, rotation: vehicle.angle, anchor : {x:19, y:19} }, 标签原点:{x:12,y:27}}
在您的 styles.css
中添加以下样式以更改背景颜色。
.gm-style div[aria-hidden="true"]{
background-color: white !important;
padding: 5px;
border-radius: 5px;
}