Skip to content

Commit

Permalink
Clean up low-zoom road definitions
Browse files Browse the repository at this point in the history
This merges code for low-zoom road definitions into the corresponding
high-zoom road definitions.

Data on z<10 now comes from osm_planet_roads, data on z>=10 comes from
osm_planet_line. Chosen is for zoom level 10 as cut-off, because residential
is rendered from z10 and is not included in osm_planet_roads, so on z>=10
osm_planet_line needs to be queried anyway.

Advantages:
* This separates the zoomlevel cut-off for querying from the roads vs line
  table from the zoomlevel cut-off for the lowzoom rendering style.
* This brings related code (i.e. code per feature) closer together in the file,
  which should make the code more easy to modify.

This is mainly a code cleanup, but it causes some small changes in rendering:
* Take into account layering of roads on z10 and z11.
* Fix the loss of layering problem of railway tunnels on z12 (resolves gravitystorm#400).
* Fix bug that prevented tunnel rendering style for railway on z11/12, and add
  tunnel style rendering for spur/siding/yard for z<12.
* Give railways on z<12 a round line-join.

This is an improvement of gravitystorm#555.
  • Loading branch information
matthijsmelissen committed Feb 9, 2015
1 parent d21b052 commit 6513fc3
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 109 deletions.
2 changes: 1 addition & 1 deletion project.mml
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@
"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",
"Datasource": {
"extent": "-20037508,-20037508,20037508,20037508",
"table": " (SELECT way, COALESCE(('highway_' || (CASE WHEN substr(highway, length(highway)-3, 4) = 'link' THEN substr(highway, 0, length(highway)-4) ELSE highway end)), ('railway_' || (CASE WHEN (railway = 'rail' AND service IN ('spur', 'siding', 'yard')) THEN 'INT-spur-siding-yard' WHEN railway IN ('rail', 'tram', 'light_rail', 'funicular', 'narrow_gauge') THEN railway ELSE NULL END))) AS feature, tunnel\n FROM planet_osm_roads\n WHERE highway IS NOT NULL\n OR (railway IS NOT NULL AND railway != 'preserved' AND (service IS NULL OR service NOT IN ('spur', 'siding', 'yard')))\n ORDER BY z_order\n ) AS roads_low_zoom",
"table": " (SELECT way, COALESCE(('highway_' || (CASE WHEN substr(highway, length(highway)-3, 4) = 'link' THEN substr(highway, 0, length(highway)-4) ELSE highway end)), ('railway_' || (CASE WHEN (railway = 'rail' AND service IN ('spur', 'siding', 'yard')) THEN 'INT-spur-siding-yard' WHEN railway IN ('rail', 'tram', 'light_rail', 'funicular', 'narrow_gauge') THEN railway ELSE NULL END))) AS feature,\n CASE WHEN tunnel = 'yes' OR tunnel = 'building_passage' OR covered = 'yes' THEN 'yes' ELSE 'no' END AS int_tunnel,\n CASE WHEN substr(highway, length(highway)-3, 4) = 'link' THEN 'yes' ELSE 'no' END AS link\n FROM planet_osm_roads\n WHERE highway IS NOT NULL\n OR (railway IS NOT NULL AND railway != 'preserved' AND (service IS NULL OR service NOT IN ('spur', 'siding', 'yard')))\n ORDER BY z_order\n ) AS roads_low_zoom",
"geometry_field": "way",
"type": "postgis",
"key_field": "",
Expand Down
4 changes: 3 additions & 1 deletion project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,9 @@ Layer:
Datasource:
<<: *osm2pgsql
table: |2-
(SELECT way, COALESCE(('highway_' || (CASE WHEN substr(highway, length(highway)-3, 4) = 'link' THEN substr(highway, 0, length(highway)-4) ELSE highway end)), ('railway_' || (CASE WHEN (railway = 'rail' AND service IN ('spur', 'siding', 'yard')) THEN 'INT-spur-siding-yard' WHEN railway IN ('rail', 'tram', 'light_rail', 'funicular', 'narrow_gauge') THEN railway ELSE NULL END))) AS feature, tunnel
(SELECT way, COALESCE(('highway_' || (CASE WHEN substr(highway, length(highway)-3, 4) = 'link' THEN substr(highway, 0, length(highway)-4) ELSE highway end)), ('railway_' || (CASE WHEN (railway = 'rail' AND service IN ('spur', 'siding', 'yard')) THEN 'INT-spur-siding-yard' WHEN railway IN ('rail', 'tram', 'light_rail', 'funicular', 'narrow_gauge') THEN railway ELSE NULL END))) AS feature,
CASE WHEN tunnel = 'yes' OR tunnel = 'building_passage' OR covered = 'yes' THEN 'yes' ELSE 'no' END AS int_tunnel,
CASE WHEN substr(highway, length(highway)-3, 4) = 'link' THEN 'yes' ELSE 'no' END AS link
FROM planet_osm_roads
WHERE highway IS NOT NULL
OR (railway IS NOT NULL AND railway != 'preserved' AND (service IS NULL OR service NOT IN ('spur', 'siding', 'yard')))
Expand Down
191 changes: 84 additions & 107 deletions roads.mss
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,15 @@
}
}

.roads-fill,.bridges-fill,.tunnels-fill {
/* Data on z<10 comes from osm_planet_roads, data on z>=10 comes from
osm_planet_line. This is for performance reasons: osm_planet_roads contains less
data, and is thus faster. Chosen is for zoom level 10 as cut-off, because
residential is rendered from z10 and is not included in osm_planet_roads. */

#roads-low-zoom[zoom < 10],
.roads-fill[zoom >= 10],
.bridges-fill[zoom >= 10],
.tunnels-fill[zoom >= 10] {
::fill {
[feature = 'highway_proposed'] {
[zoom >= 13] {
Expand Down Expand Up @@ -823,6 +831,14 @@
}

[feature = 'highway_motorway'] {
[zoom >= 5] {
line-color: @motorway-fill;
line-width: 0.5;
}
[zoom >= 7] { line-width: 1; }
[zoom >= 9] { line-width: 1.4; }
[zoom >= 10] { line-width: 2; }
[zoom >= 11] { line-width: 2.5; }
[zoom >= 12] {
line-width: @motorway-width-z12 - 2 * @casing-width-z12;
[zoom >= 13] { line-width: @motorway-width-z13 - 2 * @casing-width-z13; }
Expand All @@ -834,9 +850,6 @@
[zoom >= 15] { line-width: @motorway-link-width-z15 - 2 * @casing-width-z15; }
[zoom >= 17] { line-width: @motorway-link-width-z17 - 2 * @casing-width-z17; }
}
.roads-fill, .bridges-fill {
line-color: @motorway-fill;
}
.tunnels-fill {
line-color: @motorway-tunnel-fill;
}
Expand All @@ -858,14 +871,22 @@
}

[feature = 'highway_trunk'] {
[zoom >= 5] {
line-width: 0.4;
line-color: @trunk-fill;
}
[zoom >= 7] {
line-width: 1;
line-color: @trunk-fill-alternative;
}
[zoom >= 9] { line-width: 2; }
[zoom >= 11] { line-width: 2.5; }
[zoom >= 12] {
line-color: @trunk-fill;
line-width: @trunk-width-z12 - 2 * @casing-width-z12;
[zoom >= 13] { line-width: @trunk-width-z13 - 2 * @casing-width-z13; }
[zoom >= 15] { line-width: @trunk-width-z15 - 2 * @casing-width-z15; }
[zoom >= 17] { line-width: @trunk-width-z17 - 2 * @casing-width-z17; }
.roads-fill, .bridges-fill {
line-color: @trunk-fill;
}
.tunnels-fill {
line-color: @trunk-tunnel-fill;
}
Expand All @@ -881,14 +902,18 @@
}

[feature = 'highway_primary'] {
[zoom >= 7] {
line-width: 0.5;
line-color: @primary-fill;
}
[zoom >= 9] { line-width: 1.2; }
[zoom >= 10] { line-width: 2; }
[zoom >= 11] { line-width: 2.5; }
[zoom >= 12] {
line-width: @primary-width-z12 - 2 * @casing-width-z12;
[zoom >= 13] { line-width: @primary-width-z13 - 2 * @casing-width-z13; }
[zoom >= 15] { line-width: @primary-width-z15 - 2 * @casing-width-z15; }
[zoom >= 17] { line-width: @primary-width-z17 - 2 * @casing-width-z17; }
.roads-fill, .bridges-fill {
line-color: @primary-fill;
}
.tunnels-fill {
line-color: @primary-tunnel-fill;
}
Expand All @@ -904,14 +929,16 @@
}

[feature = 'highway_secondary'] {
[zoom >= 9] {
line-width: 1;
line-color: @secondary-fill;
}
[zoom >= 11] { line-width: 2; }
[zoom >= 12] {
line-width: @secondary-width-z12 - 2 * @casing-width-z12;
[zoom >= 13] { line-width: @secondary-width-z13 - 2 * @casing-width-z13; }
[zoom >= 15] { line-width: @secondary-width-z15 - 2 * @casing-width-z15; }
[zoom >= 17] { line-width: @secondary-width-z17 - 2 * @casing-width-z17; }
.roads-fill, .bridges-fill {
line-color: @secondary-fill;
}
.tunnels-fill {
line-color: @secondary-tunnel-fill;
}
Expand All @@ -927,15 +954,17 @@
}

[feature = 'highway_tertiary'] {
[zoom >= 10] {
line-color: @residential-casing;
line-width: 1;
}
[zoom >= 12] {
line-color: @tertiary-fill;
line-width: @tertiary-width-z12 - 2 * @casing-width-z12;
[zoom >= 13] { line-width: @tertiary-width-z13 - 2 * @casing-width-z13; }
[zoom >= 14] { line-width: @tertiary-width-z14 - 2 * @casing-width-z14; }
[zoom >= 15] { line-width: @tertiary-width-z15 - 2 * @casing-width-z15; }
[zoom >= 17] { line-width: @tertiary-width-z17 - 2 * @casing-width-z17; }
.roads-fill, .bridges-fill {
line-color: @tertiary-fill;
}
.tunnels-fill {
line-color: @tertiary-tunnel-fill;
}
Expand All @@ -953,6 +982,10 @@

[feature = 'highway_residential'],
[feature = 'highway_unclassified'] {
[zoom >= 10] {
line-color: @residential-casing;
line-width: 1;
}
[zoom >= 13] {
line-width: @residential-width-z13 - 2 * @residential-casing-width-z13;
[zoom >= 14] { line-width: @residential-width-z14 - 2 * @casing-width-z14; }
Expand All @@ -977,16 +1010,11 @@
}
}

[feature = 'highway_tertiary'][zoom >= 10][zoom < 12],
[feature = 'highway_residential'][zoom >= 10][zoom < 13],
[feature = 'highway_unclassified'][zoom >= 10][zoom < 13],
[feature = 'highway_road'][zoom >= 10][zoom < 13],
[feature = 'highway_living_street'][zoom >= 12][zoom < 13] {
line-width: 1;
line-color: @residential-casing;
}

[feature = 'highway_road'] {
[zoom >= 10] {
line-color: @residential-casing;
line-width: 1;
}
[zoom >= 13] {
.roads-fill, .bridges-fill {
line-color: @road-fill;
Expand Down Expand Up @@ -1019,6 +1047,10 @@
}

[feature = 'highway_living_street'] {
[zoom >= 12] {
line-color: @residential-casing;
line-width: 1;
}
[zoom >= 13] {
line-width: @living-street-width-z13 - 2 * @casing-width-z13;
[zoom >= 14] { line-width: @living-street-width-z14 - 2 * @casing-width-z14; }
Expand Down Expand Up @@ -1362,8 +1394,23 @@
}
}

[feature = 'railway_rail'],
[feature = 'railway_INT-spur-siding-yard'] {
[feature = 'railway_rail'][zoom >= 6],
[feature = 'railway_INT-spur-siding-yard'][zoom >= 11] {
[zoom < 13] {
line-color: #aaa;
[feature = 'railway_rail'] {
line-width: 0.6;
[zoom >= 9] { line-width: 1; }
[zoom >= 10] { line-width: 2; }
}
[feature = 'railway_INT-spur-siding-yard'] {
line-width: 1;
}
line-join: round;
.roads_low_zoom[int_tunnel = 'yes'], .tunnels-fill {
line-dasharray: 5,2;
}
}
[zoom >= 13] {
.roads-fill, .bridges-fill {
dark/line-color: #999999;
Expand Down Expand Up @@ -1424,9 +1471,12 @@
[feature = 'railway_light_rail'],
[feature = 'railway_funicular'],
[feature = 'railway_narrow_gauge'] {
[zoom >= 13] {
line-width: 2;
line-color: #666;
[zoom >= 8] {
line-color: #ccc;
[zoom >= 10] { line-color: #aaa; }
[zoom >= 13] { line-color: #666; }
line-width: 1;
[zoom >= 13] { line-width: 2; }
.tunnels-fill {
line-dasharray: 5,3;
}
Expand All @@ -1444,8 +1494,10 @@
}

[feature = 'railway_tram'] {
[zoom >= 13] {
line-color: #444;
[zoom >= 8] {
line-color: #ccc;
[zoom >= 10] { line-color: #aaa; }
[zoom >= 13] { line-color: #444; }
line-width: 1;
[zoom >= 15] {
line-width: 2;
Expand Down Expand Up @@ -1925,81 +1977,6 @@
}
}

#roads-low-zoom {
[feature = 'highway_motorway'] {
[zoom >= 5][zoom < 12] {
line-width: 0.5;
line-color: @motorway-fill;
[zoom >= 7] { line-width: 1; }
[zoom >= 9] { line-width: 1.4; }
[zoom >= 10] { line-width: 2; }
[zoom >= 11] { line-width: 2.5; }
}
}

[feature = 'highway_trunk'] {
[zoom >= 5][zoom < 12] {
line-width: 0.4;
line-color: @trunk-fill;
[zoom >= 7] {
line-width: 1;
line-color: @trunk-fill-alternative;
}
[zoom >= 9] { line-width: 2; }
[zoom >= 11] { line-width: 2.5; }
}
}

[feature = 'highway_primary'] {
[zoom >= 7][zoom < 12] {
line-width: 0.5;
line-color: @primary-fill;
[zoom >= 9] { line-width: 1.2; }
[zoom >= 10] { line-width: 2; }
[zoom >= 11] { line-width: 2.5; }
}
}

[feature = 'highway_secondary'] {
[zoom >= 9][zoom < 12] {
line-width: 1;
line-color: @secondary-fill;
[zoom >= 11] { line-width: 2; }
}
}

[feature = 'railway_rail'] {
[zoom >= 6][zoom < 13] {
line-width: 0.6;
line-color: #aaa;
[zoom >= 9] { line-width: 1; }
[zoom >= 10] { line-width: 2; }
.tunnels-casing {
line-dasharray: 5,2;
}
}
}

[feature = 'railway_INT-spur-siding-yard'] {
[zoom >= 11] {
line-width: 1;
line-color: #aaa;
line-join: round;
}
}

[feature = 'railway_tram'],
[feature = 'railway_light_rail'],
[feature = 'railway_funicular'],
[feature = 'railway_narrow_gauge'] {
[zoom >= 8][zoom < 13] {
line-width: 1;
line-color: #ccc;
[zoom >= 10] { line-color: #aaa }
}
}
}

#guideways {
[zoom >= 13] {
line-width: 3;
Expand Down

0 comments on commit 6513fc3

Please sign in to comment.