) {
const {viewport} = this._context;
const mapState = new MapState(Object.assign({}, viewport, opts));
@@ -105,8 +116,12 @@ export default class NavigationControl extends BaseControl<
_renderCompass() {
const {bearing} = this._context.viewport;
- return (
-
+ const style = {transform: `rotate(${-bearing}deg)`};
+
+ return this._uiVersion === VERSION_1_6 ? (
+
+ ) : (
+
);
}
@@ -119,7 +134,7 @@ export default class NavigationControl extends BaseControl<
title={label}
onClick={callback}
>
- {children}
+ {children || }
);
}
@@ -127,6 +142,10 @@ export default class NavigationControl extends BaseControl<
_render() {
const {className, showCompass, showZoom, zoomInLabel, zoomOutLabel, compassLabel} = this.props;
+ if (!this._uiVersion) {
+ this._uiVersion = getUIVersion(this._context.map.version);
+ }
+
return (
{showZoom && this._renderButton('zoom-in', zoomInLabel, this._onZoomIn)}
diff --git a/src/utils/version.js b/src/utils/version.js
new file mode 100644
index 00000000..9e2d85b8
--- /dev/null
+++ b/src/utils/version.js
@@ -0,0 +1,25 @@
+// @flow
+
+// Helper function for version comparison
+// A version is a string in the format of "{major}.{minor}.{patch}"
+// Empty/missing version is treated as "0.0.0"
+// If version1 is smaller than version2, return -1
+// If version1 is larger than version2, return 1
+// If equal, return 0
+export function compareVersions(version1: string, version2: string): number {
+ const v1 = (version1 || '').split('.').map(Number);
+ const v2 = (version2 || '').split('.').map(Number);
+
+ for (let i = 0; i < 3; i++) {
+ const part1 = v1[i] || 0;
+ const part2 = v2[i] || 0;
+ if (part1 < part2) {
+ return -1;
+ }
+ if (part1 > part2) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/test/src/utils/index.js b/test/src/utils/index.js
index fb2ff5d1..0d9e5831 100644
--- a/test/src/utils/index.js
+++ b/test/src/utils/index.js
@@ -6,3 +6,4 @@ import './transition-manager.spec';
import './debounce.spec';
import './deep-equal.spec';
import './style-utils.spec';
+import './version.spec';
diff --git a/test/src/utils/version.spec.js b/test/src/utils/version.spec.js
new file mode 100644
index 00000000..65aa2567
--- /dev/null
+++ b/test/src/utils/version.spec.js
@@ -0,0 +1,46 @@
+import test from 'tape-catch';
+
+import {compareVersions} from 'react-map-gl/utils/version';
+
+test('compareVersions', t => {
+ const TEST_CASES = [
+ {
+ title: 'both empty',
+ version1: undefined,
+ version2: null,
+ expected: 0
+ },
+ {
+ title: 'one empty',
+ version1: undefined,
+ version2: '1.6.0',
+ expected: -1
+ },
+ {
+ title: 'major version diff',
+ version1: '0.53.1',
+ version2: '1.3.0',
+ expected: -1
+ },
+ {
+ title: 'minor version diff',
+ version1: '1.6.0',
+ version2: '1.13.0',
+ expected: -1
+ },
+ {
+ title: 'patch version diff',
+ version1: '1.6',
+ version2: '1.6.1',
+ expected: -1
+ }
+ ];
+
+ for (const testCase of TEST_CASES) {
+ t.is(compareVersions(testCase.version1, testCase.version2), testCase.expected, testCase.title);
+ // reverse order
+ t.is(compareVersions(testCase.version2, testCase.version1), -testCase.expected, testCase.title);
+ }
+
+ t.end();
+});