我的 Visual Force 页面上的 Google 地图未将所有标记显示为获取的结果数

2024-03-05

我正在尝试开发一个显示“程序位置”的视觉力页面。在页面加载时,它会获取所有程序并使用标记显示在地图上。有一些过滤器可用于减少结果集并查看特定程序。一切正常,除了页面加载时,我的结果表位于 Google 地图 div 下方,显示 16 条记录,这是正确的,但我的地图仅显示 11 条标记,绝对不正确。在创建地理编码器变量后,我确实在线上放置了一个警报,如果我慢慢地浏览所有警报,同一页面会显示 16 个标记。我认为它之间需要一些延迟功能,但即使这样也没有帮助。有人评论我哪里错了吗?

<apex:page sidebar="false" controller="Creative_ProgramsMap" tabStyle="Program__c" id="page" action="{!find}">
<head>
<style>
    div #map_canvas { height: 450px; }
    div #pageLoadMap { height: 650px;}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
<style>
.message {
background-color: #ffc;
border-style: solid;
border-width: 1px;
color: #000;
padding: 6px 8px 6px 6px;
margin: 4px 20px;
background-image: url(/img/msg_icons/error32.png);
background-position: 10px center;
background-repeat: no-repeat;
width: 520px;
color: red;
font-weight: strong;
min-height: 30px;
margin-bottom: 20px;
padding-left: 60px;
}
</style>
<table id="contents" border="0" width="100%">
<td style= "border-style:solid; border-color:black;" width="18%">
    <div align="center">
         <br/>
         <font style="text-align:center; font-weight:bold; font-style:italic; color:green; font-size:18px">Filters</font>
    </div>
    <apex:form id="form">
    <br/>
    <font style="font-weight:bold; font-style:italic;">Service</font>
    <br/>
    <apex:selectCheckboxes layout="pageDirection" title="Service" value="{!services}">
        <apex:selectOptions value="{!service}"/>
    </apex:selectCheckboxes>
    <br/>
    <font style="font-weight:bold; font-style:italic;">Category</font>
    <br/>
    <apex:selectCheckboxes layout="pageDirection" title="Category" value="{!categories}">
        <apex:selectOptions value="{!category}"/>
    </apex:selectCheckboxes>
    <br/>
    <font style="font-weight:bold; font-style:italic;">Status</font>
    <br/>
    <apex:selectCheckboxes layout="pageDirection" title="Status" value="{!statuses}">
        <apex:selectOptions value="{!status}"/>
    </apex:selectCheckboxes>
    <br/>
    <font style="font-weight:bold; font-style:italic;">Fiscal Year</font>
    <br/>
    <apex:selectCheckboxes layout="pageDirection" title="Fiscal Year" value="{!fiscalYears}">
        <apex:selectOptions value="{!fiscalYear}"/>
    </apex:selectCheckboxes>   
    <div align="center">
         <apex:commandButton id="btnShowPrograms" value="Show Programs" title="Populates the map based on the filteration criteria." action="{!find}" />
         <br/><br/>
    </div>
    </apex:form>
</td>
<td style= "border-style:solid; border-color:black;">   
  <div align="center"><apex:messages styleClass="message" /></div>
        <apex:sectionHeader title="Portfolio" subtitle="Defense Centers of Excellence" />
        <div align="center">
            <apex:outputLabel style="font-size:12px; color:orange; font-style:italic;">Only those programs with valid Location and address show up.</apex:outputLabel>
            <br />
            <apex:outputLabel style="font-size:12px; color:grey; font-style:italic;">1 pin per location.</apex:outputLabel>
            <br/><br/>
        </div>
        <apex:form id="frmResults">
            <div id="pageLoadMap" style="border:6px solid; border-color:#BDBDBD"></div>
            <!--  Display Results  --> 
            <apex:pageBlock title="Found {!programs.size} Program(s)..." rendered="{!NOT(ISNULL(programs)) && programs.size > 0}" id="resultsBlock">
            <apex:outputPanel id="mapResults">
                <apex:pageBlockSection title="Programs on Map" columns="1" id="mapSection">
                    <div id="map_canvas"></div>
                </apex:pageBlockSection>    
            </apex:outputPanel>  
            <apex:pageBlockSection columns="1" id="tableSection">
     <div align="center">
        <br/>
        <font style="text-align:center; font-weight:bold; font-style:italic; color:green; font-size:18px">List of Programs by Criteria</font>
         <br/><br/>
    </div>
    <apex:outputPanel id="tblResults">
    <div id="tableResults" style="overflow:auto; height:200px;">
           <apex:pageBlockTable style="border-style:solid; border-color:black;" value="{!programs}" var="program" id="programs">
                    <apex:column headerValue="{!$ObjectType.Program__c.fields.Name.label}">
                       {!program.Name}
                    </apex:column>
                    <apex:column headerValue="Program Name">
                        <apex:outputLink value="../{!program.Id}">{!program.Program_Name__c}</apex:outputLink>
                    </apex:column>                            
                    <apex:column headerValue="Workflow Status">
                        {!program.Workflow_Status__c} 
                    </apex:column>
                    <apex:column headerValue="Branch of Service">
                        {!program.Branch_of_Service__c}
                    </apex:column>
                        <apex:column headerValue="Primary Program Category">
                    {!program.Primary_Program_Category__c} 
                        </apex:column>
              </apex:pageBlockTable>     
 </div>
    </apex:outputPanel>           
     </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </td>
</table>
<script type="text/javascript">
window.onload = initialize();
var infos = [];
var map;

function initialize()
{
drawMapOnLoad();
//alert('Javascript Started');
var programs;                
var coords;            
var requestCounter;
var markers;       
var balloon;       
loadMap();
}

function drawMapOnLoad()
   {
       var mapOptions = {
              center: new google.maps.LatLng(39.810556, -98.556111),
              zoom: 4,
              mapTypeId: google.maps.MapTypeId.ROADMAP
       }
       map = new google.maps.Map(document.getElementById("pageLoadMap"), mapOptions);
   }

function loadMap()
{
programs = {!contactsJson};
coords = [];
requestCounter = 0;
markers = [];
geocodeClientSide();
}

function geocodeClientSide() 
{
//alert('Programs Length : ' + programs.length);
if(programs.length > 0)
{
    for(var i = 0; i < programs.length; i++) {
        ++requestCounter;
        var address = programs[i].Program_Location__r.BillingStreet + ' ' + programs[i].Program_Location__r.BillingCity + ' '
                        + programs[i].Program_Location__r.BillingState + ' ' + programs[i].Program_Location__r.BillingCountry + ' '
                        + programs[i].Program_Location__r.BillingPostalCode;
        var geocoder = new google.maps.Geocoder();
        alert('Program : ' + i);
            geocoder.geocode({'address':address}, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    coords.push(results[0].geometry.location);
                } 
                if(--requestCounter == 0) {
                    drawMap();
                }
            });
        }
}
}
}

function drawMap(){
//alert('Coords length is ' + coords.length);
var divPageLoadMap = document.getElementById("pageLoadMap");
divPageLoadMap.style.display = 'none';
var mapOptions = {
    //center: coords[0],
    center: new google.maps.LatLng(39.810556, -98.556111),
    zoom: 4,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),  mapOptions);
if(coords.length > 0)
     {
         drawMarker();
     }
}     

function drawMarker()
{
for(var i = 0; i < coords.length; i++){
     var mouseOverContentString = 'Program ID : ' + programs[i].Name + '\n' +
                               'Program Name : ' + programs[i].Program_Name__c + '\n' +
                               'Branch of Service : ' + programs[i].Branch_of_Service__c + '\n' +
                               'Location Name : ' + programs[i].Program_Location__r.Name;
  var marker = new google.maps.Marker({map: map, position: coords[i], title:mouseOverContentString , zIndex:i});
  markers.push(marker);

 var infoWindowContentString = '<div id="content" style="width:200px; height:150px">' +
                      '<h1 id="programName">' + programs[i].Name + '</h1>' +
                      '<p>Program Name : <i>' + programs[i].Program_Name__c + '</i></p>' +
                      '<p>Program Co-ordinator : <i>' + programs[i].ProgramCoordinator__c + '</i></p>' +
                      '<p>Program Location : <i>' + programs[i].Program_Location__r.Name + '</i></p>' + '</div>'; 
  var  infoWindow = new google.maps.InfoWindow();
  google.maps.event.addListener(marker,'click', (function(marker,infoWindowContentString,infoWindow){ 
    return function() {
        //map.setZoom(4);
    //map.setCenter(marker.getPosition());
       /* close the previous info-window */
       closeInfos();
   infoWindow.setContent(infoWindowContentString);
   infoWindow.open(map,marker);infos[0]=infoWindow;    
};
})(marker,infoWindowContentString,infoWindow)); 
}
}

function closeInfos(){
if(infos.length > 0){
/* detach the info-window from the marker ... undocumented in the API docs */
infos[0].set("marker", null);
/* and close it */
infos[0].close();
/* blank the array */
infos.length = 0;
}
}
</script>
</apex:page>

您遇到了地理编码器错误 OVER_QUERY_LIMIT(根据经验,您可以在遇到速率限制之前快速对大约 11 个地址进行地理编码)。要验证将 else 添加到状态检查中:

        geocoder.geocode({'address':address}, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                coords.push(results[0].geometry.location);
            } else alert("Geocode failed, status = "+status);

选项:

  • 离线对地址进行地理编码并使用坐标来显示标记而不是地址
  • 看到这个问题SO 一种限制地理编码请求的方法 https://stackoverflow.com/questions/11792916/over-query-limit-in-google-maps-api-v3-how-do-i-pause-delay-in-javascript-to-sl/11825245#11825245
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我的 Visual Force 页面上的 Google 地图未将所有标记显示为获取的结果数 的相关文章

  • 如何将udp发送到udp node.js服务器?

    我对此很陌生 所以我真的不知道我在做什么 但我已经设置了一个 node js udp 服务器 我想从客户端 来自网站 向它发送一个数据包 但我不知道如何在 javascript 中做到这一点 或者是否可能 我不是在研究如何从 Node js
  • Angular 2 链式 Promise 并传递拒绝

    应该是一个简单的问题 但是我找不到有关如何做到这一点的文档 像这样链接一个承诺 Making a promise no problem let promise new Promise resolve reject gt let data d
  • 访问sendBeacon发送的数据

    文档表明sendBeacon通过发送其数据HTTP POST request 但在 PHP 中 POST变量似乎是一个空数组 这是我的 JavaScript 代码 navigator sendBeacon beacon log php My
  • 用隐藏单元格补充 colspanned 表格有什么不好吗?

    我一直在表格上开发一些排序和选择功能 我发现在具有跨单元格的表格中定位非常困难 我只是添加了跨区单元格并将其隐藏 它看起来不错 它与我的 js 一起工作 非常适合索引 但我想知道这是否是合法的方法 stuffing display none
  • 使用 moment.js 检查输入日期是否为星期一

    好吧 我想检查日期是否是星期一 例如 var myDate new Date moment myDate DD MM YYYY dayIs monday 在我的国家 一周的第一天是星期一 所以 我真的想检查输入日期是否是一周的开始 我尝试使
  • jQuery 选择 # id 以单词为前缀,计数器为后缀

    有没有办法用 jQuery 选择所有带有前缀 my 和后缀 0 9 的 id 像这样的 my 1 4 还是可以用循环来实现 div div div div div div div div div div 第一个想法 似乎效果很好 div i
  • Ember.js 处理 View 事件后转换到路由

    Setup 我有一个 Ember 应用程序 支持使用 Imgur API 上传图像 我已经有一个工作路线和模板来处理任何 Imgur ID 但我想在上传新图像后转换到此路线 使用返回的 Imgur ID 这是该应用程序的相关部分 http
  • jquery window.open 在 ajax 成功中被阻止

    尝试在我的 ajax 成功调用中打开一个新的浏览器窗口 但是 它被阻止为弹出窗口 我做了一些搜索 发现用户事件需要绑定到 window open 才能避免这种情况发生 我还找到了这个解决方案 您可以在 ajax 之前打开一个空白窗口 然后在
  • 仅一页 JavaScript 应用程序

    您是否尝试过单页 Web 应用程序 即浏览器仅从服务器 获取 一页 其余部分由客户端 JavaScript 代码处理 此类 应用程序页面 的一个很好的例子是 Gmail 对于更简单的应用程序 例如博客和 CMS 使用这种方法有哪些优点和缺点
  • 如何使用 JavaScript 获取没有 HTML 元素的纯文本?

    我的 HTML 中有 1 按钮和一些文本 如下所示 function get content I don t know how to do in here
  • 在闪亮的数据表中为每个单元格显示工具提示或弹出窗口?

    有没有什么方法可以为 r闪亮数据表中的每个单元格获取工具提示 有很多方法可以获取悬停行或列 但我找不到一种方法来获取行和列索引并为每个单元格显示不同的悬停工具提示 任何人都可以修改以下代码吗 library shiny library DT
  • 未捕获的错误:找不到模块“jquery”

    我在用Electron https github com atom electron制作桌面应用程序 在我的应用程序中 我正在加载一个外部站点 Atom 应用程序之外 可以说http mydummysite index html http
  • 是否有任何非轮询方式来检测 DOM 元素的大小或位置何时发生变化?

    很长一段时间以来 我一直在寻找一种方法来检测 DOM 元素的大小或位置何时发生变化 这可能是因为窗口调整了大小 或者因为向该元素添加了新的子元素 或者因为在该元素周围添加了新元素 或者因为 CSS 规则已更改 或者因为用户更改了浏览器的字体
  • 如何使JavaScript函数在Eclipse“大纲视图”中可见?

    我有这样的代码 但如果它在匿名函数中定义 则无法打开函数大纲 类没有问题 我该如何概述something2 请分享一些提示 我可以将所有函数标记为构造函数 但这是无效的方法 start of track event required deb
  • 将数组排序为第一个最小值、第一个最大值、第二个最小值、第二个最大值等

    编写一个JS程序 返回一个数组 其中第一个元素是第一个最小值 第二个元素是第一个最大值 依此类推 该程序包含一个函数 该函数接受一个参数 一个数组 该函数根据要求返回数组 输入示例 array 2 4 7 1 3 8 9 预期输出 1 9
  • 将 javascript 整数转换为字节数组并返回

    function intFromBytes x var val 0 for var i 0 i lt x length i val x i if i lt x length 1 val val lt lt 8 return val func
  • Select2 下拉列表动态添加、删除和刷新项目

    这让我发疯 为什么 Select2 不能在其页面上实现清晰的方法或示例如何在 Select2 上进行简单的 CRUD 操作 我有一个 select2 从 ajax 调用获取数据
  • 单击引导分页链接时调用 jquery 函数

    我想在单击引导分页链接时调用 jquery 函数 假设我想从第1页遍历到第2页 应该调用一个jquery函数 我正在使用以下代码 但它不起作用 ul pagination on click li function alert page ch
  • 防止文本区域出现新行

    我正在开发聊天功能 使用 Vue 并使用文本区域作为输入 以便溢出换行 并且对于编写较长消息的用户来说更具可读性 不幸的是 当用户按下 Enter 键并提交时 光标会在提交之前移动到新行 从而使用户体验感觉不佳 关于如何使用普通 Javas
  • 如何在打字稿文件中导入没有定义文件的js库

    随着我们的项目变得越来越大 我想从 JavaScript 切换到 TypeScript 以帮助进行代码管理 然而 我们使用许多库作为 amd 模块 我们不想将其转换为 TypeScript 我们仍然想将它们导入 TypeScript 文件

随机推荐