简体   繁体   English

如何在Angular2 Google地图中删除标记

[英]How to remove Markers in Angular2 google maps

Can any one help me how to remove markers in sebm google maps in angular2 google maps? 谁能帮我在angular2 Google地图中删除Sebm Google地图中的标记? It is working when I set the visibility of the marker to false. 当我将标记的可见性设置为false时,它正在工作。 It made the marker to hide. 它使标记隐藏。 But I need to remove the entire marker from the marker array. 但是我需要从标记数组中删除整个标记。

app.component.html app.component.html

<sebm-google-map  [latitude]="lat" [longitude]="lng" [zoom]="zoom" (mapClick)="mapClicked($event)">
 <sebm-google-map-marker *ngFor="let m of markers" [latitude]= 'm.lat' [longitude]='m.lng'  [visible]='m.visible' (markerClick)="clickedMarker(m)" [iconUrl]='m.iconUrl' [label]="">
  <sebm-google-map-info-window>
   <p>info window</p>
  </sebm-google-map-info-window>
 </sebm-google-map-marker>
</sebm-google-map>

app.component.ts app.component.ts

this.markers.push(
{
 id: m.perma_link,
 title: null,
 isOpen: false,
 lat: parseFloat(m.latitude),
 lng: parseFloat(m.longitude),
 label: m.event_name,
 address: m.address,
 mobile: parseFloat(m.mobile),
 phone: m.phone,
 visible: true,
 image: img_result,
 iconUrl: 'events.png'
})

Empty Array 空数组

this.markers = [];

sort array via filter 通过过滤器排序数组

  this.markers.filter( (markers) => {
    return markers.id !== 2;
    }
)

Return a new array without a marker with id of 2. 返回一个不带标识为2的标记的新数组。

I usually just set visibility to either true or false to hide markers instead of remove them from array. 我通常只将可见性设置为true或false即可隐藏标记,而不是将其从数组中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM