From 3e2fbcee2000bb27b4cd863c2c52acf05a4ae8c6 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 27 Sep 2020 21:00:37 +0200 Subject: [PATCH] Add retina detection --- State.ts | 3 ++- UI/SimpleAddUI.ts | 2 +- Utils.ts | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/State.ts b/State.ts index 06509e2..0c5d205 100644 --- a/State.ts +++ b/State.ts @@ -34,7 +34,8 @@ export class State { tagsVisibleAndWikiLinked: 150, themeGeneratorReadOnlyUnlock: 200, themeGeneratorFullUnlock: 500, - addNewPointWithUnreadMessagesUnlock: 500 + addNewPointWithUnreadMessagesUnlock: 500, + minZoomLevelToAddNewPoints: (Utils.isRetina() ? 18 : 19) }; public static runningFromConsole: boolean = false; diff --git a/UI/SimpleAddUI.ts b/UI/SimpleAddUI.ts index 28163c6..0db31ca 100644 --- a/UI/SimpleAddUI.ts +++ b/UI/SimpleAddUI.ts @@ -204,7 +204,7 @@ export class SimpleAddUI extends UIElement { ""]).Render(); } - if (State.state.locationControl.data.zoom < 19) { + if (State.state.locationControl.data.zoom < State.userJourney.minZoomLevelToAddNewPoints) { return new Combine([header, Translations.t.general.add.zoomInFurther]).Render() } diff --git a/Utils.ts b/Utils.ts index f173a16..583cd30 100644 --- a/Utils.ts +++ b/Utils.ts @@ -97,4 +97,10 @@ export class Utils { return [a.substr(0, index), a.substr(index+sep.length)]; } + public static isRetina() : boolean{ + // The cause for this line of code: https://github.com/pietervdvn/MapComplete/issues/115 + // See https://stackoverflow.com/questions/19689715/what-is-the-best-way-to-detect-retina-support-on-a-device-using-javascript + return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min--moz-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)').matches)) || (window.devicePixelRatio && window.devicePixelRatio >= 2)); + } + }