我有這個奇怪的問題:我必須從單獨的KML文件生成許多KML圖層到單個地圖窗口。數量不等,像一對夫婦和少於五十。目前,當我將1,4或15個KML文件(作爲URI)作爲數組提供時,我的代碼正在產生正確的行爲。好吧,基本上我知道我的代碼是可用的,我的KML文件足夠有效。在Google Maps API頁面上不會顯示15個以上的KML圖層
這裏是我怎麼稱呼我的地圖初始化與23 KML URI的數組的例子:
<body id="body" onload="initmap(new Array('https://CENCORED/kml/project64.kml', 'https://CENCORED/kml/project65.kml', 'https://CENCORED/kml/project66.kml', 'https://CENCORED/kml/project67.kml', 'https://CENCORED/kml/project69.kml', 'https://CENCORED/kml/project70.kml', 'https://CENCORED/kml/project71.kml', 'https://CENCORED/kml/project72.kml', 'https://CENCORED/kml/project75.kml', 'https://CENCORED/kml/project76.kml', 'https://CENCORED/kml/project80.kml', 'https://CENCORED/kml/project81.kml', 'https://CENCORED/kml/project82.kml', 'https://CENCORED/kml/project83.kml', 'https://CENCORED/kml/project84.kml', 'https://CENCORED/kml/project85.kml', 'https://CENCORED/kml/project86.kml', 'https://CENCORED/kml/project87.kml', 'https://CENCORED/kml/project88.kml', 'https://CENCORED/kml/project89.kml', 'https://CENCORED/kml/project90.kml', 'https://CENCORED/kml/project91.kml', 'https://CENCORED/kml/project92.kml'))">
然而,問題出現時,當我給我的代碼,有十六個陣列(16 )或更多KML URI。然後這些KML文件將永遠不會在地圖畫布上呈現。但是,任何地方都不會出現錯誤,還有:我知道地圖上的KML文件「在那裏」。我怎麼知道這個?好吧,你可以看到,我的代碼生成的每個KML文件的信息窗口,因爲我知道有些地方的KML文件都應該被定位,我能夠點擊的話,即使他們是看不見的或沒有被渲染並且InfoWindow出現。正如預期的那樣。
這裏是我的map_display.js的完整內容,它包含被調用的函數initmap()。
function initmap(urls){
// Creating an option object for the map
var myLatlng = new google.maps.LatLng(63.349501, 26.817627);
var options = {
zoom: 6,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Initializing the map
var map = new google.maps.Map(document.getElementById('map_canvas'), options);
if(urls != null) {
for(var i=0;i<urls.length;i++) {
var url = urls[i];
url = url+"?dummy="+(new Date()).getTime();
var ctaLayer = createKML(url);
ctaLayer.setMap(map);
}
}
function createKML(url){
var ctaLayer = new google.maps.KmlLayer(url, {suppressInfoWindows: true, preserveViewport: true});
// Creating a correct reference for project edit URL
var editUrl = urls[i];
var s1 = editUrl.indexOf("project");
s1 = s1+7;
var s2 = editUrl.indexOf(".kml");
editUrl = editUrl.substring(s1, s2);
var baseUrl = getbaseUrl();
var infoItems = new Array();
infoItems = getInfo(editUrl);
editUrl = '<b>' + infoItems[1] + '</b><br />' + infoItems[0] + '<br /><br /><a href="' + baseUrl + '/frontend/viewproject/' + editUrl + '">Katso projektin tiedot</a>';
// Creating an InfoWindow object
var infowindow = new google.maps.InfoWindow({ content: editUrl });
google.maps.event.addListener(ctaLayer, 'click', function(kmlEvent) {
var clickPos = kmlEvent.latLng;
var posX = new google.maps.LatLng(clickPos.lat(), clickPos.lng());
infowindow.close();
infowindow.setPosition(posX);
infowindow.open(map);
});
return ctaLayer;
}
function getbaseUrl(){
var baseUrl = "https://" + window.location.hostname;
var firstpath = window.location.pathname;
var first_slash = firstpath.indexOf("/", 1);
firstpath = firstpath.substring(0, first_slash);
baseUrl = baseUrl + firstpath;
return baseUrl;
}
function getInfo(pid){
var jsoninfo = new Array();
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
var json_location = getbaseUrl() + '/frontend/project_json/' + pid;
xmlhttp.open("GET",json_location,false);
xmlhttp.send();
var json_answer = eval('(' + xmlhttp.responseText + ')');
jsoninfo[0] = json_answer["projectName"];
jsoninfo[1] = json_answer["builder"];
return jsoninfo;
}
}
有人可以幫我嗎?我很抱歉,但我無法提供實時系統作爲參考,因爲它是受密碼保護的更大頁面的一部分。
GeoXML3解決了我的問題,至少現在。 :) – 2012-04-25 21:39:32