0

I'm trying to allow user to click on the marker pin to show the red circle for the specific pin.

Below is my map code:

<agm-map
  [latitude]="centerLatitude"
  [longitude]="centerLongitude"
  (mapClick)="mapClicked($event)"
  [usePanning]="true"
  [zoom]="6">

  <ng-container *ngIf="source != null">
    <agm-marker *ngFor="let marker of [].concat(source); let i = index"
      [latitude]="marker.geoLatitude"
      [longitude]="marker.geoLongitude"
      [label]="marker.label"
      [openInfoWindow]="showInfoWindow">  

      <ng-container *ngIf="marker.geoLatitude && marker.geoLongitude">
          <agm-info-window [disableAutoPan]="false" [isOpen]="showInfoWindow">
                  <label class="sr-bold">{{ marker?.name }}</label>
            </agm-info-window>    
      </ng-container>
      <agm-circle *ngIf="marker.geoLatitude && marker.geoLongitude" 
        [latitude]="marker.geoLatitude"
        [longitude]="marker.geoLongitude"
        [radius]="marker.radius ? marker.radius * 1000 : null"
        fillColor="red">
      </agm-circle>
    </agm-marker>
  </ng-container>
</agm-map>
4

1 回答 1

0

agm-circle并且agm-info-window是独立的指令,而不是 agm-marker 的子级。

<agm-map
  [latitude]="centerLatitude"
  [longitude]="centerLongitude"
  (mapClick)="mapClicked($event)"
  [usePanning]="true"
  [zoom]="6">

  <ng-container *ngIf="source != null">
    <ng-container *ngFor="let marker of [].concat(source)">
      <ng-container *ngIf="marker.geoLatitude && marker.geoLongitude">
        <agm-marker
          [latitude]="marker.geoLatitude"
          [longitude]="marker.geoLongitude"
          [label]="marker.label"
          [openInfoWindow]="showInfoWindow"> 
        </agm-marker>

        <agm-info-window [disableAutoPan]="false"
          [latitude]="marker.geoLatitude"
          [longitude]="marker.geoLongitude"
          [isOpen]="showInfoWindow">
                  <label class="sr-bold">{{ marker?.name }}</label>
        </agm-info-window>
        <agm-circle 
          [latitude]="marker.geoLatitude"
          [longitude]="marker.geoLongitude"
          [radius]="marker.radius ? marker.radius * 1000 : null"
          fillColor="red">
        </agm-circle>
      </ng-container>
    </ng-container>
  </ng-container>
</agm-map>

现在,至于您的要求,您希望圆圈仅在单击 agm 标记时显示。为此,我们向数据标记对象添加一个布尔值

<agm-marker
  [latitude]="marker.geoLatitude"
  [longitude]="marker.geoLongitude"
  [label]="marker.label"
  [openInfoWindow]="showInfoWindow"
  (click)="marker.markerClicked"
>
</agm-marker>
<agm-circle *ngIf="marker.markerClicked" 
...>
于 2019-11-06T10:15:41.297 回答