Skip to content

Commit 4707bbe

Browse files
authored
Add a toggle to disable panning/dragging on the map
* added dragging toggle * added option to disable double click zoom as well * forgot to call setter on init
1 parent 30103bd commit 4707bbe

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/partials/editor.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ <h5>Appearance</h5>
361361
<gf-form-switch class="gf-form" label="Show Zoom Control" label-class="width-10" checked="ctrl.panel.showZoomControl" on-change="ctrl.restart()"></gf-form-switch>
362362
<gf-form-switch class="gf-form" label="Mouse Wheel Zoom" label-class="width-10" checked="ctrl.panel.mouseWheelZoom" on-change="ctrl.toggleMouseWheelZoom()"></gf-form-switch>
363363
</div>
364-
364+
<gf-form-switch class="gf-form" label="Dragging" label-class="width-10" checked="ctrl.panel.dragging" on-change="ctrl.toggleDragging()"></gf-form-switch>
365+
</div>
366+
<gf-form-switch class="gf-form" label="Double Click Zoom" label-class="width-10" checked="ctrl.panel.doubleClickZoom" on-change="ctrl.toggleDoubleClickZoom()"></gf-form-switch>
367+
</div>
365368
<!-- Legend -->
366369
<div class="gf-form-subgroup">
367370
<gf-form-switch class="gf-form" label="Show Legend" label-class="width-10" checked="ctrl.panel.showLegend" on-change="ctrl.toggleLegend()"></gf-form-switch>

src/worldmap.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export default class WorldMap {
4747
attributionControl: this.ctrl.settings.showAttribution,
4848
});
4949
this.setMouseWheelZoom();
50+
this.setDragging();
51+
this.setDoubleClickZoom();
5052

5153
const selectedTileServer = tileServers[this.ctrl.tileServer];
5254
(window as any).L.tileLayer(selectedTileServer.url, {
@@ -445,6 +447,22 @@ export default class WorldMap {
445447
}
446448
}
447449

450+
setDragging() {
451+
if (!this.ctrl.settings.dragging) {
452+
this.map.dragging.disable();
453+
} else {
454+
this.map.dragging.enable();
455+
}
456+
}
457+
458+
setDoubleClickZoom() {
459+
if (!this.ctrl.settings.doubleClickZoom) {
460+
this.map.doubleClickZoom.disable();
461+
} else {
462+
this.map.doubleClickZoom.enable();
463+
}
464+
}
465+
448466
addCircles(circles) {
449467
// Todo: Optionally add fixed custom attributions to the circle layer.
450468
const attribution = undefined;

src/worldmap_ctrl.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const panelDefaults = {
4040
customAttribution: false,
4141
customAttributionText: null,
4242
mouseWheelZoom: false,
43+
dragging: true,
44+
doubleClickZoom: true,
4345
esGeoPoint: null,
4446
// Todo: Investigate: Is "Count" a reasonable default here
4547
// or does it confuse the operator?
@@ -504,6 +506,16 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
504506
this.render();
505507
}
506508

509+
toggleDragging() {
510+
this.map.setDragging();
511+
this.render();
512+
}
513+
514+
toggleDoubleClickZoom() {
515+
this.map.setDoubleClickZoom();
516+
this.render();
517+
}
518+
507519
toggleCustomAttribution() {
508520
if (this.settings.customAttribution) {
509521
const attributionControl = this.map.map.attributionControl;

0 commit comments

Comments
 (0)