Here is problem,
I have some java code
that runs
on a server
and every 60seconds
selects 60seconds
worth of data, constructs an object out of each one and then adds it to a list.
Now on the client side
i have some javascript
that calls a methods on the server and returns this list of object. these objects each represents a image that needs to move to a certain location on the screen.
Now here comes the problem im currently facing. I have about 60seconds to loop through these objects and animate the image to the right location. Now when I try loop through it almost does the loop instantly and all the images just appears at the starting location. What this tells me is the function i call to do the animation doesn't get time to complete as another call to that function is interrupting it.
How does one go about controlling this so that no matter what the size I always finish the list in 60seconds?
ps... I have tried setTimeout
to no avail
procedural client side really not my stronger side
As Requested, the json that is received is an array of objects
function dataServer() {
$.getJSON("/service/data/message", function(data) {
if(data) {
msgs = data;
check = true;
counter = 0;
var total = data.length;
waitTime = (60000 / total) - (8 * delay);
for(var message in data) {
var latLng = new google.maps.LatLng(-54.75, 148);
var marker = new google.maps.Marker({
position: latLng,
map: map,
optimized: true,
icon: new google.maps.MarkerImage( image , undefined, undefined, undefined, new google.maps.Size(85, 60))
});
position = [-55, 148];
result = [ data[message].x, data[message].y ];
i = 0;
deltaLat = (result[0] - position[0])/numDeltas;
deltaLng = (result[1] - position[1])/numDeltas;
var w = 85;
var h = 60;
var shrinkW = w / 2;
var shrinkH = h /2;
var shrinkDeltaW = shrinkW / numDeltas;
var shrinkDeltaH = shrinkH / numDeltas;
var deltaW = w / numDeltas;
var deltaH = h / numDeltas;
var toSet = true;
function moveMarker(result){
position[0] += deltaLat;
position[1] += deltaLng;
if(i % 4 == 0) {
w -= deltaW;
h -= deltaH;
}
var latlng = new google.maps.LatLng(position[0], position[1]);
marker.setPosition(latlng);
marker.setIcon(new google.maps.MarkerImage( image , undefined, undefined, undefined, new google.maps.Size(w, h)));
if(i == (numDeltas - 1)) {
var latlng = new google.maps.LatLng(data[message].x, data[message].y);
marker.setPosition(latlng);
i++;
}
if(i!=numDeltas){
i++;
if(markerArray.length > 10) {
shrinkW -= shrinkDeltaW;
shrinkH -= shrinkDeltaH;
markerArray[0].setIcon(new google.maps.MarkerImage( image , undefined, undefined, undefined, new google.maps.Size(shrinkW, shrinkH)));
if(i == (numDeltas -1)) {
markerArray[0].setIcon(new google.maps.MarkerImage( image , undefined, undefined, undefined, new google.maps.Size(85, 60)));
markerArray[0].setMap(null);
markerArray.splice(markerArray[0], 1);
feature = map.data.getFeatureById(dataArray[0].countryCode);
if (feature) {
feature.setProperty('colour', dataArray[0].opacity);
} else {
}
dataArray.splice(dataArray[0], 1);
}
}
delay = waitTime / 8;
setTimeout(moveMarker, delay);
}
}
moveMarker(result);
markerArray.push(marker);
dataArray.push(data[message]);
}
} else {
dataServer();
}
});
if(check == false) {
counter++;
if(counter == 100) {
window.location.href = "/intermission.htm";
}
}
check = false;
}