您可以使用類似於此處描述的分頁技術光標:
Pagination in Google App Engine with Java
當與地圖加載你的頁面,有它做一個空白光標參數的AJAX請求。請求處理程序將獲取少量實體,然後返回包含它們和遊標的響應(如果還有實體)。
從客戶端javascript中,在顯示地圖上的項目後,如果響應中有一個遊標,則以遊標爲參數啓動一個新的請求。在請求處理程序中,如果提供了遊標,請在進行查詢時使用它。
這將設置一個連續的AJAX請求循環,直到所有項目已被提取並顯示在地圖上。
更新:
你可以寫返回JSON這樣的服務:
{
items:
[
{ lat: 1.23, lon: 3.45, abc = 'def' },
{ lat: 2.34, lon: 4.56, abc = 'ghi' }
],
cursor: '1234abcd'
}
因此,它包含的項目的陣列(經/緯度和任何其他信息,你需要每件)以及一個遊標(當最後一個實體被提取時它將爲null)。
然後,在客戶端我會建議使用jQuery的ajax功能,使Ajax調用,像這樣:
$(document).ready(function()
{
// first you may need to initialise the map - then start fetching items
fetchItems(null);
});
function fetchItems(cursor)
{
// build the url to request the items - include the cursor as an argument
// if one is specified
var url = "/path/getitems";
if (cursor != null)
url += "?cursor=" + cursor;
// start the ajax request
$.ajax({
url: url,
dataType: 'json',
success: function(response)
{
// now handle the response - first loop over the items
for (i in response.items)
{
var item = response.items[i];
// add something to the map using item.lat, item.lon, etc
}
// if there is a cursor in the response then there are more items,
// so start fetching them
if (response.cursor != null)
fetchItems(response.cursor);
}});
}
謝謝,這聽起來就像是我的初衷。你能提供一些代碼嗎?只是一個例子,讓我開始,因爲我從來沒有使用過AJAX。 – cxk 2010-08-24 09:04:02
@cxk:我用一些示例代碼更新了我的回覆。 – 2010-08-25 01:09:36