Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 423738f

Browse files
committed
feat(geo): support min/max scale limits
fixes #5191
1 parent caf32e5 commit 423738f

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

‎src/components/modebar/buttons.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,18 @@ function handleGeo(gd, ev) {
548548

549549
if(attr === 'zoom') {
550550
var scale = geoLayout.projection.scale;
551+
var minScale = geoLayout.projection.minScale;
552+
var maxScale = geoLayout.projection.maxScale;
553+
551554
var newScale = (val === 'in') ? 2 * scale : 0.5 * scale;
552555

556+
// make sure the scale is within the min/max bounds
557+
if(newScale > maxScale) {
558+
newScale = maxScale;
559+
} else if(newScale < minScale) {
560+
newScale = minScale;
561+
}
562+
553563
Registry.call('_guiRelayout', gd, id + '.projection.scale', newScale);
554564
}
555565
}

‎src/plots/geo/geo.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,14 @@ function getProjection(geoLayout) {
709709

710710
projection.precision(constants.precision);
711711

712+
// https://github.com/d3/d3-zoom/blob/master/README.md#zoom_scaleExtent
713+
projection.scaleExtent = function() {
714+
var minscale = projLayout.minscale;
715+
var maxscale = projLayout.maxscale;
716+
if(maxscale === -1) maxscale = Infinity;
717+
return [100 * minscale, 100 * maxscale];
718+
};
719+
712720
if(geoLayout._isSatellite) {
713721
projection.tilt(projLayout.tilt).distance(projLayout.distance);
714722
}
@@ -806,4 +814,4 @@ function makeRangeBox(lon, lat) {
806814
[lon0, lat0]
807815
]]
808816
};
809-
}
817+
}

‎src/plots/geo/layout_attributes.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ var attrs = module.exports = overrideAll({
177177
'that fits the map\'s lon and lat ranges. '
178178
].join(' ')
179179
},
180+
minScale: {
181+
valType: 'number',
182+
min: 0,
183+
dflt: 0,
184+
description: [
185+
'Minimal zoom level of the map view.',
186+
'A minScale of *0.5* (50%) corresponds to a zoom level',
187+
'where the map has half the size of base zoom level.'
188+
].join(' ')
189+
},
190+
maxScale: {
191+
valType: 'number',
192+
min: 0,
193+
dflt: Infinity,
194+
description: [
195+
'Maximal zoom level of the map view.',
196+
'A maxScale of *2* (200%) corresponds to a zoom level',
197+
'where the map is twice as big as the base layer.'
198+
].join(' ')
199+
},
180200
},
181201
center: {
182202
lon: {

‎src/plots/geo/layout_defaults.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
161161
}
162162

163163
coerce('projection.scale');
164+
coerce('projection.minScale');
165+
coerce('projection.maxScale');
164166

165167
show = coerce('showland', !visible ? false : undefined);
166168
if(show) coerce('landcolor');
@@ -205,6 +207,8 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
205207
// clear attributes that will get auto-filled later
206208
if(fitBounds) {
207209
delete geoLayoutOut.projection.scale;
210+
delete geoLayoutOut.projection.minScale;
211+
delete geoLayoutOut.projection.maxScale;
208212

209213
if(isScoped) {
210214
delete geoLayoutOut.center.lon;

‎src/plots/geo/zoom.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module.exports = createGeoZoom;
3232
function initZoom(geo, projection) {
3333
return d3.behavior.zoom()
3434
.translate(projection.translate())
35+
.scaleExtent(projection.scaleExtent())
3536
.scale(projection.scale());
3637
}
3738

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /