Skip to content

Commit 747e29e

Browse files
authored
Add workaround for map panning bug (#1171)
1 parent 582fe2d commit 747e29e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

python/jupyter_leaflet/src/controls/MeasureControl.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
import L from '../leaflet';
66
import * as control from './Control';
77

8+
// Workaround for map panning bug
9+
// from https://github.com/ljagis/leaflet-measure/issues/171#issuecomment-1137483548
10+
L.Control.Measure.include({
11+
// set icon on the capture marker
12+
_setCaptureMarkerIcon: function () {
13+
// disable autopan
14+
this._captureMarker.options.autoPanOnFocus = false;
15+
16+
// default function
17+
this._captureMarker.setIcon(
18+
L.divIcon({
19+
iconSize: this._map.getSize().multiplyBy(2),
20+
})
21+
);
22+
},
23+
});
824
export class LeafletMeasureControlModel extends control.LeafletControlModel {
925
defaults() {
1026
return {
@@ -37,7 +53,6 @@ export class LeafletMeasureControlView extends control.LeafletControlView {
3753
}
3854

3955
create_obj() {
40-
//@ts-ignore
4156
this.obj = L.control.measure(this.get_options());
4257
this.default_units = L.extend({}, this.obj.options.units);
4358
}

python/jupyter_leaflet/src/definitions/leaflet-extend.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,17 @@ declare module 'leaflet' {
138138
constructor(options?: LegendOptions);
139139
options: LegendOptions;
140140
}
141+
142+
interface MeasureOptions extends ControlOptions {}
143+
class Measure extends Control {
144+
constructor(options?: MeasureOptions);
145+
options: MeasureOptions;
146+
_setCaptureMarkerIcon: () => void;
147+
}
141148
}
142149

143150
declare namespace control {
144151
function legend(options?: Control.LegendOptions): Control.Legend;
152+
function measure(options?: Control.MeasureOptions): Control.Measure;
145153
}
146154
}

0 commit comments

Comments
 (0)