only update the GMaps part that require updating.

Even when the zoom doesn’t change by repeatedly calling setZoom,
Firefox shows network operations. These can be avoided, although
this doesn’t improve the performance much when using the GMaps
layers.
This commit is contained in:
Stefan Breunig
2013-03-12 10:12:31 +01:00
parent bc63c47d47
commit 2c07d2b803

View File

@ -109,6 +109,8 @@ L.Google = L.Class.extend({
map.backgroundColor = '#ff0000'; map.backgroundColor = '#ff0000';
this._google = map; this._google = map;
this._lastZoomPosition = null;
this._lastMapPosition = null;
}, },
_resetCallback: function(e) { _resetCallback: function(e) {
@ -122,11 +124,20 @@ L.Google = L.Class.extend({
_update: function() { _update: function() {
this._resize(); this._resize();
var center = this._map.getCenter(); // update map position if required
var _center = new google.maps.LatLng(center.lat, center.lng); var newCenter = this._map.getCenter();
if(this._lastMapPosition !== newCenter) {
var _center = new google.maps.LatLng(newCenter.lat, newCenter.lng);
this._google.setCenter(_center); this._google.setCenter(_center);
}
this._lastMapPosition = newCenter;
// update zoom level if required
var newZoom = this._map.getZoom();
if(this._lastZoomPosition !== newZoom) {
this._google.setZoom(this._map.getZoom()); this._google.setZoom(this._map.getZoom());
}
this._lastZoomPosition = newZoom;
}, },
_resize: function() { _resize: function() {