leaflet.stravasegments
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -15,2 +15,4 @@ 'use strict'; | ||
this.stravaLayer = new L.layerGroup([], { attribution: '<a href="https://strava.com">Strava</a>' }); | ||
this.runningButton = new L.easyButton({ | ||
@@ -61,2 +63,6 @@ states: [{ | ||
computeAngle: function computeAngle(a, b) { | ||
return Math.atan2(b.y - a.y, b.x - a.x) * 180 / Math.PI; | ||
}, | ||
showSegments: function showSegments(map, button, activityType) { | ||
@@ -68,2 +74,4 @@ var self = this; | ||
this.stravaLayer.addTo(map); | ||
this.get(url, L.bind(function (error, explorerResponse) { | ||
@@ -83,6 +91,18 @@ button.state('default'); | ||
if (self.stravaLayer.getLayers().map(function (it) { | ||
return it.options.id; | ||
}).indexOf(segment.id) !== -1) { | ||
// this segment is already present, skipping | ||
continue; | ||
} | ||
var points = polyline.decode(segment.points); | ||
var color = activityType === 'running' ? 'red' : 'blue'; | ||
var start = new L.triangleMarker(points[0], { width: 12, height: 10, rotation: self.computeAngle(L.point(points[0]), L.point(points[1])), color: color }); | ||
var end = new L.circle(points[points.length - 1], { radius: 30, color: color }); | ||
var segmentLine = new L.polyline(points, { | ||
id: segment.id, | ||
weight: 3, | ||
color: activityType === 'running' ? 'red' : 'blue' | ||
color: color | ||
}); | ||
@@ -103,3 +123,5 @@ segmentLine.on('mouseover', function (e) { | ||
tooltip += ': ' + segment.elev_difference + 'm (avg ' + segment.avg_grade + '%)'; | ||
segmentLine.addTo(map).bindTooltip(tooltip); | ||
self.stravaLayer.addLayer(start); | ||
self.stravaLayer.addLayer(end); | ||
self.stravaLayer.addLayer(segmentLine.bindTooltip(tooltip)); | ||
} | ||
@@ -106,0 +128,0 @@ } catch (err) { |
{ | ||
"name": "leaflet.stravasegments", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Display Strava segments on a map!", | ||
@@ -5,0 +5,0 @@ "main": "dist/L.StravaSegments.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
408391
160