我有問題來適合我的圖釘自定義模板到角度組件。Angular 2/4 Bing Map圖釘自定義模板函數調用
我的組分:
import { Component, AfterViewInit } from '@angular/core';
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss']
})
export class MapComponent implements, AfterViewInit {
@ViewChild('myMap') myMap;
map: any;
infoboxClick;
infoboxTemplate = `<div id="infoboxText" class="custom-infobox">
<span class ="close-sighn" onclick="closeCustomInfoBox()">x</span>
{description}
</div>`;
constructor(private dataService: MapService) {
}
ngAfterViewInit() {
this.getMap();
}
getMap() {
if ((window as any).Microsoft && (window as any).Microsoft.Maps) {
this.map = new (window as any).Microsoft.Maps.Map(document.getElementById('mapId'), {
credentials: ''
});
var pushpin = new (window as any).Microsoft.Maps.Pushpin(map.getCenter(), null);
(window as any).Microsoft.Maps.Events.addHandler(pushpin, 'click', (args) => {
this.infoboxClick.setOptions({
location: args.target.getLocation(),
htmlContent: this.infoboxTemplate.replace('{description}', 'Some test description'),
visible: true
});
});
map.entities.push(pushpin);
} else {
setTimeout(() => { this.getMap() }, 1000);
}
}
closeCustomInfoBox() {
this.infoboxClick.setOptions({
visible: false
});
}
}
我的觀點:
<div #myMap id="mapId" class="map-container"></div>
在infoboxTemplate我有功能 'closeCustomInfoBox()',這應關閉信息框。
1)我如何從我的角度組件調用該函數?
2)我需要得到適當的角度範圍,如果我稱之爲如何可以接近我的'infoboxClick'變量?
你需要一個定製的信息框?您可以簡單地將HTML添加到信息框的描述中,然後渲染。 – rbrundritt