Changeset d33326a in OpenWorkouts-current


Ignore:
Timestamp:
Jan 19, 2019, 5:47:10 PM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
b22a9d2
Parents:
b030195
Message:

Accept two new parameters to the js leaflet map builder:

  • map_id: the id of the html element that is the container for the map
  • elevation: true if we want to show the Leaflet.Elevation chart, false otherwise.

Added a fit_bounds() call suggested in Leaflet.Elevation docs

Location:
ow
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ow/static/js/ow.js

    rb030195 rd33326a  
    1616
    1717    // parameters provided when creating an "instance" of a map
     18    var map_id = spec.map_id;
    1819    var latitude = spec.latitude;
    1920    var longitude = spec.longitude;
     
    2324    var end_icon = spec.end_icon;
    2425    var shadow = spec.shadow;
     26    var elevation = spec.elevation;
    2527
    2628    // OpenStreetMap urls and references
     
    3638    var create_map = function create_map(latitude, longitude, zoom) {
    3739        /* Create a Leaflet map, set center point and add tiles */
    38         map = L.map('map');
     40        map = L.map(map_id, {preferCanvas: true});
    3941        map.setView([latitude, longitude], zoom);
    4042        var tile_layer = L.tileLayer(openstreetmap_url, {
     
    9092            },
    9193        });
    92         gpx.on("addline",function(e){
    93             elevation.addData(e.line);
    94             // ow_charts.addData(e.line);
    95         });
     94
     95        gpx.on('loaded', function(e) {
     96            map.fitBounds(e.target.getBounds());
     97        });
     98
     99        if (elevation) {
     100            gpx.on("addline",function(e){
     101                elevation.addData(e.line);
     102                // ow_charts.addData(e.line);
     103            });
     104        };
     105
    96106        gpx.addTo(map);
    97107    };
     
    100110        // create the map, add elevation, load gpx
    101111        create_map(latitude, longitude, zoom);
    102         add_elevation_chart();
     112        if (elevation) {
     113            add_elevation_chart();
     114        }
    103115        // add_ow_charts();
    104116        load_gpx(gpx_url);
  • ow/templates/workout.pt

    rb030195 rd33326a  
    152152    <script type="text/javascript" tal:condition="context.has_gpx">
    153153     var workout_map = owjs.map({
     154         map_id: 'map',
    154155         latitude: ${start_point['latitude']},
    155156         longitude: ${start_point['longitude']},
     
    159160         end_icon: '${request.static_url('ow:static/components/leaflet-gpx/pin-icon-end.png')}',
    160161         shadow: '${request.static_url('ow:static/components/leaflet-gpx/pin-shadow.png')}',
     162         elevation: true
    161163     });
    162164     workout_map.render();
Note: See TracChangeset for help on using the changeset viewer.