簡體   English   中英

如何在 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} 屬性為 [iconUrl] 更改標簽位置。 像這樣:[iconUrl]="{ url: './assets/images/cars.png', scaledSize: { width: 45, height: 45, rotation: vehicle.angle, anchor : {x:19, y:19 } }, labelOrigin:{x:12,y:27}}

styles.css添加以下樣式以更改背景顏色。

.gm-style div[aria-hidden="true"]{
    background-color: white !important;
    padding: 5px;
    border-radius: 5px;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM