Skip to content

Commit

Permalink
Merge pull request #80 from nzzdev/release-1.4.1
Browse files Browse the repository at this point in the history
Release 1.4.1
  • Loading branch information
fromdusttilldawn authored Apr 8, 2021
2 parents 91d2ff4 + f4177d1 commit 5af6c2c
Show file tree
Hide file tree
Showing 5 changed files with 552 additions and 11,152 deletions.
56 changes: 7 additions & 49 deletions helpers/minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,51 +119,6 @@ function getGlobeVegaSpec(options) {
return spec;
}

function getDimensions(spec, bbox, options) {
const minX = bbox[0];
const minY = bbox[1];
const maxX = bbox[2];
const maxY = bbox[3];

const distanceX = turf.distance([minX, minY], [maxX, minY], {
units: "radians",
});
const distanceY = turf.distance([maxX, minY], [maxX, maxY], {
units: "radians",
});
let aspectRatio = 1;
const defaultDimension = options.styleConfig.region.width;
const minDimension = options.styleConfig.region.minWidth;
let width;
let height;
const padding = 8;
if (distanceX > distanceY) {
aspectRatio = distanceY / distanceX;
width = defaultDimension;
height = defaultDimension * aspectRatio + padding;
if (height < minDimension) height = minDimension;
} else if (distanceX < distanceY) {
aspectRatio = distanceX / distanceY;
width = defaultDimension * aspectRatio + padding;
if (width < minDimension) width = minDimension;
height = defaultDimension;
}

const distance = turf.distance([minX, minY], [maxX, maxY], {
units: "radians",
});
let scaleFactor = height / distance;
if (width > height) {
scaleFactor = width / distance;
}

return {
width: width,
height: height,
scaleFactor: scaleFactor,
};
}

async function getRegionVegaSpec(options) {
const spec = JSON.parse(JSON.stringify(minimapRegionVegaSpec));
let bboxFeature = turf.rewind(turf.bboxPolygon(options.bounds), {
Expand All @@ -178,10 +133,13 @@ async function getRegionVegaSpec(options) {
} else {
spec.marks.push(bboxMark);
}

const bbox = turf.bbox(region);
const dimensions = getDimensions(spec, bbox, options);
spec.width = dimensions.width;
spec.height = dimensions.height;
const defaultDimension = options.styleConfig.region.width;
const distance = turf.distance([bbox[0], bbox[1]], [bbox[2], bbox[3]], {
units: "radians",
});
const scaleFactor = defaultDimension / distance;

let projection = "azimuthalEqualArea";
// Use albersUsa projection for usa region (wikidataId: Q30)
Expand Down Expand Up @@ -222,7 +180,7 @@ async function getRegionVegaSpec(options) {
});
spec.signals.push({
name: "scaleFactor",
value: dimensions.scaleFactor,
value: scaleFactor,
});
spec.signals.push({
name: "rotate0",
Expand Down
Loading

0 comments on commit 5af6c2c

Please sign in to comment.