javascript - 在 openlayers 中更新/调整弹出框云的大小

标签 javascript dictionary openlayers

我已经处理这个问题近三天了,所以我想我失败的研究和我制定的概念的反复试验已经足够了。场景如下:

我使用开放图层 map 。我生成标记。将鼠标悬停在这些标记上时,我需要使用弹出框对话框显示标签“查看详细信息”。单击“查看详细信息”后,我需要加载 jpg 文件,该文件是与 map 中的标记相对应的特定位置的俯 View 屏幕截图。我可以成功完成,我单击“查看详细信息”,我可以显示图像。但最大的问题是,我的弹出框云的四个边缘分散,其内容是透明的,图像漂浮在中间。

我为 View 详细信息标签附加了一个内联“onclick 属性”:

fromImage = '<img src="'+data['map_locations'][key]['image_url']+'" class="ImageFrom"></img><label type="button" class="location_image_container" onclick="show_location_details()">VIEW DETAILS</label>';

这是每次单击查看详细信息时调用的函数

function show_location_details(){
    jQuery('#cloud_dialog_details_link').hide();
    jQuery('.olFramedCloudPopupContent').width(500);
    jQuery('.olFramedCloudPopupContent').height(400);
    jQuery('.olPopup').height(400);
    jQuery('.olPopup').width(500);
    jQuery(".ImageFrom").show();
}

知道如何让我的弹出框云按照我想要的方式运行吗?

谢谢大家的意见。

[编辑] 你好。为了清楚起见,我在脚本中声明了一个全局“AutoSizeFramedCloud”

AutoSizeFramedCloud = OpenLayers.Class(OpenLayers.Popup.FramedCloud,{'autosize':true});

在函数内部,我设置了它的初始构造函数:

function addMarkers(lonlat, marker_name, description, id, label, subgroup, category){
        var ll,popupClass,popupContentHTML,marker,popupContentDiv;
        ll = lonlat;
        popupClass = AutoSizeFramedCloud;
        popupContentHTML = description+label;
        marker = marker_name;
        popupContentDiv = id;
        popupGroupDiv = subgroup;
}

当我点击弹出窗口中的“查看详细信息”标签时:

<label type="button" class="location_image_container" onclick="show_location_details()">VIEW DETAILS</label>

我正在调用函数 show_location_details()

function show_location_details(){
        this.popup.setSize(new OpenLayers.Size(500, 400));
        //alert(jQuery('popup.contentDiv').val());
        jQuery('#cloud_dialog_details_link').hide();
        jQuery('.olPopup').width(600);
        jQuery('.olFramedCloudPopupContent').width(480);
        jQuery('.olPopup').height(500);
        jQuery('.olFramedCloudPopupContent').height(380);
        jQuery(".ImageFrom").show();
    }

但是,它给了我错误:

Uncaught TypeError: Cannot call method 'setSize' of undefined 

[编辑]

这是我创建弹出窗口功能的方法

function addMarker(ll, popupClass, popupContentHTML, closeBox, overflow, marker_name, popupContentDiv, popupGroupDiv, category){
        var feature = new OpenLayers.Feature(marker_name, ll);
        feature.closeBox = closeBox;
        feature.popupClass = popupClass;
        feature.data.popupContentHTML = popupContentHTML;
        //feature.data.overflow = (overflow) ? "auto":"hidden";
        feature.data.icon = new OpenLayers.Icon("./img/icon/blank.png", size);
        feature.data.contentDiv = popupContentDiv;
        feature.data.groupDiv = popupGroupDiv;

...
}

最佳答案

Popup是由很多不同的DIV组成的,不要尝试直接改变它们的大小,而是使用适当的popup方法:setSize(contentSize),它以大小为参数;或 updateSize(),它自动调整弹出窗口的大小以适应其内容:http://dev.openlayers.org/docs/files/OpenLayers/Popup-js.html#OpenLayers.Popup.setSize

var myPopup = new OpenLayers.Popup.FramedCloud({
...    


myPopup.setSize(new OpenLayers.Size(500, 400));
// Or...
// myPopup.updateSize();

关于javascript - 在 openlayers 中更新/调整弹出框云的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13522328/

相关文章:

c++ - Boost ICL 未按预期工作,std::set operator+= expected

python - 从字典中分配和调用内置函数 (Python)

javascript - 将绝对定位的 DIV 添加到 OpenLayers map 的底部?

html - 带有工具栏的 OpenLayers Map 显示不正确

javascript - 如何使用序列化(jQuery/Ajax)循环表单数据

javascript - 将数组转换为具有默认值的对象的更简洁的方法? (Lodash 可用)

swift - 如何按值的升序对字典进行排序?

javascript - OpenLayers 中的 Flash 动画不是连续渲染的

javascript - SyntaxError - node_modules/react-native/Libraries/polyfills/error-guard.js : Missing semicolon. (14:4) 在 react 原生库中运行 jest

javascript - 确定放置在 div 中的文本量以最大化最后一行的宽度