每个多边形的信息窗口

每个多边形的信息窗口

本文介绍了每个多边形的信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想显示每个多边形具有与Excel工作表不同的内容的信息窗口,但是我的代码显示了相同窗口,其中包含所有多边形的Excel最后一行的内容

请谁能解决这个问题.
提前谢谢.

Hi,
I want to show infowindow with each polygon having their own different contents from excel sheet but my code is showing same infowindow having contents of the last row of excel with all polygons

Please can anyone solve this .
Thanks in advance.

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Google Maps API Sample</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q" type="text/javascript"></script>
    <script type="text/javascript">

document.write("<pre>");
function initialize() {
array=new Array()
var Excel;
Excel = new ActiveXObject("Excel.Application");
Excel.Visible = false;
var a=Excel.Workbooks.Open("C:/desktop/Book1.xlsx").sheets(1);
for(var r=1;r&lt;=a.usedrange.rows.count;r++)
{
array[r-1]=new Array()
for(var c=1;c&lt;=a.usedrange.columns.count;c++)
array[r-1][c-1]=a.Cells(r,c).Value;
}
var x=0,y=0,p1=0,p2=0;
for(len in array)
{
x+=array[len][1];
y+=array[len][2];
}
p1=(x/array.length);
p2=(y/array.length);
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(p1,p2), 3);
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
map.addControl(new GMapTypeControl());

a=0,b=0,value=0;
for(m=0;m&lt;array.length;m++)&gt;
{

      var lat =array[m][1];
      var lon = array[m][2];
      var latOffset = 0.5;
      var lonOffset = 2;
      var latOffset2 = 0.5;
      var lonOffset2 = 2;
   	  var polygon = new GPolygon([
        new GLatLng(lat , lon ),
        new GLatLng(lat - latOffset2, lon + (lonOffset-1)),
        new GLatLng(lat - latOffset2, lon - (lonOffset-1)),
        new GLatLng(lat , lon ),
 ], "#ff0000", 0.1 , 0.9, "#ff0000", 0.9);
a=array[m][1];
b=array[m][2];
c=array[m][0];
f=array[m][3];
h=array[m][4];
s=array[m][6];
bsc=array[m][5];




GEvent.addListener(polygon, "click", function(overlay,lat,lon)
{
map.openInfoWindowHtml(overlay,"Site"+ s +"<br>"+"BSC"+ bsc +"<br>"+"Cell"+ c +"<br>"+"Cell lattitude"+ lat +"<br>"+"Cell longitude" + lon + "<br>"+"Freq"+ f +"<br>"+"Height"+ h );});

map.addOverlay(polygon);


}
  }

}


document.write("</br></br></br></br></br></br></pre>");
</script>
  </head>
  <body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;">
    <div id="map_canvas" style="width: 1000px; height: 900px"></div>
  </body>
</html>

推荐答案

var polyArray = [];

for(m=0;m<array.length;m++){>
var lat =array[m][1];
var lon = array[m][2];
var latOffset = 0.5;
var lonOffset = 2;
var latOffset2 = 0.5;
var lonOffset2 = 2;
var polygon = new GPolygon([
new GLatLng(lat , lon ),
new GLatLng(lat - latOffset2, lon + (lonOffset-1)),
new GLatLng(lat - latOffset2, lon - (lonOffset-1)),
new GLatLng(lat , lon ), ], "#ff0000", 0.1 , 0.9, "#ff0000", 0.9);
a=array[m][1];
b=array[m][2];
c=array[m][0];
f=array[m][3];
h=array[m][4];
s=array[m][6];
bsc=array[m][5];

polyArray.push(polygon)

GEvent.addListener(polyArray[polyArray.length-1], "click", function(overlay,lat,lon) {
    map.openInfoWindowHtml(overlay,"Site"+ s +"<br>"+"BSC"+ bsc +"<br>"+"Cell"+ c +"<br>"+"Cell lattitude"+ lat +"<br>"+"Cell longitude" + lon + "<br>"+"Freq"+ f +"<br>"+"Height"+ h );

});

map.addOverlay(polyArray[polyArray.length-1]);
}
}



不确定在openInfoWindowHtml上是否使用V3 API,但是通常我必须为每个对象(标记,多边形,其他任何东西)创建一个单独的信息窗口,并根据对象数组存储它们的数组. >
希望对您有帮助
Gib



not sure on the openInfoWindowHtml, I use the V3 API, but in that I usually have to create a seperate infowindow for each object (marker, poly, whatever) and also store an array of them in line with the object array.

hope this helps
Gib


这篇关于每个多边形的信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 20:06