Ecco una soluzione che pentole senza problemi e permette anche per altre richieste clic da queue'd mentre una padella precedente è già in corso:
var panPath = []; // An array of points the current panning action will use
var panQueue = []; // An array of subsequent panTo actions to take
var STEPS = 50; // The number of steps that each panTo action will undergo
function panTo(newLat, newLng) {
if (panPath.length > 0) {
// We are already panning...queue this up for next move
panQueue.push([newLat, newLng]);
} else {
// Lets compute the points we'll use
panPath.push("LAZY SYNCRONIZED LOCK"); // make length non-zero - 'release' this before calling setTimeout
var curLat = map.getCenter().lat();
var curLng = map.getCenter().lng();
var dLat = (newLat - curLat)/STEPS;
var dLng = (newLng - curLng)/STEPS;
for (var i=0; i < STEPS; i++) {
panPath.push([curLat + dLat * i, curLng + dLng * i]);
}
panPath.push([newLat, newLng]);
panPath.shift(); // LAZY SYNCRONIZED LOCK
setTimeout(doPan, 20);
}
}
function doPan() {
var next = panPath.shift();
if (next != null) {
// Continue our current pan action
map.panTo(new google.maps.LatLng(next[0], next[1]));
setTimeout(doPan, 20);
} else {
// We are finished with this pan - check if there are any queue'd up locations to pan to
var queued = panQueue.shift();
if (queued != null) {
panTo(queued[0], queued[1]);
}
}
}
fonte
2015-10-26 05:44:10
mai meno, c'è un modo per sovrascrivere questo? –
@Kai: non penso ci sia usando l'API. Potresti implementare l'animazione da solo, ma ciò potrebbe non valerne la pena (dipende da quanto è importante questa funzione). –
Io sostengo che questa funzionalità non è importante, ma il cliente sembra pensarla così. Poiché la navigazione è anche elencata in un menu a fisarmonica sul lato, l'utente può far saltare la mappa dappertutto scorrendo lungo la lista, e mentre così facendo potrebbero perdere traccia di dove si trova il marker in relazione alle aree familiari. –