Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style Spec for sky and fog #298

Merged
merged 3 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build/generate-style-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function propertyType(property) {
}
case 'light':
return 'LightSpecification';
case 'sky':
return 'SkySpecification';
case 'sources':
return '{[_: string]: SourceSpecification}';
case '*':
Expand Down Expand Up @@ -312,6 +314,8 @@ ${objectDeclaration('StyleSpecification', spec.$root)}

${objectDeclaration('LightSpecification', spec.light)}

${objectDeclaration('SkySpecification', spec.sky)}

${objectDeclaration('TerrainSpecification', spec.terrain)}

${spec.source.map(key => objectDeclaration(sourceTypeName(key), spec[key])).join('\n\n')}
Expand Down
85 changes: 85 additions & 0 deletions src/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
"intensity": 0.4
}
},
"sky": {
"type": "sky",
"doc": "The map sky.",
"example": {
"sky-color": "#199EF3"
HarelM marked this conversation as resolved.
Show resolved Hide resolved
}
},
"terrain": {
"type": "terrain",
"doc": "The terrain configuration.",
Expand Down Expand Up @@ -3859,6 +3866,84 @@
}
}
},
"sky": {
"sky-color": {
"type": "color",
"property-type": "data-constant",
"default": "#88C6FC",
"expression": {
"interpolated": true,
"parameters": [
"zoom"
]
},
"transition": true,
"doc": "Base color for sky.",
"sdk-support": {
"basic functionality": {
"js": "3.0.0"
}
}
},
"fog-color": {
"type": "color",
"property-type": "data-constant",
"default": "#ffffff",
"expression": {
"interpolated": true,
"parameters": [
"zoom"
]
},
"transition": true,
"doc": "Base color for fog.",
"sdk-support": {
"basic functionality": {
"js": "3.0.0"
}
}
},
"fog-blend": {
"type": "number",
"property-type": "data-constant",
"default": 0.5,
"minimum": 0,
"maximum": 1,
"expression": {
"interpolated": true,
"parameters": [
"zoom"
]
},
"transition": true,
"doc": "Blend fog over terrain3d. A value between 0 and 1. 0 is map center and 1 is the horizon",
"sdk-support": {
"basic functionality": {
"js": "3.0.0"
}
}
},
"horizon-blend": {
"type": "number",
"property-type": "data-constant",
"default": 0.8,
"minimum": 0,
"maximum": 1,
"expression": {
"interpolated": true,
"parameters": [
"zoom"
]
},
"transition": true,
"doc": "Blend fog and sky color at horizon. A value between 0 and 1. 0 is the horizon and 1 is map-height / 2",
"sdk-support": {
"basic functionality": {
"js": "3.0.0"
}
}
}
},
"terrain": {
"source": {
"type": "string",
Expand Down
2 changes: 2 additions & 0 deletions src/validate/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import validateFilter from './validate_filter';
import validateLayer from './validate_layer';
import validateSource from './validate_source';
import validateLight from './validate_light';
import validateSky from './validate_sky';
import validateTerrain from './validate_terrain';
import validateString from './validate_string';
import validateFormatted from './validate_formatted';
Expand All @@ -41,6 +42,7 @@ const VALIDATORS = {
'object': validateObject,
'source': validateSource,
'light': validateLight,
'sky': validateSky,
'terrain': validateTerrain,
'string': validateString,
'formatted': validateFormatted,
Expand Down
34 changes: 34 additions & 0 deletions src/validate/validate_sky.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import ValidationError from '../error/validation_error';
import getType from '../util/get_type';
import validate from './validate';

export default function validateSky(options) {
HarelM marked this conversation as resolved.
Show resolved Hide resolved
const sky = options.value;
const styleSpec = options.styleSpec;
const skySpec = styleSpec.sky;
const style = options.style;

const rootType = getType(sky);
if (sky === undefined) {
return [];
} else if (rootType !== 'object') {
return [new ValidationError('sky', sky, `object expected, ${rootType} found`)];
}

let errors = [];
for (const key in sky) {
if (skySpec[key]) {
errors = errors.concat(validate({
key,
value: sky[key],
valueSpec: skySpec[key],
style,
styleSpec
}));
} else {
errors = errors.concat([new ValidationError(key, sky[key], `unknown property "${key}"`)]);
}
}

return errors;
}
2 changes: 2 additions & 0 deletions src/validate_style.min.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import latestStyleSpec from './reference/latest';

import validateSource from './validate/validate_source';
import validateLight from './validate/validate_light';
import validateSky from './validate/validate_sky';
import validateTerrain from './validate/validate_terrain';
import validateLayer from './validate/validate_layer';
import validateFilter from './validate/validate_filter';
Expand Down Expand Up @@ -65,6 +66,7 @@ validateStyleMin.source = wrapCleanErrors(injectValidateSpec(validateSource));
validateStyleMin.sprite = wrapCleanErrors(injectValidateSpec(validateSprite));
validateStyleMin.glyphs = wrapCleanErrors(injectValidateSpec(validateGlyphsUrl));
validateStyleMin.light = wrapCleanErrors(injectValidateSpec(validateLight));
validateStyleMin.sky = wrapCleanErrors(injectValidateSpec(validateSky));
validateStyleMin.terrain = wrapCleanErrors(injectValidateSpec(validateTerrain));
validateStyleMin.layer = wrapCleanErrors(injectValidateSpec(validateLayer));
validateStyleMin.filter = wrapCleanErrors(injectValidateSpec(validateFilter));
Expand Down
1 change: 1 addition & 0 deletions src/validate_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function validateStyle(style: StyleSpecification | string | Buffe

export const source = validateStyleMin.source;
export const light = validateStyleMin.light;
export const sky = validateStyleMin.sky;
export const terrain = validateStyleMin.terrain;
export const layer = validateStyleMin.layer;
export const filter = validateStyleMin.filter;
Expand Down