使用JSON作为文本的小册子弹出窗口

时间:2015-11-17 23:48:52

标签: leaflet

出于调试目的,我希望我的标记有一个包含json的弹出窗口。

值类似于:

var CarState= {
    "height" : 6.2,
    "width" : 7.3,
    "length" : 9.1,
    "color" : {
        "r" : 255,
        "g" : 200,
        "b" : 10
    }
}

但这不起作用,我得到的只是一个截断的弹出窗口。 CarState的内容不断变化,但同样的属性包就在那里。

注意: self 是指此代码所在的AMD模块。我不会使用此模块,因为您可能遇到麻烦。 self.pop是一个包含L.PopUp

的变量
this.update = function () {
    var text = "<p>" + JSON.stringify(CarState) + "</p>";
    self.pop.setContent(text);
    self.pop.update();
}

这就是它的样子:

enter image description here

这就是Chrome所说的弹出式div大小:

enter image description here

1 个答案:

答案 0 :(得分:0)

好的,现在这对我有用。不完全确定问题是什么。

    this.update = function () {
        var text = "<pre><code>" + JSON.stringify(CarState, null, '\t') + "</code></pre>";
        theCar.setPopupContent(text);
        theCar.update();
        theCar.setLatLng(L.latLng(CarState.lat, CarState.lon));
        theMap.panTo(L.latLng(CarState.lat, CarState.lon));
    }
相关问题