视图渲染后,我收到此错误并且未添加弹出窗口-
mapbox-gl.js:176 TypeError: (intermediate value).setLngLat(...).setPopup 不是函数(...)
有没有人面对这个或知道解决这个问题的方法?
代码是在标记上设置弹出窗口,我按照这个链接https://www.mapbox.com/mapbox-gl-js/example/set-popup/
let tpl;
if (vendor.get('cachedAverageRating')) {
tpl = `
<div class='ui map-marker'>
<div class="photo">
<img src="${vendor.getAvatar() || FIXTURE_IMAGE}"></div>
<div class="ui violet counter">${vendor.get('cachedAverageRating')}</div>
</div>
`;
} else {
tpl = `
<div class='ui map-marker'>
<div class="photo">
<img src="${vendor.getAvatar() || FIXTURE_IMAGE}">
</div>
</div>
`;
}
let markerContainer = document.createElement('div');
markerContainer.innerHTML = tpl;
// create the popup
let markerPopup = new MapboxGL.Popup({offset: 25})
.setHTML(`<div>Name : ${vendor.get('name')}, Address : ${vendor.get('address')}, Rating : ${vendor.get('cachedAverageRating')}</div>`);
// create the marker
new MapboxGL.Marker(markerContainer, {offset:[-25, -25]})
.setLngLat([get(vendor, 'lon'), get(vendor, 'lat')])
.setPopup(markerPopup) // sets a popup on this marker
.addTo(map);