【发布时间】:2017-08-28 09:55:35
【问题描述】:
我无法将我的图钉自定义模板放入角度组件中。
我的组件:
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 添加到信息框的描述中,它就会呈现。
标签: javascript angular bing-maps