我想做一个方法,当我用鼠标悬停在标记上时,会在div的右下角显示有关标记的信息
所有打字稿。
检测到鼠标移动到标记上(控制台正确打印了消息),但信息项未创建。
错误:
core.js:1440 ERROR TypeError: Cannot read property '_controlCorners' of undefined
at NewClass.addTo (leaflet-src.js:4620)
at NewClass.eval (osm-generator.component.ts:73)
at NewClass.fire (leaflet-src.js:588)
at NewClass._fireDOMEvent (leaflet-src.js:4272)
at NewClass._handleDOMEvent (leaflet-src.js:4229)
at HTMLDivElement.handler (leaflet-src.js:2231)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4724)
at ZoneDelegate.invokeTask (zone.js:420)
at Zone.runTask (zone.js:188)
代码:
let info = L.control.attribution({position: "bottomright"});
info.onAdd = function () {
let div = L.DomUtil.create('div', 'info'),
labels = [];
labels.push('<div class="information-section">Informations</div>');
div.innerHTML = labels.join('<br>');
return div;
};
marker.on('mouseover', function (e) {
marker.openPopup();
info.addTo(this.map);
});
marker.on('mouseout', function () {
marker.closePopup();
});
答案 0 :(得分:0)
在Leaflet的源代码中快速搜索将显示访问_controlCorners
的唯一位置是this line of code:
// @method addTo(map: Map): this
// Adds the control to the given map.
addTo: function (map) {
// [stuff]
var corner = map._controlCorners[pos];
// [stuff]
},
您似乎正在向非初始化地图添加控件,否则addTo()
调用的参数不是地图。我建议您在console.log()
的来电中以map
addTo(map)
的价值开始。
答案 1 :(得分:0)
工作版本,('this')函数解析后。
let info = L.control.attribution({position: "bottomright"});
info.onAdd = function () {
let div = L.DomUtil.create('div', 'info'),
labels = [];
labels.push('<div class="information-section">Informations</div>');
div.innerHTML = labels.join('<br>');
return div;
};
marker.on('mouseover', function (e) {
marker.openPopup();
info.addTo(this.map);
});
marker.on('mouseout', function () {
marker.closePopup();
}, this );