@wemap/osm 5.4.7 → 5.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/wemap-osm.es.js
CHANGED
|
@@ -476,7 +476,7 @@ class Step {
|
|
|
476
476
|
|
|
477
477
|
class Leg {
|
|
478
478
|
|
|
479
|
-
/** @type {!string} can be WALK, BIKE, BUS, TRAM, CAR */
|
|
479
|
+
/** @type {!string} can be WALK, BIKE, BUS, TRAM, CAR, FUNICULAR */
|
|
480
480
|
mode;
|
|
481
481
|
|
|
482
482
|
/** @type {!number} */
|
|
@@ -1203,7 +1203,7 @@ function coordinatesToJson(coordinates) {
|
|
|
1203
1203
|
* @param {object} json
|
|
1204
1204
|
* @returns {Coordinates}
|
|
1205
1205
|
*/
|
|
1206
|
-
function jsonToCoordinates$
|
|
1206
|
+
function jsonToCoordinates$2(json) {
|
|
1207
1207
|
const output = new Coordinates(json[1], json[0]);
|
|
1208
1208
|
if (json.length > 2) {
|
|
1209
1209
|
output.level = Level.fromString(json[2]);
|
|
@@ -1339,7 +1339,7 @@ function parseJsonSteps$1(jsonSteps, legCoords) {
|
|
|
1339
1339
|
return jsonSteps.map(jsonStep => {
|
|
1340
1340
|
|
|
1341
1341
|
const step = new Step();
|
|
1342
|
-
step.coords = jsonToCoordinates$
|
|
1342
|
+
step.coords = jsonToCoordinates$2(jsonStep.maneuver.location);
|
|
1343
1343
|
|
|
1344
1344
|
// Sometimes, OSRM step does not have the same coordinates than a point in legCoords.
|
|
1345
1345
|
// ex: first step of https://routing.getwemap.com/route/v1/walking/2.33222164147,48.87084765712;2.3320734,48.8730212?geometries=geojson&overview=full&steps=true
|
|
@@ -1377,7 +1377,7 @@ function parseJsonSteps$1(jsonSteps, legCoords) {
|
|
|
1377
1377
|
* @param {?string} routingMode [walking|driving|bicycle]
|
|
1378
1378
|
* @returns {?RouterResponse}
|
|
1379
1379
|
*/
|
|
1380
|
-
function createRouterResponseFromJson$
|
|
1380
|
+
function createRouterResponseFromJson$2(json, from, to, routingMode = 'walking') {
|
|
1381
1381
|
|
|
1382
1382
|
const { routes: jsonRoutes } = json;
|
|
1383
1383
|
|
|
@@ -1418,7 +1418,7 @@ function createRouterResponseFromJson$1(json, from, to, routingMode = 'walking')
|
|
|
1418
1418
|
leg.duration = jsonLeg.duration;
|
|
1419
1419
|
|
|
1420
1420
|
leg.coords = jsonLeg.steps
|
|
1421
|
-
.map(step => step.geometry.coordinates.map(jsonToCoordinates$
|
|
1421
|
+
.map(step => step.geometry.coordinates.map(jsonToCoordinates$2))
|
|
1422
1422
|
.flat()
|
|
1423
1423
|
// Remove duplicates
|
|
1424
1424
|
.filter((coords, idx, arr) => idx === 0 || !arr[idx - 1].equalsTo(coords));
|
|
@@ -1448,12 +1448,12 @@ function createRouterResponseFromJson$1(json, from, to, routingMode = 'walking')
|
|
|
1448
1448
|
var OsrmUtils = /*#__PURE__*/Object.freeze({
|
|
1449
1449
|
__proto__: null,
|
|
1450
1450
|
coordinatesToJson: coordinatesToJson,
|
|
1451
|
-
jsonToCoordinates: jsonToCoordinates$
|
|
1451
|
+
jsonToCoordinates: jsonToCoordinates$2,
|
|
1452
1452
|
nodesToJsonCoords: nodesToJsonCoords,
|
|
1453
1453
|
getModifierFromAngle: getModifierFromAngle,
|
|
1454
1454
|
noRouteFoundJson: noRouteFoundJson,
|
|
1455
1455
|
itineraryToOsrmJson: itineraryToOsrmJson,
|
|
1456
|
-
createRouterResponseFromJson: createRouterResponseFromJson$
|
|
1456
|
+
createRouterResponseFromJson: createRouterResponseFromJson$2
|
|
1457
1457
|
});
|
|
1458
1458
|
|
|
1459
1459
|
/* eslint-disable max-statements */
|
|
@@ -1462,7 +1462,7 @@ var OsrmUtils = /*#__PURE__*/Object.freeze({
|
|
|
1462
1462
|
* @param {object} json
|
|
1463
1463
|
* @returns {Coordinates}
|
|
1464
1464
|
*/
|
|
1465
|
-
function jsonToCoordinates(json) {
|
|
1465
|
+
function jsonToCoordinates$1(json) {
|
|
1466
1466
|
return new Coordinates(json.lat, json.lon);
|
|
1467
1467
|
}
|
|
1468
1468
|
|
|
@@ -1480,7 +1480,7 @@ function parseJsonSteps(jsonSteps, legCoords) {
|
|
|
1480
1480
|
return jsonSteps.map(jsonStep => {
|
|
1481
1481
|
|
|
1482
1482
|
const step = new Step();
|
|
1483
|
-
const stepCoords = jsonToCoordinates(jsonStep);
|
|
1483
|
+
const stepCoords = jsonToCoordinates$1(jsonStep);
|
|
1484
1484
|
|
|
1485
1485
|
// OTP step does not have the same coordinates than a point in legCoords.
|
|
1486
1486
|
// That is why we look for the closest point.
|
|
@@ -1506,7 +1506,7 @@ function parseJsonSteps(jsonSteps, legCoords) {
|
|
|
1506
1506
|
* @param {object} json JSON file provided by OTP.
|
|
1507
1507
|
* @returns {?RouterResponse}
|
|
1508
1508
|
*/
|
|
1509
|
-
function createRouterResponseFromJson(json) {
|
|
1509
|
+
function createRouterResponseFromJson$1(json) {
|
|
1510
1510
|
|
|
1511
1511
|
const { plan: jsonPlan } = json;
|
|
1512
1512
|
|
|
@@ -1517,8 +1517,8 @@ function createRouterResponseFromJson(json) {
|
|
|
1517
1517
|
const routerResponse = new RouterResponse();
|
|
1518
1518
|
routerResponse.routerName = 'otp';
|
|
1519
1519
|
|
|
1520
|
-
routerResponse.from = jsonToCoordinates(jsonPlan.from);
|
|
1521
|
-
routerResponse.to = jsonToCoordinates(jsonPlan.to);
|
|
1520
|
+
routerResponse.from = jsonToCoordinates$1(jsonPlan.from);
|
|
1521
|
+
routerResponse.to = jsonToCoordinates$1(jsonPlan.to);
|
|
1522
1522
|
|
|
1523
1523
|
for (const jsonItinerary of jsonPlan.itineraries) {
|
|
1524
1524
|
|
|
@@ -1542,11 +1542,11 @@ function createRouterResponseFromJson(json) {
|
|
|
1542
1542
|
leg.endTime = jsonLeg.endTime;
|
|
1543
1543
|
leg.from = {
|
|
1544
1544
|
name: jsonLeg.from.name,
|
|
1545
|
-
coords: jsonToCoordinates(jsonLeg.from)
|
|
1545
|
+
coords: jsonToCoordinates$1(jsonLeg.from)
|
|
1546
1546
|
};
|
|
1547
1547
|
leg.to = {
|
|
1548
1548
|
name: jsonLeg.to.name,
|
|
1549
|
-
coords: jsonToCoordinates(jsonLeg.to)
|
|
1549
|
+
coords: jsonToCoordinates$1(jsonLeg.to)
|
|
1550
1550
|
};
|
|
1551
1551
|
leg.coords = Polyline.decode(jsonLeg.legGeometry.points).map(([lat, lon]) => new Coordinates(lat, lon));
|
|
1552
1552
|
|
|
@@ -1597,6 +1597,233 @@ function createRouterResponseFromJson(json) {
|
|
|
1597
1597
|
}
|
|
1598
1598
|
|
|
1599
1599
|
var OtpUtils = /*#__PURE__*/Object.freeze({
|
|
1600
|
+
__proto__: null,
|
|
1601
|
+
jsonToCoordinates: jsonToCoordinates$1,
|
|
1602
|
+
createRouterResponseFromJson: createRouterResponseFromJson$1
|
|
1603
|
+
});
|
|
1604
|
+
|
|
1605
|
+
/* eslint-disable max-depth */
|
|
1606
|
+
|
|
1607
|
+
/**
|
|
1608
|
+
* @param {object} json
|
|
1609
|
+
* @returns {Coordinates}
|
|
1610
|
+
*/
|
|
1611
|
+
function jsonToCoordinates(json) {
|
|
1612
|
+
return new Coordinates(json.Lat, json.Long);
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* @param {string} jsonDate
|
|
1617
|
+
* @returns {number}
|
|
1618
|
+
*/
|
|
1619
|
+
function jsonDateToTimestamp(jsonDate) {
|
|
1620
|
+
const [dateStr, timeStr] = jsonDate.split(' ');
|
|
1621
|
+
const [dayStr, monthStr, yearStr] = dateStr.split('/');
|
|
1622
|
+
const [hoursStr, minutesStr, secondsStr] = timeStr.split(':');
|
|
1623
|
+
const date = new Date(
|
|
1624
|
+
Number(yearStr), Number(monthStr) - 1, Number(dayStr),
|
|
1625
|
+
Number(hoursStr), Number(minutesStr), Number(secondsStr)
|
|
1626
|
+
);
|
|
1627
|
+
return date.getTime();
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* @param {string} wktGeometry
|
|
1632
|
+
* @returns {Coordinates[]}
|
|
1633
|
+
*/
|
|
1634
|
+
function parseWKTGeometry(wktGeometry) {
|
|
1635
|
+
const tmpCoordsStr = wktGeometry.match(/LINESTRING \((.*)\)/i);
|
|
1636
|
+
if (!tmpCoordsStr) {
|
|
1637
|
+
return null;
|
|
1638
|
+
}
|
|
1639
|
+
return tmpCoordsStr[1].split(',').map(str => {
|
|
1640
|
+
const sp = str.trim().split(' ');
|
|
1641
|
+
return new Coordinates(Number(sp[1]), Number(sp[0]));
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
/**
|
|
1646
|
+
* @param {string} iso8601Duration
|
|
1647
|
+
* @see https://stackoverflow.com/a/29153059/2239938
|
|
1648
|
+
*/
|
|
1649
|
+
function parseDuration(iso8601Duration) {
|
|
1650
|
+
const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
|
|
1651
|
+
|
|
1652
|
+
var matches = iso8601Duration.match(iso8601DurationRegex);
|
|
1653
|
+
|
|
1654
|
+
// const sign = typeof matches[1] === 'undefined' ? '+' : '-',
|
|
1655
|
+
const years = typeof matches[2] === 'undefined' ? 0 : Number(matches[2]);
|
|
1656
|
+
const months = typeof matches[3] === 'undefined' ? 0 : Number(matches[3]);
|
|
1657
|
+
const weeks = typeof matches[4] === 'undefined' ? 0 : Number(matches[4]);
|
|
1658
|
+
const days = typeof matches[5] === 'undefined' ? 0 : Number(matches[5]);
|
|
1659
|
+
const hours = typeof matches[6] === 'undefined' ? 0 : Number(matches[6]);
|
|
1660
|
+
const minutes = typeof matches[7] === 'undefined' ? 0 : Number(matches[7]);
|
|
1661
|
+
const seconds = typeof matches[8] === 'undefined' ? 0 : Number(matches[8]);
|
|
1662
|
+
|
|
1663
|
+
return seconds
|
|
1664
|
+
+ minutes * 60
|
|
1665
|
+
+ hours * 3600
|
|
1666
|
+
+ days * 86400
|
|
1667
|
+
+ weeks * (86400 * 7)
|
|
1668
|
+
+ months * (86400 * 30)
|
|
1669
|
+
+ years * (86400 * 365.25);
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
/**
|
|
1673
|
+
* Generate multi itineraries from Cityway JSON
|
|
1674
|
+
* @param {object} json JSON file provided by Cityway.
|
|
1675
|
+
* @returns {?RouterResponse}
|
|
1676
|
+
* @example https://preprod.api.lia2.cityway.fr/journeyplanner/api/opt/PlanTrips/json?DepartureLatitude=49.51509388236216&DepartureLongitude=0.09341749619366316&ArrivalLatitude=49.5067090188444&ArrivalLongitude=0.1694842115417831&DepartureType=COORDINATES&ArrivalType=COORDINATES
|
|
1677
|
+
*/
|
|
1678
|
+
function createRouterResponseFromJson(json) {
|
|
1679
|
+
|
|
1680
|
+
if (json.StatusCode !== 200 || !json.Data || !json.Data.length) {
|
|
1681
|
+
return null;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
const routerResponse = new RouterResponse();
|
|
1685
|
+
routerResponse.routerName = 'cityway';
|
|
1686
|
+
|
|
1687
|
+
|
|
1688
|
+
// Do not know if it the best approach, but it works...
|
|
1689
|
+
const allJsonTrips = json.Data.reduce((acc, dataObj) => {
|
|
1690
|
+
acc.push(...dataObj.response.trips.Trip);
|
|
1691
|
+
return acc;
|
|
1692
|
+
}, []);
|
|
1693
|
+
|
|
1694
|
+
for (const trip of allJsonTrips) {
|
|
1695
|
+
|
|
1696
|
+
const itinerary = new Itinerary();
|
|
1697
|
+
|
|
1698
|
+
itinerary.duration = parseDuration(trip.Duration);
|
|
1699
|
+
itinerary.startTime = jsonDateToTimestamp(trip.Departure.Time);
|
|
1700
|
+
itinerary.from = jsonToCoordinates(trip.Departure.Site.Position);
|
|
1701
|
+
itinerary.endTime = jsonDateToTimestamp(trip.Arrival.Time);
|
|
1702
|
+
itinerary.to = jsonToCoordinates(trip.Arrival.Site.Position);
|
|
1703
|
+
routerResponse.itineraries.push(itinerary);
|
|
1704
|
+
|
|
1705
|
+
for (const jsonSection of trip.sections.Section) {
|
|
1706
|
+
|
|
1707
|
+
const jsonLeg = jsonSection.Leg ? jsonSection.Leg : jsonSection.PTRide;
|
|
1708
|
+
|
|
1709
|
+
const leg = new Leg();
|
|
1710
|
+
|
|
1711
|
+
leg.mode = jsonLeg.TransportMode;
|
|
1712
|
+
leg.duration = parseDuration(jsonLeg.Duration);
|
|
1713
|
+
leg.startTime = jsonDateToTimestamp(jsonLeg.Departure.Time);
|
|
1714
|
+
leg.endTime = jsonDateToTimestamp(jsonLeg.Arrival.Time);
|
|
1715
|
+
leg.coords = [];
|
|
1716
|
+
|
|
1717
|
+
if (leg.mode === 'WALK' || leg.mode === 'BICYCLE') {
|
|
1718
|
+
|
|
1719
|
+
leg.from = {
|
|
1720
|
+
name: jsonLeg.Departure.Site.Name,
|
|
1721
|
+
coords: jsonToCoordinates(jsonLeg.Departure.Site.Position)
|
|
1722
|
+
};
|
|
1723
|
+
leg.to = {
|
|
1724
|
+
name: jsonLeg.Arrival.Site.Name,
|
|
1725
|
+
coords: jsonToCoordinates(jsonLeg.Arrival.Site.Position)
|
|
1726
|
+
};
|
|
1727
|
+
|
|
1728
|
+
leg.steps = [];
|
|
1729
|
+
for (const jsonPathLink of jsonLeg.pathLinks.PathLink) {
|
|
1730
|
+
const step = new Step();
|
|
1731
|
+
let stepCoords;
|
|
1732
|
+
if (jsonPathLink.Geometry) {
|
|
1733
|
+
stepCoords = parseWKTGeometry(jsonPathLink.Geometry);
|
|
1734
|
+
} else {
|
|
1735
|
+
stepCoords = [leg.from.coords, leg.to.coords];
|
|
1736
|
+
}
|
|
1737
|
+
step.coords = stepCoords[0];
|
|
1738
|
+
step._idCoordsInLeg = leg.coords.length;
|
|
1739
|
+
stepCoords.forEach((coords, idx) => {
|
|
1740
|
+
if (
|
|
1741
|
+
idx !== 0
|
|
1742
|
+
|| leg.coords.length === 0
|
|
1743
|
+
|| !leg.coords[leg.coords.length - 1].equalsTo(coords)
|
|
1744
|
+
) {
|
|
1745
|
+
leg.coords.push(coords);
|
|
1746
|
+
}
|
|
1747
|
+
});
|
|
1748
|
+
|
|
1749
|
+
|
|
1750
|
+
step.name = jsonPathLink.Departure.Site.Name;
|
|
1751
|
+
step.levelChange = null;
|
|
1752
|
+
|
|
1753
|
+
step.distance = jsonPathLink.Distance;
|
|
1754
|
+
|
|
1755
|
+
leg.steps.push(step);
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
} else if (leg.mode === 'BUS' || leg.mode === 'TRAM' || leg.mode === 'FUNICULAR') {
|
|
1759
|
+
|
|
1760
|
+
leg.from = {
|
|
1761
|
+
name: jsonLeg.Departure.StopPlace.Name,
|
|
1762
|
+
coords: jsonToCoordinates(jsonLeg.Departure.StopPlace.Position)
|
|
1763
|
+
};
|
|
1764
|
+
leg.to = {
|
|
1765
|
+
name: jsonLeg.Arrival.StopPlace.Name,
|
|
1766
|
+
coords: jsonToCoordinates(jsonLeg.Arrival.StopPlace.Position)
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
leg.transportInfo = {
|
|
1770
|
+
name: jsonLeg.Line.Number,
|
|
1771
|
+
routeColor: jsonLeg.Line.Color,
|
|
1772
|
+
routeTextColor: jsonLeg.Line.TextColor,
|
|
1773
|
+
directionName: jsonLeg.Destination
|
|
1774
|
+
};
|
|
1775
|
+
|
|
1776
|
+
for (const jsonStep of jsonLeg.steps.Step) {
|
|
1777
|
+
const stepCoords = parseWKTGeometry(jsonStep.Geometry);
|
|
1778
|
+
stepCoords.forEach((coords, idx) => {
|
|
1779
|
+
if (
|
|
1780
|
+
idx !== 0
|
|
1781
|
+
|| leg.coords.length === 0
|
|
1782
|
+
|| !leg.coords[leg.coords.length - 1].equalsTo(coords)
|
|
1783
|
+
) {
|
|
1784
|
+
leg.coords.push(coords);
|
|
1785
|
+
}
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
const legStep = new Step();
|
|
1790
|
+
legStep.coords = leg.coords[0];
|
|
1791
|
+
legStep._idCoordsInLeg = 0;
|
|
1792
|
+
legStep.name = jsonLeg.Line.Name;
|
|
1793
|
+
legStep.levelChange = null;
|
|
1794
|
+
legStep.distance = jsonLeg.Distance;
|
|
1795
|
+
leg.steps = [legStep];
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
leg.distance = leg.coords.reduce((acc, coords, idx, arr) => {
|
|
1799
|
+
if (idx === 0) {
|
|
1800
|
+
return acc;
|
|
1801
|
+
}
|
|
1802
|
+
return acc + arr[idx - 1].distanceTo(coords);
|
|
1803
|
+
}, 0);
|
|
1804
|
+
|
|
1805
|
+
itinerary.legs.push(leg);
|
|
1806
|
+
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
itinerary.distance = itinerary.coords.reduce((acc, coords, idx, arr) => {
|
|
1810
|
+
if (idx === 0) {
|
|
1811
|
+
return acc;
|
|
1812
|
+
}
|
|
1813
|
+
return acc + arr[idx - 1].distanceTo(coords);
|
|
1814
|
+
}, 0);
|
|
1815
|
+
|
|
1816
|
+
// All legs have to be parsed before computing steps metadata
|
|
1817
|
+
generateStepsMetadata(itinerary);
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
routerResponse.from = routerResponse.itineraries[0].from;
|
|
1821
|
+
routerResponse.to = routerResponse.itineraries[routerResponse.itineraries.length - 1].to;
|
|
1822
|
+
|
|
1823
|
+
return routerResponse;
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
var CitywayUtils = /*#__PURE__*/Object.freeze({
|
|
1600
1827
|
__proto__: null,
|
|
1601
1828
|
jsonToCoordinates: jsonToCoordinates,
|
|
1602
1829
|
createRouterResponseFromJson: createRouterResponseFromJson
|
|
@@ -1771,5 +1998,5 @@ class ItineraryInfoManager {
|
|
|
1771
1998
|
|
|
1772
1999
|
}
|
|
1773
2000
|
|
|
1774
|
-
export { Itinerary, ItineraryInfo, ItineraryInfoManager, Leg, LevelChange, OsmElement, OsmModel, OsmNetworkUtils, OsmNode, OsmParser, OsmRouter, OsmRouterOptions, OsmRouterUtils, OsmWay, OsrmUtils, OtpUtils, RouterResponse, Step };
|
|
2001
|
+
export { CitywayUtils, Itinerary, ItineraryInfo, ItineraryInfoManager, Leg, LevelChange, OsmElement, OsmModel, OsmNetworkUtils, OsmNode, OsmParser, OsmRouter, OsmRouterOptions, OsmRouterUtils, OsmWay, OsrmUtils, OtpUtils, RouterResponse, Step };
|
|
1775
2002
|
//# sourceMappingURL=wemap-osm.es.js.map
|