Closed leabdalla closed 4 years ago
Add a click handler to the frame. See this demo for an example:
Thanks for the answer. So, what if I have two different links inside the frame?
@leabdalla You should try by yourself before asking. @ndrake gives a hint at least.
I tried and it worked, so I'm talking about another issue..
multiple links solved by adding custom event listeners for each one.
mapClickCam(){
console.log('mapClickCam');
}
mapClickAttach(){
console.log('mapClickAttach');
}
let htmlInfoWindow = new HtmlInfoWindow();
let frame = document.createElement('div');
frame.innerHTML = `
<div>
<p align="center">
<font size="6">
<ion-icon class="link_videocam" name="videocam-outline"></ion-icon>
<ion-icon class="link_attach" name="attach"></ion-icon>
</font>
</p>
</div>
`;
htmlInfoWindow.setContent(frame, {width:"220px", height:"auto"});
frame.getElementsByClassName("link_videocam")[0].addEventListener("click", (evt) => {
console.log('link_videocam');
mapClickCam();
});
frame.getElementsByClassName("link_attach")[0].addEventListener("click", (evt) => {
console.log('link_attach');
mapClickAttach();
});
But the methods mapClickCam()
and mapClickAttach()
inside events are not being called.
error TS2304: Cannot find name 'mapClickCam'.
error TS2304: Cannot find name 'mapClickAttach'.
How can I access those methods? I'm trying something like evt.parentNode.parentNode...
but no success.
I'd appreciate if someone can help.
let self = this;
frame.getElementsByClassName("link_videocam")[0].addEventListener("click", (evt) => {
console.log('link_videocam');
self.mapClickCam.call(self);
});
frame.getElementsByClassName("link_attach")[0].addEventListener("click", (evt) => {
console.log('link_attach');
self.mapClickAttach.call(self);
});
Thanks it worked!
Congrats, but you should learn "why the code works". Search "function.bind()" on Google.
Yes I've made a search about javascript call() method
.
Sorry it's my first time with typescript and also my first time coding a mobile app. Thanks!
I'm calling the
addMarker()
function to add markers and their windows. This is working Fine.So now I need to call
mapClickCam()
method from the link inside each HtmlInfoWindow.How can I do that?
This way its displaying error "mapClickCam()" is not defined.