@maptalks/function-type
Advanced tools
+37
-5
@@ -0,1 +1,8 @@ | ||
| import { ColorIn } from 'colorin'; | ||
| var isMapSupported = typeof Map === 'function'; | ||
| var colorInCache; | ||
| if (isMapSupported) { | ||
| colorInCache = new Map(); | ||
| } | ||
| /*eslint-disable no-var, prefer-const*/ | ||
@@ -25,2 +32,4 @@ function createFunction(parameters, defaultType) { | ||
| innerFun = evaluateIdentityFunction; | ||
| } else if (type === 'color-interpolate') { | ||
| innerFun = evaluateColorInterpolateFunction; | ||
| } else { | ||
@@ -128,2 +137,27 @@ throw new Error('Unknown function type "' + type + '"'); | ||
| } | ||
| const COLORIN_OPTIONS = { | ||
| width: 100, | ||
| height: 1 | ||
| }; | ||
| function evaluateColorInterpolateFunction(parameters, input) { | ||
| const stops = parameters.stops; | ||
| if (stops && stops.length > 1) { | ||
| let colorIn; | ||
| if (colorInCache) { | ||
| const key = JSON.stringify(stops); | ||
| if (!colorInCache.has(key)) { | ||
| const colorIn = new ColorIn(stops, COLORIN_OPTIONS); | ||
| colorInCache.set(key, colorIn); | ||
| } | ||
| colorIn = colorInCache.get(key); | ||
| } else { | ||
| colorIn = new ColorIn(stops, COLORIN_OPTIONS); | ||
| } | ||
| const [r, g, b, a] = colorIn.getColor(input); | ||
| return [r / 255, g / 255, b / 255, a / 255]; | ||
| } else if (stops && stops.length === 1) { | ||
| return stops[0][1]; | ||
| } | ||
| return null; | ||
| } | ||
@@ -149,3 +183,3 @@ function evaluateIdentityFunction(parameters, input) { | ||
| function interpolateNumber(input, base, inputLower, inputUpper, outputLower, outputUpper) { | ||
| var difference = inputUpper - inputLower; | ||
| var difference = inputUpper - inputLower; | ||
| var progress = input - inputLower; | ||
@@ -230,5 +264,3 @@ | ||
| } | ||
| var result = { | ||
| '__fn_types_loaded' : true | ||
| }, | ||
| var result = { '__fn_types_loaded': true }, | ||
| props = [], | ||
@@ -305,3 +337,3 @@ p; | ||
| } | ||
| } | ||
| } | ||
| } | ||
@@ -308,0 +340,0 @@ const fn = createFunction(parameters, defaultType); |
+5
-2
| { | ||
| "name": "@maptalks/function-type", | ||
| "version": "1.2.3", | ||
| "version": "1.3.0", | ||
| "main": "./index.js", | ||
| "module": "./index.js", | ||
| "description": "function type support for maptalks", | ||
| "dependencies": {}, | ||
| "dependencies": { | ||
| "colorin": "^0.4.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@napi-rs/canvas": "^0.1.30", | ||
| "eslint": "^5.0.1", | ||
@@ -10,0 +13,0 @@ "eslint-config-maptalks": "^0.2.1", |
15065
8.33%309
11.15%1
Infinity%7
16.67%+ Added
+ Added