-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucas Wojciechowski
committed
Jan 14, 2016
1 parent
c1d8e06
commit 263def1
Showing
10 changed files
with
173 additions
and
82 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
var parseCSSColor = require('csscolorparser').parseCSSColor; | ||
var util = require('../util/util'); | ||
|
||
var colorCache = {}; | ||
|
||
function parseColor(input) { | ||
|
||
if (colorCache[input]) { | ||
return colorCache[input]; | ||
|
||
// RGBA array | ||
} else if (Array.isArray(input)) { | ||
return input; | ||
|
||
// style function | ||
} else if (input && input.range) { | ||
return util.extend({}, input, { | ||
range: input.range.map(parseColor) | ||
}); | ||
|
||
// legacy style function | ||
} else if (input && input.stops) { | ||
return util.extend({}, input, { | ||
stops: input.stops.map(function(step) { | ||
return [step[0], parseColor(step[1])]; | ||
}) | ||
}); | ||
|
||
// Color string | ||
} else if (typeof input === 'string') { | ||
var output = colorDowngrade(parseCSSColor(input)); | ||
colorCache[input] = output; | ||
return output; | ||
|
||
} else { | ||
throw new Error('Invalid color ' + input); | ||
} | ||
|
||
} | ||
|
||
function colorDowngrade(color) { | ||
return [color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 1]; | ||
} | ||
|
||
module.exports = parseColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
var createStyleFunction = require('mapbox-gl-function'); | ||
|
||
function createBackwardsCompatibleStyleFunction(reference, parameters) { | ||
if (parameters.stops) { | ||
var domain = []; | ||
var range = []; | ||
|
||
for (var i = 0; i < parameters.stops.length; i++) { | ||
domain.push(parameters.stops[i][0]); | ||
range.push(parameters.stops[i][1]); | ||
} | ||
|
||
parameters.domain = domain; | ||
parameters.range = range; | ||
delete parameters.stops; | ||
|
||
if (reference.function === 'interpolated') { | ||
parameters.type = 'exponential'; | ||
} else { | ||
parameters.domain.shift(); | ||
parameters.type = 'interval'; | ||
} | ||
} | ||
|
||
var fun = createStyleFunction(parameters); | ||
return function(zoom) { | ||
return fun({$zoom: zoom}, {}); | ||
}; | ||
} | ||
|
||
module.exports = { | ||
create: createStyleFunction, | ||
createBackwardsCompatible: createBackwardsCompatibleStyleFunction | ||
}; |