这是我在JavaScript中的脚本,
当我调用函数calculate()
时,JSON不调用方法ConvertDataTabletoString()
,当我加载页面时,只执行一次。
我希望每隔5秒调用一次spade方法。
我在.aspx中调用e vb.net函数。
我该怎么办?
var map;
var markers;
function onClickRow(detailUrl) {
debugger;
}
function calulate() {
//Call the approve method on the code behind
markers = JSON.parse('<%=ConvertDataTabletoString() %>');
var markerlivo = new google.maps.Marker
(
{
position: new google.maps.LatLng(43.5518760, 10.3080108),
map: map,
title: 'Porto Livorno'
}
);
var infowindow = new google.maps.InfoWindow({
content: 'Location info:Porto Livorno<br/>Country Name:Italy'
});
var infowindowLivorno = new google.maps.InfoWindow({
content: 'Location info:Porto Livorno<br/>Country Name:Italy'
});
google.maps.event.addListener(markerlivo, 'click', function () {
// Calling the open method of the infoWindow
infowindowLivorno.open(map, markerlivo);
});
for (i = 0; i < markers.length - 1; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(markers[i].F_LATPRIMI, markers[i].F_LONPRIMI);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.nome
});
(function (i, marker) {
google.maps.event.addListener(marker, 'click', function () {
if (!infowindow) {
infowindow = new google.maps.InfoWindow();
}
infowindow.setContent('Latitudine: ' + markers[i].F_LATPRIMI + '<br/>longitudine: ' + markers[i].F_LONPRIMI + '<br/>Data' + markers[i].D_TS + '<br/>Velocità ' + markers[i].F_VELOCITA);
infowindow.open(map, marker);
});
})(i, marker);
}
/*
Dim Nome As String
Dim I_ID_NAVE As Integer
Dim F_LATPRIMI As Double
Dim F_LONPRIMI As Double
Dim D_TS As Date
Dim F_ROTAZIONE As Double
Dim F_VELOCITA As Double
*/
}
function initialize() {
var mapProp = {
center: new google.maps.LatLng(43.5518760, 10.3080108),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions:
{
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
poistion: google.maps.ControlPosition.TOP_RIGHT,
mapTypeIds: [google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.HYBRID,
google.maps.MapTypeId.SATELLITE]
},
navigationControl: true,
navigationControlOptions:
{
style: google.maps.NavigationControlStyle.ZOOM_PAN
},
scaleControl: true,
disableDoubleClickZoom: true,
draggable: true,
streetViewControl: true,
draggableCursor: 'move'
};
map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
aggiorna();
}
var bool=true
function aggiorna() {
// while (bool === true)
try{
setTimeout(aggiorna, 5000)
calulate();
}
catch (e) {
/*
* This will happen if the sleep is woken up - you might want to check
* if enough time has passed and sleep again if not - depending on how
* important the sleep time is to you.
*/
}
}
google.maps.event.addDomListener(window, 'load', initialize);
答案 0 :(得分:0)
您希望每5秒调用哪种方法? 计算或 ConvertDataTabletoString ?
您可以考虑使用setInterval,例如
var interval = setInterval(calculate, 5000);
将每隔5秒调用计算方法,直到您使用
清除间隔clearInterval(interval);
溴