-
Notifications
You must be signed in to change notification settings - Fork 38
Add fill-extrude-height, fill-extrude-base, and light root property #495
Changes from all commits
1d4e02e
277b7f3
ab5e653
ccbdf0d
40b2a36
348b476
256c1b8
b5b6be2
f317d2e
b07472a
cf1f41c
75a3cb4
139bbf2
e88937e
b814b4c
a89f6fc
bc2fc7d
d03f412
b1046f8
7bbb3e4
6f6a150
75131b5
76014c4
59d6f47
da73797
fc31ea0
12e212d
9db077c
c41f9e3
0df913b
c3a9fd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
var ValidationError = require('../error/validation_error'); | ||
var getType = require('../util/get_type'); | ||
var validate = require('./validate'); | ||
var validateTypes = { | ||
enum: require('./validate_enum'), | ||
color: require('./validate_color'), | ||
array: require('./validate_array'), | ||
number: require('./validate_number'), | ||
function: require('./validate_function') | ||
}; | ||
|
||
module.exports = function validateLight(options) { | ||
var light = options.value; | ||
var styleSpec = options.styleSpec; | ||
var lightSpec = styleSpec.$root.light; | ||
var style = options.style; | ||
|
||
var errors = []; | ||
|
||
var type; | ||
for (var key in light) { | ||
var transitionMatch = key.match(/^(.*)-transition$/); | ||
|
||
if (transitionMatch && lightSpec[transitionMatch[1]] && lightSpec[transitionMatch[1]].transition) { | ||
var baseKey = transitionMatch[1]; | ||
|
||
type = lightSpec[baseKey].type; | ||
errors = errors.concat(validate({ | ||
key: key, | ||
value: light[key], | ||
valueSpec: styleSpec.transition, | ||
style: style, | ||
styleSpec: styleSpec | ||
})); | ||
} else if (lightSpec[key]) { | ||
type = lightSpec[key].type; | ||
if (lightSpec[key].function && getType(light[key]) === 'object') type = 'function'; | ||
errors = errors.concat(validateTypes[type]({ | ||
key: key, | ||
value: light[key], | ||
valueSpec: lightSpec[key], | ||
style: style, | ||
styleSpec: styleSpec | ||
})); | ||
} else { | ||
errors = errors.concat([new ValidationError(key, light[key], 'unknown property "%s"', key)]); | ||
} | ||
} | ||
|
||
return errors; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,55 @@ | |
"doc": "Default pitch, in degrees. Zero is perpendicular to the surface, for a look straight down at the map, while a greater value like 60 looks ahead towards the horizon. The style pitch will be used only if the map has not been positioned by other means (e.g. map options or user interaction).", | ||
"example": 50 | ||
}, | ||
"light": { | ||
"anchor": { | ||
"type": "enum", | ||
"default": "viewport", | ||
"values": { | ||
"map": { | ||
"doc": "The position of the light source is aligned to the rotation of the map." | ||
}, | ||
"viewport": { | ||
"doc": "The position of the light source is aligned to the rotation of the viewport." | ||
} | ||
}, | ||
"transition": false, | ||
"doc": "Whether extruded geometries are lit relative to the map or viewport.", | ||
"example": "map" | ||
}, | ||
"position": { | ||
"type": "array", | ||
"default": [1.15, 210, 30], | ||
"length": 3, | ||
"value": "number", | ||
"transition": true, | ||
"function": "interpolated", | ||
"zoom-function": true, | ||
"property-function": false, | ||
"doc": "Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below).", | ||
"example": [1.5, 90, 80] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think our code would be more self-documenting if this were split into 3 separate properties? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe more self-documenting, but I hesitate because:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is common to express polar coordinates as a tuple as well. However, if the concern is that most developers would be unfamiliar with this convention, we could use the terms Whatever the case, I think we should be very explicit in our documentation for these properties, similar to Apple’s documentation for a similar construct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The radial coordinate doesn't have an equivalent in I'm open to improvements to this spec description, but I think we should merge this for now. |
||
}, | ||
"color": { | ||
"type": "color", | ||
"default": "#ffffff", | ||
"function": "interpolated", | ||
"zoom-function": true, | ||
"property-function": false, | ||
"transition": true, | ||
"doc": "Color tint for lighting extruded geometries." | ||
}, | ||
"intensity": { | ||
"type": "number", | ||
"default": 0.5, | ||
"minimum": 0, | ||
"maximum": 1, | ||
"function": "interpolated", | ||
"zoom-function": true, | ||
"property-function": false, | ||
"transition": true, | ||
"doc": "Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast." | ||
} | ||
}, | ||
"sources": { | ||
"required": true, | ||
"type": "sources", | ||
|
@@ -1513,7 +1562,7 @@ | |
"default": 1, | ||
"minimum": 0, | ||
"maximum": 1, | ||
"doc": "The opacity of the entire fill layer. In contrast to the `fill-color`, this value will also affect the 1px stroke around the fill, if the stroke is used.", | ||
"doc": "The opacity of the entire fill layer. In contrast to the `fill-color`, this value will also affect the 1px stroke around the fill, if the stroke is used. If a fill layer is extruded, opacity will be per-layer rather than per-feature (and will thus not support property functions).", | ||
"transition": true, | ||
"sdk-support": { | ||
"basic functionality": { | ||
|
@@ -1638,6 +1687,31 @@ | |
"android": "2.0.1" | ||
} | ||
} | ||
}, | ||
"fill-extrude-height": { | ||
"type": "number", | ||
"function": "interpolated", | ||
"zoom-function": true, | ||
"property-function": true, | ||
"default": 0, | ||
"minimum": 0, | ||
"doc": "The height with which to extrude this fill layer.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify |
||
"transition": true | ||
}, | ||
"fill-extrude-base": { | ||
"type": "number", | ||
"function": "interpolated", | ||
"zoom-function": true, | ||
"property-function": true, | ||
"default": 0, | ||
"minimum": 0, | ||
"doc": "The height with which to extrude the base of this layer.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify |
||
"transition": true, | ||
"requires": [ | ||
{ | ||
"<=": "fill-extrude-height" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
} | ||
] | ||
} | ||
}, | ||
"paint_line": { | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": 8, | ||
"sources": { | ||
"vector": { | ||
"type": "vector", | ||
"url": "mapbox://mapbox.mapbox-streets-v5" | ||
} | ||
}, | ||
"light": { | ||
"anchor": true, | ||
"position": [1, 2], | ||
"color": [255, 255, 255, 1], | ||
"intensity": 1.5 | ||
}, | ||
"layers": [] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"message": "light.anchor: expected one of [map, viewport], true found", | ||
"line": 10 | ||
}, | ||
{ | ||
"message": "light.position: array length 3 expected, length 2 found", | ||
"line": 11 | ||
}, | ||
{ | ||
"message": "light.color: color expected, array found", | ||
"line": 12 | ||
}, | ||
{ | ||
"message": "light.intensity: 1.5 is greater than the maximum value 1", | ||
"line": 13 | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify
"length": 3
.