我试着复制粘贴错误,并找到了一个资源,但实际上我无法理解它是什么。我被弹出的问题困住了,帮我解决吧。我正在附加代码片段以及控制台日志中弹出的错误。
片段:
for (var i=0; i<quakePoints.length; i++) {
var lon = quakePoints[i][1];
var lat = quakePoints[i][0];
var popupText = quakePoints[i][2];
var markerLocation = new L.LatLng(lat, lon);
var marker = new L.marker(markerLocation);
marker.bindPopup(popupText).addTo(map);
}错误:
leaflet.js:7 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
at e._updateContent (leaflet.js:7)
at e.update (leaflet.js:7)
at e.onAdd (leaflet.js:7)
at e._layerAdd (leaflet.js:6)
at e.addLayer (leaflet.js:6)
at e.openPopup (leaflet.js:7)
at e.openPopup (leaflet.js:7)
at e.togglePopup (leaflet.js:7)
at e.fireEvent (leaflet.js:6)
at e._onMouseClick (leaflet.js:7)错误-使用传单-src.js后
leaflet-src.js:4046 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
at NewClass._updateContent (leaflet-src.js:4046)
at NewClass.update (leaflet-src.js:3974)
at NewClass.onAdd (leaflet-src.js:3899)
at NewClass._layerAdd (leaflet-src.js:2265)
at NewClass.addLayer (leaflet-src.js:1723)
at NewClass.openPopup (leaflet-src.js:4172)
at NewClass.openPopup (leaflet-src.js:4197)
at NewClass.togglePopup (leaflet-src.js:4215)
at NewClass.fireEvent (leaflet-src.js:466)
at NewClass._onMouseClick (leaflet-src.js:3738)编辑,附加示例数据
var quakePoints = [
[17.123184,79.208824,1.7345],
[19.123184,76.208824,2.7345],
[18.123184,69.208824,2.7345],
[21.123184,70.208824,3.7345],
[23.123184,72.208824,2.6645],
[22.123184,77.208824,1.2245],
[24.123184,85.208824,2.7345],
[18.123184,78.208824,1.7345],
[11.123184,89.208824,1.7345]];发布于 2018-08-06 12:52:59
根据您的另一个问题,quakePoints数组看起来如下:
var quakePoints = [
[17.123184,79.208824,1.7345],
...
];也就是说这里的popupText ..。
var popupText = quakePoints[i][2];...gets值1.7345,但作为数字,而不是字符串。
稍后,传单运行这段代码,将内部参数content设置为Number 1.7345。
if (typeof content === 'string') {
node.innerHTML = content;
} else {
// snip
node.appendChild(content);
}该参数不是字符串,因此它试图将其处理为一个HTMLElement。
请仔细阅读方法来自传单API引用。
bindPopup(<String|HTMLElement|Function|Popup> content, <Popup options> options?)使用传递的内容将弹出绑定到该层,并设置必要的事件侦听器。如果传递了一个Function,它将接收该层作为第一个参数,并且应该返回一个String或HTMLElement。
请注意,bindPopup的第一个参数必须是String、HTMLElement、返回String或HTMLElement或Popup实例的Function。您正在传递一个Number,这不是这些,所以您的问题实际上是一个GIGO的例子。
这里的方法是确保您正在传递一个String
例如用String()
var popupText = String(quakePoints[i][2]);或者例如使用Number.toString()
var popupText = quakePoints[i][2].toString();https://stackoverflow.com/questions/51707472
复制相似问题