From 2a30eb2fd3be4b0ae72ed4ea43ab4716fdca1ad8 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 27 May 2016 15:10:20 +0200 Subject: [PATCH] Fix zoom from scale condition for NULL result And rewrite in cleaner form. --- scripts-available/CDB_ZoomFromScale.sql | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts-available/CDB_ZoomFromScale.sql b/scripts-available/CDB_ZoomFromScale.sql index faa54b7..6ef00d1 100644 --- a/scripts-available/CDB_ZoomFromScale.sql +++ b/scripts-available/CDB_ZoomFromScale.sql @@ -17,11 +17,20 @@ RETURNS int LANGUAGE SQL IMMUTABLE AS $$ -SELECT - CASE - -- Don't bother if the scale is larger than ~zoom level 0 - WHEN scaleDenominator > 600000000 OR scaleDenominator = 0 THEN NULL - WHEN scaleDenominator = 0 THEN _CDB_MaxSupportedZoom() - ELSE CAST (LEAST(ROUND(LOG(2, 559082264.028/scaleDenominator)), _CDB_MaxSupportedZoom()) AS INTEGER) - END; + SELECT + CASE + WHEN scaleDenominator > 600000000 THEN + -- Scale is smaller than zoom level 0 + NULL + WHEN scaleDenominator = 0 THEN + -- Actual zoom level would be infinite + _CDB_MaxSupportedZoom() + ELSE + CAST ( + LEAST( + ROUND(LOG(2, 559082264.028/scaleDenominator)), + _CDB_MaxSupportedZoom() + ) + AS INTEGER) + END; $$;