diff --git a/README.md b/README.md index fe49bf0..987f37b 100644 --- a/README.md +++ b/README.md @@ -148,3 +148,5 @@ Copyright (c) 2018 Norbert Renner and [contributors](https://github.com/nrenner/ Copyright (c) 2012 davidshimjs [The MIT License](https://github.com/llyys/qrcodejs/blob/master/LICENSE) - [Bootstrap Icons](https://github.com/twbs/icons) Copyright (c) 2019-2023 The Bootstrap Authors [The MIT License](https://github.com/twbs/icons/blob/main/LICENSE) +- [compare-versions](https://github.com/omichelsen/compare-versions) + Copyright (c) 2015-2021 Ole Michelsen [The MIT License](https://github.com/omichelsen/compare-versions/blob/main/LICENSE) diff --git a/js/router/BRouter.js b/js/router/BRouter.js index 7b191f4..ccdf2be 100644 --- a/js/router/BRouter.js +++ b/js/router/BRouter.js @@ -10,6 +10,7 @@ L.BRouter = L.Class.extend({ GROUP_SEPARATOR: '|', ABORTED_ERROR: 'aborted', CUSTOM_PREFIX: 'custom_', + SUPPORTED_BROUTER_VERSIONS: '< 1.7.0 || >=1.7.2', // compatibility string should be in npm package versioning format isCustomProfile: function (profileName) { return profileName && profileName.substring(0, 7) === L.BRouter.CUSTOM_PREFIX; }, @@ -178,6 +179,7 @@ L.BRouter = L.Class.extend({ try { geojson = JSON.parse(xhr.responseText); layer = this._assignFeatures(L.geoJSON(geojson).getLayers()[0]); + this.checkBRouterVersion(layer.feature.properties.creator); return cb(null, layer); } catch (e) { @@ -189,6 +191,31 @@ L.BRouter = L.Class.extend({ } }, + versionCheckDone: false, + checkBRouterVersion: function (creator) { + if (this.versionCheckDone) { + return; + } + this.versionCheckDone = true; + + try { + const actualBRouterVersion = creator.replace(/^BRouter-/, ''); + if (!compareVersions.satisfies(actualBRouterVersion, L.BRouter.SUPPORTED_BROUTER_VERSIONS)) { + console.warn( + 'BRouter-Web ' + + BR.version + + ' requires BRouter versions ' + + L.BRouter.SUPPORTED_BROUTER_VERSIONS + + ', but only ' + + creator + + ' was found.' + ); + } + } catch (e) { + console.error(e); + } + }, + getRouteSegment: function (l1, l2, cb) { this.queue.push({ segment: [l1, l2] }, cb); }, diff --git a/package.json b/package.json index f61a047..2383ab6 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "bootstrap-select": "1.13.18", "bootstrap-slider": "11.0.2", "codemirror": "5.65.13", + "compare-versions": "^6.0.0", "core-js-bundle": "3.29.1", "datatables": "1.10.18", "fit-file-writer": "tbsmark86/fit-file-writer#3eebe13", @@ -309,6 +310,11 @@ "index.js" ] }, + "compare-versions": { + "main": [ + "lib/umd/index.js" + ] + }, "@mapbox/maki": { "main": [ "icons/art-gallery.svg", diff --git a/yarn.lock b/yarn.lock index 564d8f6..13d0316 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4197,6 +4197,11 @@ commander@^9.0.0: resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== +compare-versions@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-6.0.0.tgz#a3edb527e4487bfab9a8b62ffe70cebc9b87675b" + integrity sha512-s2MzYxfRsE9f/ow8hjn7ysa7pod1xhHdQMsgiJtKx6XSNf4x2N1KG4fjrkUmXcP/e9Y2ZX4zB6sHIso0Lm6evQ== + component-emitter@^1.2.1: version "1.3.0" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"