mapbox / carto

fast CSS-like map stylesheets
https://cartocss.readthedocs.io/
Apache License 2.0
654 stars 129 forks source link

Can px-units be scaled? #427

Open OnkelTem opened 8 years ago

OnkelTem commented 8 years ago

Currently, it's impossible to scale sizes specified with in px-units, e.g.: text-size: 13 will be always 13 at any dpi/ppi. While this is similar to how browsers treat px-sizes (at least before retina-displays era), for maps this would mean that scaling is not possible at all.

What I suggest is to consider a change which would allow for px-scaling. A quick patch:

diff --git a/lib/carto/tree/dimension.js b/lib/carto/tree/dimension.js
index 07232f2..7d762ee 100644
--- a/lib/carto/tree/dimension.js
+++ b/lib/carto/tree/dimension.js
@@ -11,7 +11,7 @@ tree.Dimension = function Dimension(value, unit, index) {

 tree.Dimension.prototype = {
     is: 'float',
-    physical_units: ['m', 'cm', 'in', 'mm', 'pt', 'pc'],
+    physical_units: ['m', 'cm', 'in', 'mm', 'pt', 'pc', 'px'],
     screen_units: ['px', '%'],
     all_units: ['m', 'cm', 'in', 'mm', 'pt', 'pc', 'px', '%'],
     densities: {
@@ -19,7 +19,8 @@ tree.Dimension.prototype = {
         mm: 25.4,
         cm: 2.54,
         pt: 72,
-        pc: 6
+        pc: 6,
+        px: 90.714 // the same as the default ppi
     },
     ev: function (env) {
         if (this.unit && !_.contains(this.all_units, this.unit)) {

This behavior is not necessary to trigger by default, instead a command-line switch can be added.

Thoughts?

OnkelTem commented 8 years ago

Seems like this part (scaling) doesn't work properly.

For example, openstreetmap-carto's roads.mss has the code (near 3000th line):

.directions::directions {
  [zoom >= 16] {
    // intentionally omitting highway_platform, highway_construction
    [feature = 'highway_motorway'],
    [feature = 'highway_motorway_link'],
    [feature = 'highway_trunk'],
    [feature = 'highway_trunk_link'],
    [feature = 'highway_primary'],
    [feature = 'highway_primary_link'],
    [feature = 'highway_secondary'],
    [feature = 'highway_secondary_link'],
    [feature = 'highway_tertiary'],
    [feature = 'highway_tertiary_link'],
    [feature = 'highway_residential'],
    [feature = 'highway_unclassified'],
    [feature = 'highway_living_street'],
    [feature = 'highway_road'],
    [feature = 'highway_service'],
    [feature = 'highway_pedestrian'],
    [feature = 'highway_raceway'],
    [feature = 'highway_cycleway'],
    [feature = 'highway_footway'],
    [feature = 'highway_path'],
    [feature = 'highway_steps'],
    [feature = 'highway_track'],
    [feature = 'highway_bridleway'] {
      [oneway = 'yes'],
      [oneway = '-1'] {
        marker-placement: line;
        marker-spacing: 180;
        ...

and if you change 180 to 180pt (or other unit), you'll get a recursion with 46 iterations, where the value is changing with every step starting from 180.

Initial Value: 180
New value: 250

Initial Value: 250
New value: 275.59

Initial Value: 275.59
New value: 303.8

Initial Value: 303.8
New value: 334.9

Initial Value: 334.9
New value: 369.18

Initial Value: 369.18
New value: 406.97

and etc.