jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 自动平移映射以在加载来自ajax的内容后适合infoWindow大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用谷歌地图的实现,在地图上加载由 PHP脚本确定的位置的标记,允许用户根据搜索条件动态过滤兴趣点.这是通过对PHP搜索脚本的ajax调用完成的.这些标记还有一个附加的infoWindow,通过访问不同的PHP脚本动态加载有关该站点的详细信息.在标记创建过程中,我使用以下代码

// Initialize the info window
var InfoWindow = new google.maps.InfoWindow({ content: 'Display Error: Please Try Again',maxWidth: 400 });

// Lots of code to prep the search filters and Now inside an $.ajax().done(function(html) { $('#ajaxstub div.stubCalc').each(function() {  } }) method

var newMarker = new google.maps.Marker({
    position: latlon,icon: $(this).find('.iconstub').text(),title: $(this).find('.namestub').text(),map: gmap
});
// onClick show the InfoWindow
google.maps.event.addListener(newMarker,'click',function(E) {
    InfoWindow.content = $('<div class="projectstub" guid=""></div>').attr('guid',guid).get(0);
    InfoWindow.open(gmap,newMarker);
    // loadstub(div,guid,[isToolBox],[callBACk()]) is defined in CalcInfo.js so that it can also be used by the Calculator ToolBox Page
    loadstub($('div.projectstub[guid="' + guid + '"]').get(),false,function() {
        InfoWindow.setContent(InfoWindow.content);
    });
});

并且你可以看到loadstub方法进行初始的ajax调用并为文件上传的ajax调用做准备(因此这个infowindow的内容非常动态)

function loadstub(project,isToolBox,callBACk) {
    if (typeof(isToolBox) === 'undefined') isToolBox = false;
    $(project).html('<img src="/Styles/images/ajax-loader.gif"/>');
    $.ajax({
        url: "/ajax.PHP?ajax=CalcInfo",type: "POST",data: { guid: guid,isToolBox: isToolBox.toString() },cache: false
    }).done(function(html) {
        $(project).html($(html).html());
        $(project).find('#fileInput').change(function() {
            // More code here to prepare for ajax upload
            $.ajax({
                url: "/ajax.PHP&ajax=Thumbnail&guid=" + guid,data: formdata
            }).done(function(html) {
                if ($(html).find('#ajaxContent .error').length > 0) {
                    var errormessage = 'The Server Returned the Following Error(s):\n';
                    $(html).find('#ajaxContent .error').each(function() {
                        errormessage += $(this).text() + '\n';
                    });
                    errormessage += 'Please Try Again';
                    alert(errormessagE);
                }
            }).fail(function() {
                alert('There Was an Error ConnecTing to the Server. Please Try Again.');
            }).always(function() {
                loadstub();
            });
        });
        if (typeof callBACk == 'function') {
            callBACk();
        }
    }).fail(function() {
        $(project).html('<div style="margin: 75px 0; text-align: center;">There Was an Error ConnecTing to the Server<br/>Please Try Again</div>');
    });
}

我能够确定通过使用setContent方法而不是分配InfoWindow.content谷歌地图将适当地调整InfoWindow大小,但它不会平移地图以适应InfoWindow的内容,因为它在使用InfoWindow.open时认().有谁知道一个体面的解决方案?

如果我需要澄清任何事情,请告诉我.

提前致谢.

解决方法

尝试调用InfoWindow.open(gmap,newMarker);再次将内容设置为ajax结果之后. 根据内容大小调用open方法时,地图将自动平移,这似乎是一个可用的解决方法.

大佬总结

以上是大佬教程为你收集整理的jquery – 自动平移映射以在加载来自ajax的内容后适合infoWindow全部内容,希望文章能够帮你解决jquery – 自动平移映射以在加载来自ajax的内容后适合infoWindow所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。