@mapbox/mapbox-gl-style-spec
Advanced tools
Comparing version 8.11.0-test.0 to 8.11.0
@@ -11,2 +11,3 @@ 'use strict'; | ||
* | ||
* @private | ||
* @param {Object} style A style JSON object. | ||
@@ -13,0 +14,0 @@ * @param {Array<string>} classes An array of paint classes to apply, in order. |
@@ -34,2 +34,3 @@ 'use strict'; | ||
* | ||
* @private | ||
* @param {Array<Layer>} layers | ||
@@ -36,0 +37,0 @@ * @returns {Array<Layer>} |
38
diff.js
'use strict'; | ||
const deepEqual = require('../util/util').deepEqual; | ||
const isEqual = require('lodash.isequal'); | ||
@@ -120,3 +120,3 @@ const operations = { | ||
commands.push({ command: operations.addSource, args: [sourceId, after[sourceId]] }); | ||
} else if (!deepEqual(before[sourceId], after[sourceId])) { | ||
} else if (!isEqual(before[sourceId], after[sourceId])) { | ||
// no update command, must remove then add | ||
@@ -138,3 +138,3 @@ commands.push({ command: operations.removeSource, args: [sourceId] }); | ||
if (!before.hasOwnProperty(prop)) continue; | ||
if (!deepEqual(before[prop], after[prop])) { | ||
if (!isEqual(before[prop], after[prop])) { | ||
commands.push({ command: command, args: [layerId, prop, after[prop], klass] }); | ||
@@ -145,3 +145,3 @@ } | ||
if (!after.hasOwnProperty(prop) || before.hasOwnProperty(prop)) continue; | ||
if (!deepEqual(before[prop], after[prop])) { | ||
if (!isEqual(before[prop], after[prop])) { | ||
commands.push({ command: command, args: [layerId, prop, after[prop], klass] }); | ||
@@ -222,7 +222,7 @@ } | ||
// no need to update if previously added (new or moved) | ||
if (clean[layerId] || deepEqual(beforeLayer, afterLayer)) continue; | ||
if (clean[layerId] || isEqual(beforeLayer, afterLayer)) continue; | ||
// If source, source-layer, or type have changes, then remove the layer | ||
// and add it back 'from scratch'. | ||
if (!deepEqual(beforeLayer.source, afterLayer.source) || !deepEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !deepEqual(beforeLayer.type, afterLayer.type)) { | ||
if (!isEqual(beforeLayer.source, afterLayer.source) || !isEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !isEqual(beforeLayer.type, afterLayer.type)) { | ||
commands.push({ command: operations.removeLayer, args: [layerId] }); | ||
@@ -239,6 +239,6 @@ // we add the layer back at the same position it was already in, so | ||
diffLayerPropertyChanges(beforeLayer.paint, afterLayer.paint, commands, layerId, null, operations.setPaintProperty); | ||
if (!deepEqual(beforeLayer.filter, afterLayer.filter)) { | ||
if (!isEqual(beforeLayer.filter, afterLayer.filter)) { | ||
commands.push({ command: operations.setFilter, args: [layerId, afterLayer.filter] }); | ||
} | ||
if (!deepEqual(beforeLayer.minzoom, afterLayer.minzoom) || !deepEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) { | ||
if (!isEqual(beforeLayer.minzoom, afterLayer.minzoom) || !isEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) { | ||
commands.push({ command: operations.setLayerZoomRange, args: [layerId, afterLayer.minzoom, afterLayer.maxzoom] }); | ||
@@ -254,3 +254,3 @@ } | ||
diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), operations.setPaintProperty); | ||
} else if (!deepEqual(beforeLayer[prop], afterLayer[prop])) { | ||
} else if (!isEqual(beforeLayer[prop], afterLayer[prop])) { | ||
commands.push({ command: operations.setLayerProperty, args: [layerId, prop, afterLayer[prop]] }); | ||
@@ -265,3 +265,3 @@ } | ||
diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), operations.setPaintProperty); | ||
} else if (!deepEqual(beforeLayer[prop], afterLayer[prop])) { | ||
} else if (!isEqual(beforeLayer[prop], afterLayer[prop])) { | ||
commands.push({ command: operations.setLayerProperty, args: [layerId, prop, afterLayer[prop]] }); | ||
@@ -297,27 +297,27 @@ } | ||
// Handle changes to top-level properties | ||
if (!deepEqual(before.version, after.version)) { | ||
if (!isEqual(before.version, after.version)) { | ||
return [{ command: operations.setStyle, args: [after] }]; | ||
} | ||
if (!deepEqual(before.center, after.center)) { | ||
if (!isEqual(before.center, after.center)) { | ||
commands.push({ command: operations.setCenter, args: [after.center] }); | ||
} | ||
if (!deepEqual(before.zoom, after.zoom)) { | ||
if (!isEqual(before.zoom, after.zoom)) { | ||
commands.push({ command: operations.setZoom, args: [after.zoom] }); | ||
} | ||
if (!deepEqual(before.bearing, after.bearing)) { | ||
if (!isEqual(before.bearing, after.bearing)) { | ||
commands.push({ command: operations.setBearing, args: [after.bearing] }); | ||
} | ||
if (!deepEqual(before.pitch, after.pitch)) { | ||
if (!isEqual(before.pitch, after.pitch)) { | ||
commands.push({ command: operations.setPitch, args: [after.pitch] }); | ||
} | ||
if (!deepEqual(before.sprite, after.sprite)) { | ||
if (!isEqual(before.sprite, after.sprite)) { | ||
commands.push({ command: operations.setSprite, args: [after.sprite] }); | ||
} | ||
if (!deepEqual(before.glyphs, after.glyphs)) { | ||
if (!isEqual(before.glyphs, after.glyphs)) { | ||
commands.push({ command: operations.setGlyphs, args: [after.glyphs] }); | ||
} | ||
if (!deepEqual(before.transition, after.transition)) { | ||
if (!isEqual(before.transition, after.transition)) { | ||
commands.push({ command: operations.setTransition, args: [after.transition] }); | ||
} | ||
if (!deepEqual(before.light, after.light)) { | ||
if (!isEqual(before.light, after.light)) { | ||
commands.push({ command: operations.setLight, args: [after.light] }); | ||
@@ -324,0 +324,0 @@ } |
@@ -12,2 +12,3 @@ 'use strict'; | ||
* | ||
* @private | ||
* @param {Array} filter mapbox gl filter | ||
@@ -14,0 +15,0 @@ * @returns {Function} filter-evaluating function |
@@ -31,2 +31,3 @@ 'use strict'; | ||
* | ||
* @private | ||
* @param {Object} style a Mapbox GL Style | ||
@@ -33,0 +34,0 @@ * @param {number} [space] space argument to pass to `JSON.stringify` |
@@ -23,4 +23,3 @@ 'use strict'; | ||
const zoomDependent = zoomAndFeatureDependent || !featureDependent; | ||
const inputType = parameters.stops && typeof (zoomAndFeatureDependent ? parameters.stops[0][0].property : parameters.stops[0][0]); | ||
const type = parameters.type || defaultType || (inputType === 'string' ? 'categorical' : 'exponential'); | ||
const type = parameters.type || defaultType || 'exponential'; | ||
@@ -67,3 +66,3 @@ let innerFun; | ||
// For categorical functions, generate an Object as a hashmap of the stops for fast searching | ||
const hashedStops = {}; | ||
const hashedStops = Object.create(null); | ||
if (innerFun === evaluateCategoricalFunction) { | ||
@@ -107,3 +106,5 @@ for (let i = 0; i < parameters.stops.length; i++) { | ||
return outputFunction(innerFun(parameters, zoom, hashedStops)); | ||
} else return outputFunction(innerFun(parameters, zoom)); | ||
} else { | ||
return outputFunction(innerFun(parameters, zoom)); | ||
} | ||
}; | ||
@@ -116,4 +117,5 @@ fun.isFeatureConstant = true; | ||
return outputFunction(innerFun(parameters, feature[parameters.property], hashedStops)); | ||
} else return outputFunction( | ||
innerFun(parameters, feature[parameters.property])); | ||
} else { | ||
return outputFunction(innerFun(parameters, feature[parameters.property])); | ||
} | ||
}; | ||
@@ -120,0 +122,0 @@ fun.isFeatureConstant = false; |
@@ -24,2 +24,3 @@ 'use strict'; | ||
* | ||
* @private | ||
* @param {Array<Layer>} layers | ||
@@ -26,0 +27,0 @@ * @returns {Array<Array<Layer>>} |
@@ -6,2 +6,3 @@ 'use strict'; | ||
* | ||
* @private | ||
* @alias migrate | ||
@@ -8,0 +9,0 @@ * @param {object} style a Mapbox GL Style |
{ | ||
"name": "@mapbox/mapbox-gl-style-spec", | ||
"description": "a specification for mapbox gl styles", | ||
"version": "8.11.0-test.0", | ||
"version": "8.11.0", | ||
"author": "Mapbox", | ||
"bin": { | ||
"gl-style-migrate": "bin/gl-style-migrate", | ||
"gl-style-validate": "bin/gl-style-validate", | ||
"gl-style-format": "bin/gl-style-format", | ||
"gl-style-composite": "bin/gl-style-composite" | ||
"keywords": [ | ||
"mapbox", | ||
"mapbox-gl", | ||
"mapbox-gl-js" | ||
], | ||
"license": "ISC", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:mapbox/mapbox-gl-style-spec.git" | ||
}, | ||
"bin": { | ||
"gl-style-migrate": "bin/gl-style-migrate", | ||
"gl-style-validate": "bin/gl-style-validate", | ||
"gl-style-format": "bin/gl-style-format", | ||
"gl-style-composite": "bin/gl-style-composite" | ||
}, | ||
@@ -18,16 +29,4 @@ "dependencies": { | ||
"minimist": "0.0.8", | ||
"rw": "^0.1.4", | ||
"sort-object": "^0.3.2" | ||
}, | ||
"keywords": [ | ||
"mapbox", | ||
"mapbox-gl", | ||
"mapbox-gl-js" | ||
], | ||
"license": "ISC", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:mapbox/mapbox-gl-js.git" | ||
} | ||
} |
@@ -1,29 +0,21 @@ | ||
# Mapbox GL Spec & Lint | ||
# Mapbox GL style specification & utilities | ||
[![Circle CI](https://circleci.com/gh/mapbox/mapbox-gl-style-spec.svg?style=svg)](https://circleci.com/gh/mapbox/mapbox-gl-style-spec) | ||
This directory contains code and reference files that define the Mapbox GL style specification and provides some utilities for working with Mapbox styles. | ||
GL style spec, validation, and migration scripts for [mapbox-gl-js](https://github.com/mapbox/mapbox-gl-js) and | ||
[mapbox-gl-native](https://github.com/mapbox/mapbox-gl-native). | ||
## npm package | ||
### Install | ||
The Mapbox GL style specification and utilities are published as a seperate npm | ||
package so that they can be installed without the bulk of GL JS. | ||
npm install -g mapbox-gl-style-spec | ||
npm install @mapbox/mapbox-gl-style-spec | ||
Provides the utilities: | ||
## CLI Tools | ||
* `gl-style-migrate` | ||
* `gl-style-format` | ||
* `gl-style-validate` | ||
If you install this package globally, you will have access to several CLI tools. | ||
### Validation | ||
npm install @mapbox/mapbox-gl-style-spec --global | ||
```bash | ||
$ gl-style-validate style.json | ||
``` | ||
Will validate the given style JSON and print errors to stdout. Provide a | ||
`--json` flag to get JSON output. | ||
### `gl-style-migrate` | ||
### Migrations | ||
This repo contains scripts for migrating GL styles of any version to the latest version | ||
@@ -43,30 +35,17 @@ (currently v8). Migrate a style like this: | ||
### [API](API.md) | ||
### `gl-style-format` | ||
## Tests | ||
```bash | ||
$ gl-style-format style.json | ||
``` | ||
To run tests: | ||
Will format the given style JSON to use standard indentation and sorted object keys. | ||
npm install | ||
npm test | ||
### `gl-style-validate` | ||
To update test fixtures | ||
UPDATE=true npm test | ||
### Documentation | ||
* The utility reference page [API.md](API.md) is generated automatically from inline source documentation. | ||
* The style reference page exists here: `docs/_generate/index.html` and can be edited directly. | ||
To view the documentation, run | ||
```bash | ||
npm start | ||
$ gl-style-validate style.json | ||
``` | ||
and open the served page | ||
```bash | ||
open http://127.0.0.1:4000/mapbox-gl-style-spec | ||
``` | ||
Will validate the given style JSON and print errors to stdout. Provide a | ||
`--json` flag to get JSON output. |
@@ -10,2 +10,3 @@ 'use strict'; | ||
* | ||
* @private | ||
* @alias validate | ||
@@ -12,0 +13,0 @@ * @param {Object|String|Buffer} style The style to be validated. If a `String` |
@@ -14,2 +14,3 @@ 'use strict'; | ||
* | ||
* @private | ||
* @param {Object} style The style to be validated. | ||
@@ -16,0 +17,0 @@ * @param {Object} [styleSpec] The style specification to validate against. |
@@ -53,4 +53,2 @@ 'use strict'; | ||
errors.push(new ValidationError(`${key}[1]`, value[1], 'string expected, %s found', type)); | ||
} else if (value[1][0] === '@') { | ||
errors.push(new ValidationError(`${key}[1]`, value[1], 'filter key cannot be a constant')); | ||
} | ||
@@ -68,4 +66,2 @@ } | ||
})); | ||
} else if (type === 'string' && value[i][0] === '@') { | ||
errors.push(new ValidationError(`${key}[${i}]`, value[i], 'filter value cannot be a constant')); | ||
} else if (type !== 'string' && type !== 'number' && type !== 'boolean') { | ||
@@ -97,4 +93,2 @@ errors.push(new ValidationError(`${key}[${i}]`, value[i], 'string, number, or boolean expected, %s found', type)); | ||
errors.push(new ValidationError(`${key}[1]`, value[1], 'string expected, %s found', type)); | ||
} else if (value[1][0] === '@') { | ||
errors.push(new ValidationError(`${key}[1]`, value[1], 'filter key cannot be a constant')); | ||
} | ||
@@ -101,0 +95,0 @@ break; |
@@ -13,3 +13,3 @@ 'use strict'; | ||
const functionValueSpec = options.valueSpec; | ||
let functionType = unbundle(options.value.type); | ||
const functionType = unbundle(options.value.type); | ||
let stopKeyType; | ||
@@ -153,5 +153,2 @@ const stopDomainValues = {}; | ||
stopKeyType = type; | ||
if (!functionType && type === 'string') { | ||
functionType = 'categorical'; | ||
} | ||
} else if (type !== stopKeyType) { | ||
@@ -166,3 +163,7 @@ return [new ValidationError(options.key, options.value, '%s stop domain type must match previous stop domain type %s', type, stopKeyType)]; | ||
if (type !== 'number' && functionType !== 'categorical') { | ||
return [new ValidationError(options.key, options.value, 'number expected, %s found', type)]; | ||
let message = 'number expected, %s found'; | ||
if (functionValueSpec['property-function'] && functionType === undefined) { | ||
message += '\nIf you intended to use a categorical function, specify `"type": "categorical"`.'; | ||
} | ||
return [new ValidationError(options.key, options.value, message, type)]; | ||
} | ||
@@ -169,0 +170,0 @@ |
'use strict'; | ||
const validate = require('./validate'); | ||
const ValidationError = require('../error/validation_error'); | ||
const validateProperty = require('./validate_property'); | ||
module.exports = function validateLayoutProperty(options) { | ||
const key = options.key; | ||
const style = options.style; | ||
const styleSpec = options.styleSpec; | ||
const value = options.value; | ||
const propertyKey = options.objectKey; | ||
const layerSpec = styleSpec[`layout_${options.layerType}`]; | ||
if (!layerSpec) return []; | ||
if (options.valueSpec || layerSpec[propertyKey]) { | ||
const errors = []; | ||
if (options.layerType === 'symbol') { | ||
if (propertyKey === 'icon-image' && style && !style.sprite) { | ||
errors.push(new ValidationError(key, value, 'use of "icon-image" requires a style "sprite" property')); | ||
} else if (propertyKey === 'text-field' && style && !style.glyphs) { | ||
errors.push(new ValidationError(key, value, 'use of "text-field" requires a style "glyphs" property')); | ||
} | ||
} | ||
return errors.concat(validate({ | ||
key: options.key, | ||
value: value, | ||
valueSpec: options.valueSpec || layerSpec[propertyKey], | ||
style: style, | ||
styleSpec: styleSpec | ||
})); | ||
} else { | ||
return [new ValidationError(key, value, 'unknown property "%s"', propertyKey)]; | ||
} | ||
return validateProperty(options, 'layout'); | ||
}; |
'use strict'; | ||
const validate = require('./validate'); | ||
const ValidationError = require('../error/validation_error'); | ||
const validateProperty = require('./validate_property'); | ||
module.exports = function validatePaintProperty(options) { | ||
const key = options.key; | ||
const style = options.style; | ||
const styleSpec = options.styleSpec; | ||
const value = options.value; | ||
const propertyKey = options.objectKey; | ||
const layerSpec = styleSpec[`paint_${options.layerType}`]; | ||
if (!layerSpec) return []; | ||
const transitionMatch = propertyKey.match(/^(.*)-transition$/); | ||
if (transitionMatch && layerSpec[transitionMatch[1]] && layerSpec[transitionMatch[1]].transition) { | ||
return validate({ | ||
key: key, | ||
value: value, | ||
valueSpec: styleSpec.transition, | ||
style: style, | ||
styleSpec: styleSpec | ||
}); | ||
} else if (options.valueSpec || layerSpec[propertyKey]) { | ||
return validate({ | ||
key: options.key, | ||
value: value, | ||
valueSpec: options.valueSpec || layerSpec[propertyKey], | ||
style: style, | ||
styleSpec: styleSpec | ||
}); | ||
} else { | ||
return [new ValidationError(key, value, 'unknown property "%s"', propertyKey)]; | ||
} | ||
return validateProperty(options, 'paint'); | ||
}; |
@@ -67,2 +67,11 @@ 'use strict'; | ||
case 'canvas': | ||
return validateObject({ | ||
key: key, | ||
value: value, | ||
valueSpec: styleSpec.source_canvas, | ||
style: style, | ||
styleSpec: styleSpec | ||
}); | ||
default: | ||
@@ -72,3 +81,3 @@ return validateEnum({ | ||
value: value.type, | ||
valueSpec: {values: ['vector', 'raster', 'geojson', 'video', 'image']}, | ||
valueSpec: {values: ['vector', 'raster', 'geojson', 'video', 'image', 'canvas']}, | ||
style: style, | ||
@@ -75,0 +84,0 @@ styleSpec: styleSpec |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6
7615
1
242479
51