Hi, @SebastianM. Can you please tell me how can I get instance of SebmGoogleMapMarker to get native marker?
for example:
this.markerManager.getNativeMarker(INSTANCE_OF_SebmGoogleMapMarker).then((nativeMarker) => {
console.log('YEAH marker is here: ' + nativeMarker);
})
I found solution
For others interested in the solution, you have to create a new directive, and nest it inside the sebm-google-map component. Have the MarkerManager object injected into this component, then emit it with an Output property to pass it to the parent component. For example:
<my-parent-component>
<sebm-google-map>
<get-map-objects (markerManager)="setMarkerManager($event)">
<sebm-google-map-marker ... ></sebm-google-map-marker>
</get-map-objects>
</sebm-google-map>
</my-parent-component>
Then the
import { Directive, Output, EventEmitter, AfterViewInit, ContentChildren, QueryList } from '@angular/core';
import { GoogleMapsAPIWrapper, MarkerManager, SebmGoogleMapMarker } from 'angular2-google-maps/core';
@Directive({
selector: 'get-map-objects',
})
export class GetMapObjectsDirective implements AfterViewInit {
/**
* Get native map object
*/
private _map: any = null;
@Output('map') mapChanged: EventEmitter<any> = new EventEmitter<any>();
set map(val){
this._map = val;
this.mapChanged.emit(val);
}
get map(){
return this._map;
}
/**
* Get marker manager
*/
private _markerManager: any = null;
@Output('markerManager') markerManagerChanged: EventEmitter<MarkerManager> = new EventEmitter<MarkerManager>();
set markerManager(val){
this._markerManager = val;
this.markerManagerChanged.emit(val);
}
get markerManager(){
return this._markerManager;
}
/**
* Get sebm markers
*/
private _markers: any = null;
@Output('markers') markersChanged: EventEmitter<SebmGoogleMapMarker[]> = new EventEmitter<SebmGoogleMapMarker[]>();
set markers(val){
this._markers = val;
this.markersChanged.emit(val);
}
get markers(){
return this._markers;
}
@ContentChildren(SebmGoogleMapMarker) markerChildren: QueryList<SebmGoogleMapMarker>;
constructor(
private googleMapsWrapper: GoogleMapsAPIWrapper,
private googleMarkerManager: MarkerManager
) { }
ngAfterViewInit() {
// get native map
this.googleMapsWrapper.getNativeMap().then(map => {
this.map = map;
}, error => {
throw error;
})
// get marker manager
this.markerManager = this.googleMarkerManager;
// get markers
this.markerChildren.changes.subscribe(markers => {
this.markers = markers._results;
})
}
}
Finally in your parent component, make use of the marker manager (and markers) like so:
setMarkerManager(markerManager: MarkerManager){
this.markerManager = markerManager;
}
/**
* Sets the markers, used by spidifier
*/
setMarkers(markers: SebmGoogleMapMarker[]){
this.markers = markers;
for(let marker of markers){
this.markerManager.getNativeMarker(marker).then(marker => {
this.overlappingMarkerSpidifier.addMarker(marker);
});
}
}
Hi @maxmumford
That what exactly I want,
Thank you so much.
@maxmumford
I have one more issue.
I want to add manually infowindow on hover of marker.
Will please send some example for that?
Most helpful comment
For others interested in the solution, you have to create a new directive, and nest it inside the sebm-google-map component. Have the MarkerManager object injected into this component, then emit it with an Output property to pass it to the parent component. For example:
Then the directive would look something like this:
Finally in your parent component, make use of the marker manager (and markers) like so: