Skip to content

Commit

Permalink
Add “zoomControl” and “attributionControl” to visual option settings
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 20, 2019
1 parent f73bb50 commit 0e476d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/partials/editor.html
Expand Up @@ -48,6 +48,8 @@ <h5 class="section-heading">Map Visual Options</h5>
ng-change="ctrl.render()" ng-model-onblur />
</div>
<gf-form-switch class="gf-form" label="Show Legend" label-class="width-10" checked="ctrl.panel.showLegend" on-change="ctrl.toggleLegend()"></gf-form-switch>
<gf-form-switch class="gf-form" label="Show Zoom Control" label-class="width-10" checked="ctrl.panel.showZoomControl" on-change="ctrl.toggleZoomControl()"></gf-form-switch>
<gf-form-switch class="gf-form" label="Show Attribution" label-class="width-10" checked="ctrl.panel.showAttribution" on-change="ctrl.toggleAttribution()"></gf-form-switch>
<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>
</div>
<div class="section gf-form-group">
Expand Down
2 changes: 2 additions & 0 deletions src/worldmap.ts
Expand Up @@ -43,6 +43,8 @@ export default class WorldMap {
preferCanvas: true,
center: mapCenter,
zoom: parseInt(this.ctrl.panel.initialZoom, 10) || 1,
zoomControl: this.ctrl.panel.showZoomControl,
attributionControl: this.ctrl.panel.showAttribution,
});
this.setMouseWheelZoom();

Expand Down
23 changes: 20 additions & 3 deletions src/worldmap_ctrl.ts
Expand Up @@ -27,6 +27,8 @@ const panelDefaults = {
unitSingle: "",
unitPlural: "",
showLegend: true,
showZoomControl: true,
showAttribution: true,
mouseWheelZoom: false,
esMetric: "Count",
decimals: 0,
Expand Down Expand Up @@ -166,9 +168,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
}

onPanelTeardown() {
if (this.map) {
this.map.remove();
}
this.teardownMap();
}

onInitEditMode() {
Expand Down Expand Up @@ -250,13 +250,30 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
this.map.setZoom(this.panel.initialZoom || 1);
}

teardownMap() {
if (this.map) {
this.map.remove();
this.map = null;
}
}

toggleLegend() {
if (!this.panel.showLegend) {
this.map.removeLegend();
}
this.render();
}

toggleZoomControl() {
this.teardownMap();
this.render();
}

toggleAttribution() {
this.teardownMap();
this.render();
}

toggleMouseWheelZoom() {
this.map.setMouseWheelZoom();
this.render();
Expand Down

0 comments on commit 0e476d0

Please sign in to comment.