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

Fix transitions for *-translate properties #2771

Closed
wants to merge 2 commits into from
Closed
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: 1 addition & 3 deletions js/style/style_declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ var util = require('../util/util');
module.exports = StyleDeclaration;

function StyleDeclaration(reference, value) {
this.type = reference.type;
this.transitionable = reference.transition;
this.value = util.clone(value);
this.isFunction = MapboxGLFunction.isFunctionDefinition(value);

// immutable representation of value. used for comparison
this.json = JSON.stringify(this.value);

var parsedValue = this.type === 'color' ? parseColor(this.value) : value;
var parsedValue = reference.type === 'color' ? parseColor(this.value) : value;
this.calculate = MapboxGLFunction[reference.function || 'piecewise-constant'](parsedValue);
this.isFeatureConstant = this.calculate.isFeatureConstant;
this.isZoomConstant = this.calculate.isZoomConstant;
Expand Down
4 changes: 2 additions & 2 deletions js/style/style_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ StyleLayer.prototype = util.inherit(Evented, {
// set paint transition based on a given paint declaration
_applyPaintDeclaration: function (name, declaration, options, globalOptions, animationLoop) {
var oldTransition = options.transition ? this._paintTransitions[name] : undefined;
var spec = this._paintSpecifications[name];

if (declaration === null || declaration === undefined) {
var spec = this._paintSpecifications[name];
declaration = new StyleDeclaration(spec, spec.default);
}

Expand All @@ -305,7 +305,7 @@ StyleLayer.prototype = util.inherit(Evented, {
}, globalOptions, this.getPaintProperty(name + TRANSITION_SUFFIX));

var newTransition = this._paintTransitions[name] =
new StyleTransition(declaration, oldTransition, transitionOptions);
new StyleTransition(spec, declaration, oldTransition, transitionOptions);

if (!newTransition.instant()) {
newTransition.loopID = animationLoop.set(newTransition.endTime - Date.now());
Expand Down
7 changes: 3 additions & 4 deletions js/style/style_transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ module.exports = StyleTransition;
/*
* Represents a transition between two declarations
*/
function StyleTransition(declaration, oldTransition, value) {
function StyleTransition(reference, declaration, oldTransition, value) {

this.declaration = declaration;
this.startTime = this.endTime = (new Date()).getTime();

var type = declaration.type;
if ((type === 'string' || type === 'array') && declaration.transitionable) {
if (reference.function === 'piecewise-constant' && reference.transition) {
this.interp = interpZoomTransitioned;
} else {
this.interp = interpolate[type];
this.interp = interpolate[reference.type];
}

this.oldTransition = oldTransition;
Expand Down
60 changes: 60 additions & 0 deletions test/manual/2762.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel='stylesheet' href='../../dist/mapbox-gl.css' />
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>

<body>
<div id='map'></div>
<script src='../../dist/mapbox-gl-dev.js'></script>
<script>
var map = new mapboxgl.Map({
container: 'map',
style: {
"version": 8,
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "Point",
"coordinates": [
0,
0
]
}
}
},
"transition": {
"duration": 1000
},
"layers": [
{
"id": "circle",
"type": "circle",
"source": "geojson",
"paint": {
"circle-translate": [
-50,
-50
]
}
}
]
}
});

map.on('click', function(e) {
map.setPaintProperty("circle", "circle-color", "red");
map.setPaintProperty("circle", "circle-translate", [50, 50]);
});
</script>
</body>
</html>