Can any one help me how to remove markers in sebm google maps in angular2 google maps? It is working when I set the visibility of the marker to false. It made the marker to hide. But I need to remove the entire marker from the marker array.
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
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.
I usually just set visibility to either true or false to hide markers instead of remove them from array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.