diff --git a/schema/layers/country.sql b/schema/layers/country.sql index a80e503f..41e2d39d 100644 --- a/schema/layers/country.sql +++ b/schema/layers/country.sql @@ -9,14 +9,18 @@ CREATE TABLE IF NOT EXISTS country_label AS ( ); CREATE INDEX IF NOT EXISTS country_label_geom_idx ON country_label USING gist(geom); -CREATE OR REPLACE VIEW country_z1 AS ( +CREATE OR REPLACE VIEW country_z0 AS ( SELECT * FROM country_label WHERE scalerank = 0 AND is_tiny = 0 AND labelrank <= 2 ); -CREATE OR REPLACE VIEW country_z2 AS ( +CREATE OR REPLACE VIEW country_z1 AS ( SELECT * FROM country_label WHERE scalerank = 0 AND is_tiny = 0 AND labelrank <= 3 ); +CREATE OR REPLACE VIEW country_z2 AS ( + SELECT * FROM country_label WHERE scalerank = 0 AND is_tiny = 0 AND labelrank <= 4 +); + CREATE OR REPLACE VIEW country_z3 AS ( SELECT * FROM country_label WHERE scalerank = 0 AND is_tiny = 0 ); @@ -28,6 +32,9 @@ CREATE OR REPLACE VIEW country_z5 AS ( CREATE OR REPLACE FUNCTION layer_country(bbox geometry, zoom_level int) RETURNS TABLE(geom geometry, name text, abbrev text, postal text, scalerank int, labelrank int) AS $$ SELECT geom, name, abbrev, postal, scalerank::int, labelrank::int FROM ( + SELECT * FROM country_z0 + WHERE zoom_level = 0 + UNION ALL SELECT * FROM country_z1 WHERE zoom_level = 1 UNION ALL @@ -41,5 +48,5 @@ RETURNS TABLE(geom geometry, name text, abbrev text, postal text, scalerank int, WHERE zoom_level >= 5 ) AS t WHERE geom && bbox - ORDER BY scalerank, labelrank, length(name); + ORDER BY scalerank ASC, labelrank ASC, length(name) ASC; $$ LANGUAGE SQL IMMUTABLE;