deck.gl + tripslayer without react.js











up vote
2
down vote

favorite












How can I enable animation of TripsLayer without react? TripsLayer example uses React and I really don't know, how to convert it to pure js. Please look at "animate" function in the code below. I tried to update state of layer but it doesn't work (there is no animation of TripsLayer). I don't know, where should I assign "time" variable.



Demo of TripsLayer: https://deck.gl/#/examples/custom-layers/trip-routes



React version my code: https://github.com/uber/deck.gl/blob/master/examples/website/trips/app.js



Docs for TripsLayer: https://github.com/uber/deck.gl/tree/master/modules/experimental-layers/src/trips-layer



My code:



import {MapboxLayer} from '@deck.gl/mapbox';
import {TripsLayer} from '@deck.gl/experimental-layers';
import mapboxgl from 'mapbox-gl';

class App
{
constructor()
{
this.stateInfo = { time: 600 };
}

get state()
{
return this.stateInfo;
}

animate() {
var loopLength = 18000; // unit corresponds to the timestamp in source data
var animationSpeed = 30; // unit time per second

const timestamp = Date.now() / 1000;
const loopTime = loopLength / animationSpeed;

var time = Math.round(((timestamp % loopTime) / loopTime) * loopLength);

// HOW SHOULD I USE time VARIABLE???

window.requestAnimationFrame(this.animate.bind(this));
}
}

var obido = new App();

var tripsLayerObido = new TripsLayer({
id: 'trips',
data: 'trips/tripsKR.json',
getPath: d => d.segments,
getColor: d => (d.vendor === 0 ? [253, 128, 93] : [23, 184, 190]),
opacity: 0.6,
strokeWidth: 30,
trailLength: 180,
currentTime: obido.state.time
});

const LIGHT_SETTINGS = {
lightsPosition: [-74.05, 40.7, 8000, -73.5, 41, 5000],
ambientRatio: 0.05,
diffuseRatio: 0.6,
specularRatio: 0.8,
lightsStrength: [2.0, 0.0, 0.0, 0.0],
numberOfLights: 2
};

export const INITIAL_VIEW_STATE = {
longitude: 19.93,
latitude: 50.03,
zoom: 12.8,
maxZoom: 19,
pitch: 60,
bearing: 0
};


mapboxgl.accessToken = "XXX";
const map = new mapboxgl.Map({
container: 'app',
style: 'mapbox://styles/elninopl/cjnlge6rl094w2so70l1cf8y5',
center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],
zoom: INITIAL_VIEW_STATE.zoom,
pitch: INITIAL_VIEW_STATE.pitch,
layers: [tripsLayerObido]
});

map.on('load', () => {
obido.animate(0);
});









share|improve this question




















  • 1




    Hi, please edit your question to explain exactly what happens ('it doesn't work' isn't helpful). I would also have another look at the tags (suggest you add javascript, for a start). Finally, please clarify why you don't want to use react. Thanks.
    – MandyShaw
    Nov 10 at 22:49















up vote
2
down vote

favorite












How can I enable animation of TripsLayer without react? TripsLayer example uses React and I really don't know, how to convert it to pure js. Please look at "animate" function in the code below. I tried to update state of layer but it doesn't work (there is no animation of TripsLayer). I don't know, where should I assign "time" variable.



Demo of TripsLayer: https://deck.gl/#/examples/custom-layers/trip-routes



React version my code: https://github.com/uber/deck.gl/blob/master/examples/website/trips/app.js



Docs for TripsLayer: https://github.com/uber/deck.gl/tree/master/modules/experimental-layers/src/trips-layer



My code:



import {MapboxLayer} from '@deck.gl/mapbox';
import {TripsLayer} from '@deck.gl/experimental-layers';
import mapboxgl from 'mapbox-gl';

class App
{
constructor()
{
this.stateInfo = { time: 600 };
}

get state()
{
return this.stateInfo;
}

animate() {
var loopLength = 18000; // unit corresponds to the timestamp in source data
var animationSpeed = 30; // unit time per second

const timestamp = Date.now() / 1000;
const loopTime = loopLength / animationSpeed;

var time = Math.round(((timestamp % loopTime) / loopTime) * loopLength);

// HOW SHOULD I USE time VARIABLE???

window.requestAnimationFrame(this.animate.bind(this));
}
}

var obido = new App();

var tripsLayerObido = new TripsLayer({
id: 'trips',
data: 'trips/tripsKR.json',
getPath: d => d.segments,
getColor: d => (d.vendor === 0 ? [253, 128, 93] : [23, 184, 190]),
opacity: 0.6,
strokeWidth: 30,
trailLength: 180,
currentTime: obido.state.time
});

const LIGHT_SETTINGS = {
lightsPosition: [-74.05, 40.7, 8000, -73.5, 41, 5000],
ambientRatio: 0.05,
diffuseRatio: 0.6,
specularRatio: 0.8,
lightsStrength: [2.0, 0.0, 0.0, 0.0],
numberOfLights: 2
};

export const INITIAL_VIEW_STATE = {
longitude: 19.93,
latitude: 50.03,
zoom: 12.8,
maxZoom: 19,
pitch: 60,
bearing: 0
};


mapboxgl.accessToken = "XXX";
const map = new mapboxgl.Map({
container: 'app',
style: 'mapbox://styles/elninopl/cjnlge6rl094w2so70l1cf8y5',
center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],
zoom: INITIAL_VIEW_STATE.zoom,
pitch: INITIAL_VIEW_STATE.pitch,
layers: [tripsLayerObido]
});

map.on('load', () => {
obido.animate(0);
});









share|improve this question




















  • 1




    Hi, please edit your question to explain exactly what happens ('it doesn't work' isn't helpful). I would also have another look at the tags (suggest you add javascript, for a start). Finally, please clarify why you don't want to use react. Thanks.
    – MandyShaw
    Nov 10 at 22:49













up vote
2
down vote

favorite









up vote
2
down vote

favorite











How can I enable animation of TripsLayer without react? TripsLayer example uses React and I really don't know, how to convert it to pure js. Please look at "animate" function in the code below. I tried to update state of layer but it doesn't work (there is no animation of TripsLayer). I don't know, where should I assign "time" variable.



Demo of TripsLayer: https://deck.gl/#/examples/custom-layers/trip-routes



React version my code: https://github.com/uber/deck.gl/blob/master/examples/website/trips/app.js



Docs for TripsLayer: https://github.com/uber/deck.gl/tree/master/modules/experimental-layers/src/trips-layer



My code:



import {MapboxLayer} from '@deck.gl/mapbox';
import {TripsLayer} from '@deck.gl/experimental-layers';
import mapboxgl from 'mapbox-gl';

class App
{
constructor()
{
this.stateInfo = { time: 600 };
}

get state()
{
return this.stateInfo;
}

animate() {
var loopLength = 18000; // unit corresponds to the timestamp in source data
var animationSpeed = 30; // unit time per second

const timestamp = Date.now() / 1000;
const loopTime = loopLength / animationSpeed;

var time = Math.round(((timestamp % loopTime) / loopTime) * loopLength);

// HOW SHOULD I USE time VARIABLE???

window.requestAnimationFrame(this.animate.bind(this));
}
}

var obido = new App();

var tripsLayerObido = new TripsLayer({
id: 'trips',
data: 'trips/tripsKR.json',
getPath: d => d.segments,
getColor: d => (d.vendor === 0 ? [253, 128, 93] : [23, 184, 190]),
opacity: 0.6,
strokeWidth: 30,
trailLength: 180,
currentTime: obido.state.time
});

const LIGHT_SETTINGS = {
lightsPosition: [-74.05, 40.7, 8000, -73.5, 41, 5000],
ambientRatio: 0.05,
diffuseRatio: 0.6,
specularRatio: 0.8,
lightsStrength: [2.0, 0.0, 0.0, 0.0],
numberOfLights: 2
};

export const INITIAL_VIEW_STATE = {
longitude: 19.93,
latitude: 50.03,
zoom: 12.8,
maxZoom: 19,
pitch: 60,
bearing: 0
};


mapboxgl.accessToken = "XXX";
const map = new mapboxgl.Map({
container: 'app',
style: 'mapbox://styles/elninopl/cjnlge6rl094w2so70l1cf8y5',
center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],
zoom: INITIAL_VIEW_STATE.zoom,
pitch: INITIAL_VIEW_STATE.pitch,
layers: [tripsLayerObido]
});

map.on('load', () => {
obido.animate(0);
});









share|improve this question















How can I enable animation of TripsLayer without react? TripsLayer example uses React and I really don't know, how to convert it to pure js. Please look at "animate" function in the code below. I tried to update state of layer but it doesn't work (there is no animation of TripsLayer). I don't know, where should I assign "time" variable.



Demo of TripsLayer: https://deck.gl/#/examples/custom-layers/trip-routes



React version my code: https://github.com/uber/deck.gl/blob/master/examples/website/trips/app.js



Docs for TripsLayer: https://github.com/uber/deck.gl/tree/master/modules/experimental-layers/src/trips-layer



My code:



import {MapboxLayer} from '@deck.gl/mapbox';
import {TripsLayer} from '@deck.gl/experimental-layers';
import mapboxgl from 'mapbox-gl';

class App
{
constructor()
{
this.stateInfo = { time: 600 };
}

get state()
{
return this.stateInfo;
}

animate() {
var loopLength = 18000; // unit corresponds to the timestamp in source data
var animationSpeed = 30; // unit time per second

const timestamp = Date.now() / 1000;
const loopTime = loopLength / animationSpeed;

var time = Math.round(((timestamp % loopTime) / loopTime) * loopLength);

// HOW SHOULD I USE time VARIABLE???

window.requestAnimationFrame(this.animate.bind(this));
}
}

var obido = new App();

var tripsLayerObido = new TripsLayer({
id: 'trips',
data: 'trips/tripsKR.json',
getPath: d => d.segments,
getColor: d => (d.vendor === 0 ? [253, 128, 93] : [23, 184, 190]),
opacity: 0.6,
strokeWidth: 30,
trailLength: 180,
currentTime: obido.state.time
});

const LIGHT_SETTINGS = {
lightsPosition: [-74.05, 40.7, 8000, -73.5, 41, 5000],
ambientRatio: 0.05,
diffuseRatio: 0.6,
specularRatio: 0.8,
lightsStrength: [2.0, 0.0, 0.0, 0.0],
numberOfLights: 2
};

export const INITIAL_VIEW_STATE = {
longitude: 19.93,
latitude: 50.03,
zoom: 12.8,
maxZoom: 19,
pitch: 60,
bearing: 0
};


mapboxgl.accessToken = "XXX";
const map = new mapboxgl.Map({
container: 'app',
style: 'mapbox://styles/elninopl/cjnlge6rl094w2so70l1cf8y5',
center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],
zoom: INITIAL_VIEW_STATE.zoom,
pitch: INITIAL_VIEW_STATE.pitch,
layers: [tripsLayerObido]
});

map.on('load', () => {
obido.animate(0);
});






javascript reactjs deck.gl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 9:06

























asked Nov 10 at 21:10









elniño

4116




4116








  • 1




    Hi, please edit your question to explain exactly what happens ('it doesn't work' isn't helpful). I would also have another look at the tags (suggest you add javascript, for a start). Finally, please clarify why you don't want to use react. Thanks.
    – MandyShaw
    Nov 10 at 22:49














  • 1




    Hi, please edit your question to explain exactly what happens ('it doesn't work' isn't helpful). I would also have another look at the tags (suggest you add javascript, for a start). Finally, please clarify why you don't want to use react. Thanks.
    – MandyShaw
    Nov 10 at 22:49








1




1




Hi, please edit your question to explain exactly what happens ('it doesn't work' isn't helpful). I would also have another look at the tags (suggest you add javascript, for a start). Finally, please clarify why you don't want to use react. Thanks.
– MandyShaw
Nov 10 at 22:49




Hi, please edit your question to explain exactly what happens ('it doesn't work' isn't helpful). I would also have another look at the tags (suggest you add javascript, for a start). Finally, please clarify why you don't want to use react. Thanks.
– MandyShaw
Nov 10 at 22:49

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243436%2fdeck-gl-tripslayer-without-react-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243436%2fdeck-gl-tripslayer-without-react-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)