2016-05-27 18:19:47 +08:00
|
|
|
-- Maximum supported zoom level
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@._CDB_MaxSupportedZoom()
|
2016-05-27 18:19:47 +08:00
|
|
|
RETURNS int
|
|
|
|
LANGUAGE SQL
|
2017-10-24 20:16:56 +08:00
|
|
|
IMMUTABLE PARALLEL SAFE
|
2016-05-27 18:19:47 +08:00
|
|
|
AS $$
|
|
|
|
-- The maximum zoom level has to be limited for various reasons,
|
|
|
|
-- e.g. zoom levels greater than 31 would require tile coordinates
|
|
|
|
-- that would not fit in an INTEGER (which is signed, 32 bits long).
|
|
|
|
-- We'll choose 20 as a limit which is safe also when the JavaScript shift
|
|
|
|
-- operator (<<) is used for computing powers of two.
|
|
|
|
SELECT 29;
|
|
|
|
$$;
|
|
|
|
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_ZoomFromScale(scaleDenominator numeric)
|
2016-02-09 14:45:27 +08:00
|
|
|
RETURNS int
|
|
|
|
LANGUAGE SQL
|
2017-10-24 20:16:56 +08:00
|
|
|
IMMUTABLE PARALLEL SAFE
|
2016-02-09 14:45:27 +08:00
|
|
|
AS $$
|
2016-05-27 21:10:20 +08:00
|
|
|
SELECT
|
|
|
|
CASE
|
|
|
|
WHEN scaleDenominator > 600000000 THEN
|
|
|
|
-- Scale is smaller than zoom level 0
|
|
|
|
NULL
|
|
|
|
WHEN scaleDenominator = 0 THEN
|
|
|
|
-- Actual zoom level would be infinite
|
2019-05-31 21:29:28 +08:00
|
|
|
@extschema@._CDB_MaxSupportedZoom()
|
2016-05-27 21:10:20 +08:00
|
|
|
ELSE
|
|
|
|
CAST (
|
|
|
|
LEAST(
|
|
|
|
ROUND(LOG(2, 559082264.028/scaleDenominator)),
|
2019-05-31 21:29:28 +08:00
|
|
|
@extschema@._CDB_MaxSupportedZoom()
|
2016-05-27 21:10:20 +08:00
|
|
|
)
|
|
|
|
AS INTEGER)
|
|
|
|
END;
|
2016-02-09 14:45:27 +08:00
|
|
|
$$;
|