scale: 1
metatile: 2
name: Cartida clone for Sixdots GmbH
description: A simple map style with roads, buildings and other important features for printing
bounds: &world
  - -180
  - -85.05112877980659
  - 180
  - 85.05112877980659
center:
  - 13
  - 51
  - 12
format: png
interactivity: false
minzoom: 0
maxzoom: 22
srs: "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"

_parts:
  # Extents are used for tilemill, and don't actually make it to the generated XML
  extents: &extents
    extent: *world
    srs-name: "900913"
    srs: "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"
  osm2pgsql: &osm2pgsql
    type: "postgis"
    dbname: "gis"
    key_field: ""
    geometry_field: "way"
    extent: "-20037508,-20037508,20037508,20037508"

Stylesheet:
  - fonts.mss
  - style.mss
  - placenames.mss
  - shapefiles.mss
  - roads.mss
  - water.mss
  - buildings.mss
  - landcover.mss
Layer:
  - id: ocean-simplified
    class: ocean
    geometry: polygon
    <<: *extents
    Datasource:
      <<: *osm2pgsql
      table: |-
        (SELECT
            way
          FROM simplified_water_polygons
        ) AS simplified_water_polygons
    properties:
      maxzoom: 9
  - id: ocean
    class: ocean
    geometry: polygon
    <<: *extents
    Datasource:
      <<: *osm2pgsql
      table: |-
        (SELECT
            way
          FROM water_polygons
        ) AS water_polygons
    properties:
      minzoom: 10
  - id: forest
    geometry: polygon
    <<: *extents
    Datasource:
      <<: *osm2pgsql
      table: |-
        (SELECT
            way
          FROM planet_osm_polygon
          WHERE landuse = 'forest' OR "natural" = 'wood'
        ) AS forest
    properties:
      minzoom: 7
  - id: grass-park
    geometry: polygon
    <<: *extents
    Datasource:
      <<: *osm2pgsql
      table: |-
        (SELECT
            way
          FROM planet_osm_polygon
          WHERE landuse IN ('grass', 'meadow') OR leisure = 'park'
        ) AS grass_park
    properties:
      minzoom: 10
  - id: water-areas
    geometry: polygon
    <<: *extents
    Datasource:
      <<: *osm2pgsql
      table: |-
        (SELECT
            way,
            way_area/NULLIF(POW(!scale_denominator!*0.001*0.28,2),0) AS way_pixels
          FROM planet_osm_polygon
          WHERE
            (waterway IN ('dock', 'riverbank')
              OR landuse IN ('reservoir', 'basin')
              OR "natural" IN ('water'))
            AND building IS NULL
            AND way_area > 1*!pixel_width!::real*!pixel_height!::real
          ORDER BY way_area DESC
        ) AS water_areas
    properties:
      cache-features: true
      minzoom: 0
  - id: rivers-canals
    class: water-lines
    geometry: line
    <<: *extents
    Datasource:
      <<: *osm2pgsql
      table: |-
        (SELECT
            way,
            waterway
          FROM planet_osm_line
          WHERE
            waterway IN ('river', 'canal') AND (tunnel IS NULL OR tunnel = 'no')
        ) AS rivers_canals
    properties:
      cache-features: true
      minzoom: 8
  - id: streams-ditches-drains
    class: water-lines
    geometry: line
    <<: *extents
    Datasource:
      <<: *osm2pgsql
      table: |-
        (SELECT
            way,
            waterway
          FROM planet_osm_line
          WHERE
            waterway IN ('stream', 'drain') AND (tunnel IS NULL OR tunnel = 'no')
        ) AS streams_ditches_drains
    properties:
      cache-features: true
      minzoom: 12
#   - id: buildings
#     geometry: polygon
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             way_area/NULLIF(POW(!scale_denominator!*0.001*0.28,2),0) AS way_pixels
#           FROM planet_osm_polygon
#           WHERE building IS NOT NULL AND building != 'no'
#         ) AS buildings
#     properties:
#       minzoom: 7
#   - id: building-outline
#     geometry: polygon
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             way_area/NULLIF(POW(!scale_denominator!*0.001*0.28,2),0) AS way_pixels
#           FROM planet_osm_polygon
#           WHERE building IS NOT NULL AND building != 'no'
#         ) AS buildings
#     properties:
#       minzoom: 15
#   - id: railway-detail
#     class: railway
#     geometry: linestring
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             railway
#           FROM planet_osm_line
#           WHERE
#             (railway = 'rail' AND service IS NOT NULL)
#             OR railway IN ('tram', 'subway', 'light_rail', 'narrow_gauge', 'funicular')
#         ) as railway_detail
#     properties:
#       cache-features: true
#       minzoom: 12
#   - id: railway-main
#     class: railway
#     geometry: linestring
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             railway
#           FROM planet_osm_line
#           WHERE railway = 'rail' AND service IS NULL AND osm_id > 0
#         ) as railway_main
#     properties:
#       cache-features: true
#       minzoom: 8
#   - id: roads-low
#     class: roads
#     geometry: linestring
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             highway
#           FROM planet_osm_roads
#           WHERE highway IN ('motorway', 'trunk', 'primary') AND osm_id > 0
#         ) as roads_low
#     properties:
#       cache-features: true
#       maxzoom: 7
#   - id: roads-mid
#     class: roads
#     geometry: linestring
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             highway
#           FROM planet_osm_line
#           WHERE highway IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'primary', 'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link') AND osm_id > 0
#         ) as roads_mid
#     properties:
#       cache-features: true
#       minzoom: 8
#       maxzoom: 9
#   - id: roads-high
#     class: roads
#     geometry: linestring
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             l.highway AS highway
#           FROM planet_osm_line AS l
#           JOIN (VALUES
#               ('motorway', 1),
#               ('motorway_link', 1),
#               ('trunk', 2),
#               ('trunk_link', 2),
#               ('primary', 3),
#               ('primary_link', 3),
#               ('secondary', 4),
#               ('secondary_link', 4),
#               ('tertiary', 5),
#               ('tertiary_link', 5),
#               ('unclassified', 6),
#               ('residential', 6),
#               ('living_street', 6),
#               ('service', 6),
#               ('pedestrian', 6),
#               ('track', 6)
#             ) AS v (highway, prio)
#             ON v.highway = l.highway
#           ORDER BY v.prio DESC
#         ) as roads_high
#     properties:
#       cache-features: true
#       minzoom: 10
#   - id: roads-detail
#     class: roads
#     geometry: linestring
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             l.highway AS highway
#           FROM planet_osm_line AS l
#           WHERE highway IN ('footway', 'path', 'cycleway', 'bridleway', 'steps')
#         ) as roads_detail
#     properties:
#       cache-features: true
#       minzoom: 13
#   - id: capital-names
#     geometry: point
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             name,
#             CASE
#               WHEN (tags->'population' ~ '^[0-9]{1,8}$') THEN (tags->'population')::INTEGER ELSE 0
#             END as population,
#             round(ascii(md5(osm_id::text)) / 55) AS dir -- base direction factor on geometry to be consistent across metatiles
#           FROM planet_osm_point
#           WHERE place IN ('city', 'town', 'village', 'hamlet')
#             AND name IS NOT NULL
#             AND tags @> 'capital=>yes'
#           ORDER BY population DESC
#         ) AS capital_names
#     properties:
#       minzoom: 5
#       maxzoom: 15
#   - id: placenames-medium
#     geometry: point
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             name,
#             score,
#             CASE
#               WHEN (place = 'city') THEN 1
#               ELSE 2
#             END as category,
#             round(ascii(md5(osm_id::text)) / 55) AS dir -- base direction factor on geometry to be consistent across metatiles
#           FROM
#             (SELECT
#                 osm_id,
#                 way,
#                 place,
#                 name,
#                 (
#                   (CASE
#                     WHEN (tags->'population' ~ '^[0-9]{1,8}$') THEN (tags->'population')::INTEGER
#                     WHEN (place = 'city') THEN 100000
#                     WHEN (place = 'town') THEN 1000
#                     ELSE 1
#                   END)
#                   *
#                   (CASE
#                     WHEN (tags @> 'capital=>4') THEN 2
#                     ELSE 1
#                   END)
#                 ) AS score
#               FROM planet_osm_point
#               WHERE place IN ('city', 'town')
#                 AND name IS NOT NULL
#                 AND NOT (tags @> 'capital=>yes')
#             ) as p
#           ORDER BY score DESC, length(name) DESC, name
#         ) AS placenames_medium
#     properties:
#       cache-features: true
#       minzoom: 6
#       maxzoom: 15
#   - id: placenames-small
#     geometry: point
#     <<: *extents
#     Datasource:
#       <<: *osm2pgsql
#       table: |-
#         (SELECT
#             way,
#             place,
#             name
#           FROM planet_osm_point
#           WHERE place IN ('village', 'hamlet')
#              AND name IS NOT NULL
#              AND NOT tags @> 'capital=>yes'
#              OR (place IN ('suburb', 'quarter', 'neighbourhood', 'isolated_dwelling', 'farm')
#              ) AND name IS NOT NULL
#           ORDER BY CASE
#               WHEN place = 'suburb' THEN 7
#               WHEN place = 'village' THEN 6
#               WHEN place = 'hamlet' THEN 5
#               WHEN place = 'quarter' THEN 4
#               WHEN place = 'neighbourhood' THEN 3
#               WHEN place = 'isolated_dwelling' THEN 2
#               WHEN place = 'farm' THEN 1
#             END DESC,
#             length(name) DESC,
#             name
#         ) AS placenames_small
#     properties:
#       cache-features: true
#       minzoom: 12