Skip to content

Commit d5e4f53

Browse files
committed
Set translate and scale only if set by the user.
Auto fit site only if translate and scale are not set.
1 parent 499bcae commit d5e4f53

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/js/geomap.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ export class Geomap {
9090
if (!self.properties.height)
9191
self.properties.height = self.properties.width / 1.92;
9292

93-
if (!self.properties.scale)
94-
self.properties.scale = self.properties.width / 5.4;
95-
96-
if (!self.properties.translate)
97-
self.properties.translate = [self.properties.width / 2, self.properties.height / 2];
98-
9993
self.svg = selection.append('svg')
10094
.attr('width', self.properties.width)
10195
.attr('height', self.properties.height);
@@ -108,20 +102,25 @@ export class Geomap {
108102

109103
// Set map projection and path.
110104
const proj = self.properties.projection()
111-
.scale(self.properties.scale)
112-
.translate(self.properties.translate)
113105
.precision(.1);
114106

107+
// Apply optional user settings to projection.
108+
if (self.properties.scale) proj.scale(self.properties.scale);
109+
if (self.properties.translate) proj.scale(self.properties.translate);
110+
115111
// Not every projection supports rotation, e. g. albersUsa does not.
116112
if (proj.hasOwnProperty('rotate') && self.properties.rotate)
117113
proj.rotate(self.properties.rotate);
118114

119115
self.path = geoPath().projection(proj);
120-
121116
const drawGeoData = geo => {
122117
self.geo = geo;
123118
self.geoFeature = topoFeature(geo, geo.objects[self.properties.units]);
124-
proj.fitSize([self.properties.width, self.properties.height], self.geoFeature);
119+
120+
// Auto fit size if scale and translate are not set.
121+
if (self.properties.scale === null && self.properties.translate === null) {
122+
proj.fitSize([self.properties.width, self.properties.height], self.geoFeature);
123+
}
125124

126125
self.svg.append('g').attr('class', 'units zoom')
127126
.selectAll('path')

0 commit comments

Comments
 (0)