source: OpenWorkouts-current/ow/static/js/ow.js @ 8af3272

currentfeature/docs
Last change on this file since 8af3272 was 8af3272, checked in by borja <borja@…>, 5 years ago

A bit of clean up in the workout details page, removed temporary code

tested while looking for a better solution for the elevation/hr/cad/etc
charts.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1
2/*
3
4  OpenWorkouts Javascript code
5
6*/
7
8
9// Namespace
10var owjs = {};
11
12
13owjs.map = function(spec) {
14
15    "use strict";
16
17    // parameters provided when creating an "instance" of a map
18    var latitude = spec.latitude;
19    var longitude = spec.longitude;
20    var zoom = spec.zoom;
21    var gpx_url = spec.gpx_url;
22    var start_icon = spec.start_icon;
23    var end_icon = spec.end_icon;
24    var shadow = spec.shadow;
25
26    // OpenStreetMap urls and references
27    var openstreetmap_url = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
28    var openstreetmap_attr = 'Map data &copy; <a href="http://www.osm.org">OpenStreetMap</a>'
29
30    // Some constants reused through the code
31    var map;
32    var gpx;
33    var elevation;
34    var ow_charts;
35
36    var create_map = function create_map(latitude, longitude, zoom) {
37        /* Create a Leaflet map, set center point and add tiles */
38        map = L.map('map');
39        map.setView([latitude, longitude], zoom);
40        var tile_layer = L.tileLayer(openstreetmap_url, {
41            attribution: openstreetmap_attr
42        });
43        tile_layer.addTo(map);
44    };
45
46    var add_elevation_chart = function add_elevation_chart() {
47        /*
48           Add the elevation chart support to the map.
49           This has to be called *after* create_map and *before* load_gpx.
50        */
51        elevation = L.control.elevation({
52            position: "bottomright",
53            theme: "steelblue-theme", //default: lime-theme
54            width: 600,
55            height: 125,
56            margins: {
57                top: 10,
58                right: 20,
59                bottom: 30,
60                left: 50
61            },
62            useHeightIndicator: true, //if false a marker is drawn at map position
63            interpolation: "linear", //see https://github.com/mbostock/d3/wiki/SVG-Shapes#wiki-area_interpolate
64            hoverNumber: {
65                decimalsX: 3, //decimals on distance (always in km)
66                decimalsY: 0, //deciamls on height (always in m)
67                formatter: undefined //custom formatter function may be injected
68            },
69            xTicks: undefined, //number of ticks in x axis, calculated by default according to width
70            yTicks: undefined, //number of ticks on y axis, calculated by default according to height
71            collapsed: false    //collapsed mode, show chart on click or mouseover
72        });
73
74        var ele_container = elevation.addTo(map);
75        /* document.getElementById('ow-analysis').appendChild(
76            ele_container._container); */
77    };
78
79    var load_gpx = function load_gpx(gpx_url) {
80        /*
81          Load the gpx from the given url, add it to the map and feed it to the
82          elevation chart
83        */
84        var gpx = new L.GPX(gpx_url, {
85            async: true,
86            marker_options: {
87                startIconUrl: start_icon,
88                endIconUrl: end_icon,
89                shadowUrl: shadow,
90            },
91        });
92        gpx.on("addline",function(e){
93            elevation.addData(e.line);
94            // ow_charts.addData(e.line);
95        });
96        gpx.addTo(map);
97    };
98
99    var render = function render() {
100        // create the map, add elevation, load gpx
101        create_map(latitude, longitude, zoom);
102        add_elevation_chart();
103        // add_ow_charts();
104        load_gpx(gpx_url);
105    };
106
107    var that = {}
108    that.render = render;
109    return that
110
111};
Note: See TracBrowser for help on using the repository browser.