Skip to content

Commit 416335f

Browse files
committed
Limit effective zoom level by new "Maximum zoom level" option
1 parent 20150a2 commit 416335f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
- Add options `customAttribution` and `customAttributionText`.
5050
- Rename `point_` prefix to `__field_` when interpolating datapoint field values
5151
- Remove automatic key suffix for popover texts
52+
- Limit effective zoom level by new "Maximum zoom level" option
5253

5354
## v0.2.0
5455

src/partials/editor.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,14 @@ <h3 class="main-section-heading">Visual options</h3>
293293

294294
<div class="gf-form-group">
295295
<h5>Center and zoom level</h5>
296+
296297
<gf-form-switch class="gf-form" label="Fit to data" label-class="width-10" checked="ctrl.panel.mapFitData" on-change="ctrl.updateMapCenter()">
297298
</gf-form-switch>
299+
<div class="gf-form">
300+
<label class="gf-form-label width-10">Maximum zoom level</label>
301+
<input type="text" class="input-small gf-form-input max-width-18" ng-model="ctrl.panel.maximumZoom" ng-change="ctrl.updateMapCenter()"
302+
placeholder="9" ng-model-onblur />
303+
</div>
298304

299305
<ng-thing ng-show="ctrl.panel.mapFitData != true">
300306

src/worldmap.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ export default class WorldMap {
4040
center.mapCenterLatitude,
4141
center.mapCenterLongitude
4242
);
43+
44+
let zoomLevel = this.getEffectiveZoomLevel(center.mapZoomLevel);
45+
4346
this.map = L.map(this.mapContainer, {
4447
worldCopyJump: true,
4548
preferCanvas: true,
4649
center: mapCenter,
47-
zoom: center.mapZoomLevel,
50+
zoom: zoomLevel,
4851
zoomControl: this.ctrl.settings.showZoomControl,
4952
attributionControl: this.ctrl.settings.showAttribution,
5053
});
@@ -97,6 +100,13 @@ export default class WorldMap {
97100
//this.ctrl.updatePanelCorner();
98101
}
99102

103+
getEffectiveZoomLevel(zoomLevel) {
104+
if (this.ctrl.settings.maximumZoom) {
105+
zoomLevel = Math.min(parseInt(this.ctrl.settings.maximumZoom), zoomLevel);
106+
}
107+
return zoomLevel;
108+
}
109+
100110
createLegend() {
101111
this.legend = (<any>window).L.control({ position: 'bottomleft' });
102112
this.legend.onAdd = () => {
@@ -380,6 +390,8 @@ export default class WorldMap {
380390
zoomLevel = this.map.getBoundsZoom(bounds);
381391
}
382392

393+
zoomLevel = this.getEffectiveZoomLevel(zoomLevel);
394+
383395
// Apply coordinates and zoom level to Leaflet map.
384396
this.map.setView(coordinates, zoomLevel, options);
385397

src/worldmap_ctrl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const panelDefaults = {
1818
mapCenterLatitude: 0,
1919
mapCenterLongitude: 0,
2020
initialZoom: 1,
21+
maximumZoom: null,
2122
mapZoomByRadius: null,
2223
valueName: "total",
2324
circleMinSize: 2,

0 commit comments

Comments
 (0)