1

我正在使用最新的 LeafletJS 库在地图上显示带有某些弹出选项的弹出窗口。

它在 Firefox 和 Chrome 中运行良好,但在 IE8 中失败并显示错误消息:

无效的论点。Leaflet.js,第 6 行,字符 14452

这是:

i=Math.min(i,this.options.maxWidth),i=Math.max(i,this.options.minWidth),e.width=i+1+"px",e.whiteSpace="",e.height=""

问题显然似乎与popupOptions 声明有关——取消注释它们时,IE8 中不会出现 js 错误,但当然也不会应用这些选项。

所以我想知道,语法有什么问题?

function onEachFeature(feature, layer) {

    var popupContent = '...';

    if (feature.properties && feature.properties.popupContent) {
        popupContent += feature.properties.popupContent;
    }

    var popupOptions =
    {
        'minWidth': '491px',
        'maxWidth': '491px',
        'closeButton': false
    }

    layer.bindPopup(popupContent, popupOptions);
}
4

1 回答 1

2

在该行中,minWidth 和 maxWidth 选项被馈送到 Math.max。但是你的不是数字,因为它们已经px添加到它们中。

所以应该是

var popupOptions =
{
    'minWidth': '491',
    'maxWidth': '491',
    'closeButton': false
}

http://leafletjs.com/reference.html#popup-options

于 2013-05-08T08:49:05.593 回答