Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: MarkerManager.getNativeMarker() #685

Closed
ostapch opened this issue Sep 29, 2016 · 4 comments
Closed

Question: MarkerManager.getNativeMarker() #685

ostapch opened this issue Sep 29, 2016 · 4 comments

Comments

@ostapch
Copy link

ostapch commented Sep 29, 2016

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);
})
@ostapch ostapch closed this as completed Sep 29, 2016
@ostapch
Copy link
Author

ostapch commented Sep 29, 2016

I found solution

@maxmumford
Copy link

maxmumford commented Oct 29, 2016

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 directive would look something like this:

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);
      });
    }
  }

@RathodGirish
Copy link

Hi @maxmumford
That what exactly I want,
Thank you so much.

@RathodGirish
Copy link

@maxmumford
I have one more issue.
I want to add manually infowindow on hover of marker.
Will please send some example for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants