Skip to content

Commit

Permalink
Set translate and scale only if set by the user.
Browse files Browse the repository at this point in the history
Auto fit site only if translate and scale are not set.
  • Loading branch information
yaph committed Oct 3, 2024
1 parent 499bcae commit d5e4f53
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/js/geomap.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export class Geomap {
if (!self.properties.height)
self.properties.height = self.properties.width / 1.92;

if (!self.properties.scale)
self.properties.scale = self.properties.width / 5.4;

if (!self.properties.translate)
self.properties.translate = [self.properties.width / 2, self.properties.height / 2];

self.svg = selection.append('svg')
.attr('width', self.properties.width)
.attr('height', self.properties.height);
Expand All @@ -108,20 +102,25 @@ export class Geomap {

// Set map projection and path.
const proj = self.properties.projection()
.scale(self.properties.scale)
.translate(self.properties.translate)
.precision(.1);

// Apply optional user settings to projection.
if (self.properties.scale) proj.scale(self.properties.scale);
if (self.properties.translate) proj.scale(self.properties.translate);

// Not every projection supports rotation, e. g. albersUsa does not.
if (proj.hasOwnProperty('rotate') && self.properties.rotate)
proj.rotate(self.properties.rotate);

self.path = geoPath().projection(proj);

const drawGeoData = geo => {
self.geo = geo;
self.geoFeature = topoFeature(geo, geo.objects[self.properties.units]);
proj.fitSize([self.properties.width, self.properties.height], self.geoFeature);

// Auto fit size if scale and translate are not set.
if (self.properties.scale === null && self.properties.translate === null) {
proj.fitSize([self.properties.width, self.properties.height], self.geoFeature);
}

self.svg.append('g').attr('class', 'units zoom')
.selectAll('path')
Expand Down

0 comments on commit d5e4f53

Please sign in to comment.