Skip to content

Commit b557ccc

Browse files
authored
Update bounce.js
Checking if the marker has exceeded the maximum jump value after a period of time.
1 parent 8f942b3 commit b557ccc

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

bounce.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {
5151
let listenerKey;
5252

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

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

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

100+
98101
}
99102

100103
//Função responsável por executar a animação quadro a quadro
@@ -143,7 +146,17 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {
143146
else
144147
{
145148
//Atualiza a posição do marcador com a nova posição
146-
this.feature.getGeometry().setCoordinates([position[0], position[1], 0]);
149+
//verifica se a posição atual é maior do que a última atinginda
150+
if (this.feature.upMax != undefined && position[1] > this.feature.upMax)
151+
{
152+
//caso a nova posição ultrapasse os limites a última posição máxima é atribuída
153+
this.feature.getGeometry().setCoordinates([position[0], this.feature.upMax, 0]);
154+
}
155+
else
156+
{
157+
this.feature.getGeometry().setCoordinates([position[0], position[1], 0]);
158+
}
159+
147160
}
148161
}
149162

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

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

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

185198
var style = new ol.style.Style({
186199
image: new ol.style.Circle({
187-
radius: radius_a,
200+
radius: Math.abs(radius_a),
188201
snapToPixel: false,
189202
stroke: new ol.style.Stroke({
190203
color: 'rgba(255, 0, 0, ' + opacity_a + ')',
@@ -221,8 +234,11 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {
221234
ol.Observable.unByKey(listenerKey);
222235

223236
//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
237+
this.map.render();
238+
224239
if (this.feature._stopBouncing)
225240
{
241+
226242
this.feature.getGeometry().setCoordinates(this.feature.position.getCoordinates(), false);
227243
return;
228244
}
@@ -233,6 +249,10 @@ ol.Feature.prototype.playBouncing = function (_map, layerGroup) {
233249

234250
restart = false;
235251

252+
//atualiza com a última posição máxima atingida
253+
if (this.feature.upMax == undefined && this.feature.direction == way.up)
254+
this.feature.upMax = position[1];
255+
236256
this.feature.direction = this.feature.direction * way.down;
237257

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

0 commit comments

Comments
 (0)