|
48 | 48 | }
|
49 | 49 | },
|
50 | 50 |
|
| 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 | + |
51 | 77 | onAdd: function(map) {
|
52 | 78 | var container = L.Routing.Itinerary.prototype.onAdd.call(this, map);
|
53 | 79 |
|
54 | 80 | this._map = map;
|
55 | 81 | this._map.addLayer(this._plan);
|
56 | 82 |
|
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); |
82 | 84 |
|
83 | 85 | if (this._plan.options.geocoder) {
|
84 | 86 | container.insertBefore(this._plan.createGeocoders(), container.firstChild);
|
|
88 | 90 | },
|
89 | 91 |
|
90 | 92 | onRemove: function(map) {
|
| 93 | + map.off('zoomend', this.onZoomEnd, this); |
91 | 94 | if (this._line) {
|
92 | 95 | map.removeLayer(this._line);
|
93 | 96 | }
|
|
0 commit comments