Skip to content

Commit b6b10e8

Browse files
Mario Aeberhardfbarbe
authored andcommitted
Output all waypoints as loc parameters, using empty string for missing
1 parent 11633c5 commit b6b10e8

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/links.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ function _parseInteger(intStr) {
3737
}
3838

3939
function formatLink(options) {
40+
// Output all waypoints as loc parameters, using empty string for missing
41+
var locs = undefined;
42+
if (options.waypoints) {
43+
locs = options.waypoints.map(function(wp) {
44+
return wp && wp.latLng ? _formatCoord(wp.latLng) : '';
45+
});
46+
}
4047
return qs.stringify({
4148
z: options.zoom,
4249
center: options.center ? _formatCoord(options.center) : undefined,
43-
loc: options.waypoints ? options.waypoints.filter(function(wp) {
44-
return wp.latLng !== undefined;
45-
})
46-
.map(function(wp) {
47-
return wp.latLng;
48-
})
49-
.map(_formatCoord) : undefined,
50+
loc: locs,
5051
hl: options.language,
5152
alt: options.alternative,
5253
df: options.units,
@@ -65,16 +66,12 @@ function parseLink(link) {
6566
parsedValues.center = q.center && _parseCoord(q.center);
6667
if (q.loc) {
6768
if (q.loc.constructor === Array) {
68-
// more than one loc is given
69-
parsedValues.waypoints = q.loc.filter(function (loc) {
70-
return loc != "";
71-
}).map(_parseCoord).map(
72-
function (coord) {
73-
return L.Routing.waypoint(coord);
74-
}
75-
);
69+
// any number of locs: start, via, end, etc.
70+
parsedValues.waypoints = q.loc.map(function(loc) {
71+
return loc && loc !== '' ? L.Routing.waypoint(_parseCoord(loc)) : L.Routing.waypoint(null);
72+
});
7673
} else if (q.loc.constructor === String) {
77-
// exactly one loc is given
74+
// exactly one loc is given (backward compatibility)
7875
parsedValues.waypoints = [L.Routing.waypoint(_parseCoord(q.loc))];
7976
}
8077
}

0 commit comments

Comments
 (0)