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

Open info window doesn't work with <custom-marker> #276

Open
fatemamandsourwala opened this issue Jul 5, 2018 · 1 comment
Open

Open info window doesn't work with <custom-marker> #276

fatemamandsourwala opened this issue Jul 5, 2018 · 1 comment

Comments

@fatemamandsourwala
Copy link

IMPORTANT
Please be specific with an example. An issue with no example or unclear requirements may be closed.

Steps to reproduce and a minimal demo

-html

<custom-marker *ngFor="let pos of positions" [position]="pos" (click)="showInfo($event)">



-ts
showInfo({target: marker}) {
this.marker.lat = marker.getPosition().lat();
this.marker.lng = marker.getPosition().lng();
marker.nguiMapComponent.openInfoWindow('iw', marker);
}

Current behavior
Giving this error
MapComponent.html:49 ERROR TypeError: marker.getPosition is not a function
at MapComponent.Array.concat.MapComponent.showInfo (map.ts:44)
at Object.eval [as handleEvent] (MapComponent.html:49)
at handleEvent (core.js:13589)
at callWithDebugContext (core.js:15098)
at Object.debugHandleEvent [as handleEvent] (core.js:14685)
at dispatchEvent (core.js:10004)
at core.js:10629
at HTMLElement. (platform-browser.js:2628)
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.js:4751)

Expected/desired behavior

Should show info window on click of custom-marker

@plamen-redzhov
Copy link

You're passing an event to showInfo function, which holds the actual DOM element as target. This element does not have a getPosition method, nor has a nguiMapComponent property.
Use the initialized$ event of the custom marker to create an array of markers, and then pass the corresponding custom marker to the openInfoWindow function. E.g.
HTML:
<custom-marker *ngFor="let pos of positions; let i = index" [position]="pos]" (initialized$)="onMarkersInit($event)" > <div (click)="showInfo(i)"></div> </custom-marker>

TS:
`
@ViewChild(NguiMapComponent) nguiMapComponent: NguiMapComponent;

onMarkersInit(marker) {
this.markers.push(marker);
}

showInfo(index) {
this.nguiMapComponent.openInfoWindow('iw', this.markers[index]);
}

`

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

2 participants