0

使用 OpenLayers 2.12,我正在检索 KML 地图数据,其中包含来自远程服务器的地图点位置。我的 Javascript 成功接收了数据,创建了功能,我可以在地图上看到位置标记。

然后我尝试做的是在单击每个位置时创建一个弹出窗口。这是我的“功能选择”事件处理程序:

function site_selected(event) {

    var feature = event.feature;
    feature.closeBox = true;
    feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
        'autoSize': true
    });
    feature.data.popupContentHTML = '<div>hello</div>';
    feature.data.overflow = "auto";
    feature.lonlat = new OpenLayers.LonLat(feature.geometry.x, feature.geometry.y);
    var popup = feature.createPopup(true);
    popup.show();
}

但是,调用feature.createPopup(true)返回 null。

我查看了弹出示例,但这不涉及加载 KML 数据。我设置了 lonlat 属性,但是仍然返回 null。问题是,为什么?

4

2 回答 2

0

请看“弹出”示例https://github.com/ccnmtl/openlayers/tree/master/openlayers/examples

线 createPopup 功能: https ://github.com/ccnmtl/openlayers/blob/master/openlayers/examples/popupMatrix.html#L857

于 2012-09-25T10:47:31.877 回答
0

我发现使用以下代码会创建一个弹出窗口并将其显示在地图上:

popup = new OpenLayers.Popup("popup",
        new OpenLayers.LonLat(feature.geometry.x,feature.geometry.y),
        new OpenLayers.Size(200,200),
        "example popup",
        true);

map.addPopup(popup);
popup.show();
于 2012-09-25T19:57:22.117 回答