Skip to content

Commit

Permalink
Update bounce.js
Browse files Browse the repository at this point in the history
Checking if the marker has exceeded the maximum jump value after a period of time.
  • Loading branch information
jefferson authored Mar 8, 2018
1 parent 8f942b3 commit b557ccc
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions bounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {
let listenerKey;

//Direção do marcador
//para cima os valores são negativos
//para baixo os valores são positivos
let way = { up: 1, down: -1 };

//Momento em que a animação começou
Expand Down Expand Up @@ -95,6 +97,7 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {

listenerKey = _map.on('postcompose', Animate, { feature: this, map: _map });


}

//Função responsável por executar a animação quadro a quadro
Expand Down Expand Up @@ -143,7 +146,17 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {
else
{
//Atualiza a posição do marcador com a nova posição
this.feature.getGeometry().setCoordinates([position[0], position[1], 0]);
//verifica se a posição atual é maior do que a última atinginda
if (this.feature.upMax != undefined && position[1] > this.feature.upMax)
{
//caso a nova posição ultrapasse os limites a última posição máxima é atribuída
this.feature.getGeometry().setCoordinates([position[0], this.feature.upMax, 0]);
}
else
{
this.feature.getGeometry().setCoordinates([position[0], position[1], 0]);
}

}
}

Expand All @@ -162,7 +175,7 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {

var styleb = new ol.style.Style({
image: new ol.style.Circle({
radius: radius_b,
radius: Math.abs(radius_b),
snapToPixel: false,
stroke: new ol.style.Stroke({
color: 'rgba(255, 0, 0, ' + opacity_b + ')',
Expand All @@ -173,7 +186,7 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {

var stylec = new ol.style.Style({
image: new ol.style.Circle({
radius: radius_c,
radius: Math.abs(radius_c),
snapToPixel: false,
stroke: new ol.style.Stroke({
color: 'rgba(255, 0, 0, ' + opacity_c + ')',
Expand All @@ -184,7 +197,7 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {

var style = new ol.style.Style({
image: new ol.style.Circle({
radius: radius_a,
radius: Math.abs(radius_a),
snapToPixel: false,
stroke: new ol.style.Stroke({
color: 'rgba(255, 0, 0, ' + opacity_a + ')',
Expand Down Expand Up @@ -221,8 +234,11 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {
ol.Observable.unByKey(listenerKey);

//Caso a animação esteja no estado parado a animação não irá ocorrer novamente e o marcador volta para a posição inicial
this.map.render();

if (this.feature._stopBouncing)
{

this.feature.getGeometry().setCoordinates(this.feature.position.getCoordinates(), false);
return;
}
Expand All @@ -233,6 +249,10 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {

restart = false;

//atualiza com a última posição máxima atingida
if (this.feature.upMax == undefined && this.feature.direction == way.up)
this.feature.upMax = position[1];

this.feature.direction = this.feature.direction * way.down;

//Solicita uma nova animação e adiciona a referência novamente para o listener
Expand Down

0 comments on commit b557ccc

Please sign in to comment.