Skip to content

Commit 06d0264

Browse files
committed
Should fix #304
1 parent bdf2c39 commit 06d0264

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

src/L.Routing.Control.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,39 @@
4848
}
4949
},
5050

51+
onZoomEnd: function() {
52+
if (!this._selectedRoute ||
53+
!this._router.requiresMoreDetail) {
54+
return;
55+
}
56+
57+
var map = this._map;
58+
if (this._router.requiresMoreDetail(this._selectedRoute,
59+
map.getZoom(), map.getBounds())) {
60+
this.route({
61+
callback: L.bind(function(err, routes) {
62+
var i;
63+
if (!err) {
64+
for (i = 0; i < routes.length; i++) {
65+
this._routes[i].properties = routes[i].properties;
66+
}
67+
this._updateLineCallback(err, routes);
68+
}
69+
70+
}, this),
71+
simplifyGeometry: false,
72+
geometryOnly: true
73+
});
74+
}
75+
},
76+
5177
onAdd: function(map) {
5278
var container = L.Routing.Itinerary.prototype.onAdd.call(this, map);
5379

5480
this._map = map;
5581
this._map.addLayer(this._plan);
5682

57-
this._map.on('zoomend', function() {
58-
if (!this._selectedRoute ||
59-
!this._router.requiresMoreDetail) {
60-
return;
61-
}
62-
63-
var map = this._map;
64-
if (this._router.requiresMoreDetail(this._selectedRoute,
65-
map.getZoom(), map.getBounds())) {
66-
this.route({
67-
callback: L.bind(function(err, routes) {
68-
var i;
69-
if (!err) {
70-
for (i = 0; i < routes.length; i++) {
71-
this._routes[i].properties = routes[i].properties;
72-
}
73-
this._updateLineCallback(err, routes);
74-
}
75-
76-
}, this),
77-
simplifyGeometry: false,
78-
geometryOnly: true
79-
});
80-
}
81-
}, this);
83+
this._map.on('zoomend', this.onZoomEnd, this);
8284

8385
if (this._plan.options.geocoder) {
8486
container.insertBefore(this._plan.createGeocoders(), container.firstChild);
@@ -88,6 +90,7 @@
8890
},
8991

9092
onRemove: function(map) {
93+
map.off('zoomend', this.onZoomEnd, this);
9194
if (this._line) {
9295
map.removeLayer(this._line);
9396
}

0 commit comments

Comments
 (0)