Skip to content

Commit

Permalink
performance improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarkraemer committed Aug 28, 2023
1 parent ea4926c commit d317d3d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def home():

@app.route('/tour/<tourid>')
def gpx(tourid):
if not is_logged_in():
return Response(status=401)
#if not is_logged_in():
# return Response(status=401)

gpx_data = get_data.get_tour_gpx(request.cookies.get('api'), tourid)
if not gpx_data:
Expand Down
34 changes: 29 additions & 5 deletions static/js/visualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var polylines = [];
var osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {id: 'OSM', attribution: '&copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors'}),
satellite = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {id: 'satellite', attribution: 'Tiles &copy; Esri &mdash; Source: Esri, [...] and the GIS User Community'});

var map = L.map('map').setView([51.16, 10.44], 6);
var map = L.map('map', {preferCanvas: true}).setView([51.16, 10.44], 6);
osm.addTo(map);

//create sidebar
Expand All @@ -143,6 +143,10 @@ var elapsedMax = 0;

var allRoutes = [];

var speeds = [];

var viz_counter = 0;

//Visualizer class
class Visualizer {

Expand All @@ -160,11 +164,11 @@ class Visualizer {
"speed": {
unit: "km/h",
thresholds: [],
optionIdxFn: function(latLng, prevLatLng) {
optionIdxFn: function(latLng, prevLatLng, index) {
var i, speed,
speedThresholds = Visualizer.options["speed"].thresholds;

speed = getSpeed(latLng, prevLatLng);
speed = speeds[viz_counter][index];

for (i = 0; i < speedThresholds.length; ++i) {
if (speed <= speedThresholds[i]) {
Expand Down Expand Up @@ -268,9 +272,9 @@ class Visualizer {
opacity = 0.5;
}

for (var i = 0; i < allRoutes.length; i++) {
for (viz_counter = 0; viz_counter < allRoutes.length; viz_counter++) {
//create multi options polyline
var polyline = L.multiOptionsPolyline(allRoutes[i], {
var polyline = L.multiOptionsPolyline(allRoutes[viz_counter], {
multiOptions: Visualizer.options[new_vizualisation],
weight: 4,
lineCap: 'round',
Expand All @@ -283,6 +287,24 @@ class Visualizer {
}
}

static precalculate_speeds() {
//calculate speeds
for (var i = 0; i < allRoutes.length; i++) {
var latLngSpeeds = [];

var points = allRoutes[i];

for (var j = 1; j < points.length - 1; j++) {
var speed = getSpeed(points[j], points[j-1]);
latLngSpeeds.push(speed);
}

speeds.push(latLngSpeeds);
}

console.log(speeds);
}

static change_layer(new_layer) {
if(new_layer == "osm") {
map.removeLayer(satellite);
Expand Down Expand Up @@ -325,5 +347,7 @@ loadGPX(function(tours) {

allRoutes = convertedRoutes;

Visualizer.precalculate_speeds();

Visualizer.show_polylines(map, allRoutes, "heatmap");
});

0 comments on commit d317d3d

Please sign in to comment.