@wemap/routers 11.0.0-alpha.15 → 11.0.0-alpha.18

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/index.mjs CHANGED
@@ -11,7 +11,6 @@ import Logger from "@wemap/logger";
11
11
  import Polyline from "@mapbox/polyline";
12
12
  import pointInPolygon from "@turf/boolean-point-in-polygon";
13
13
  import convexHullFn from "@turf/convex";
14
- import { polygon } from "@turf/helpers";
15
14
  function getDurationFromLength(length, speed = 5) {
16
15
  return length / (speed * 1e3 / 3600);
17
16
  }
@@ -1637,7 +1636,7 @@ class WemapMultiRouter {
1637
1636
  }
1638
1637
  let ioMapItinerary;
1639
1638
  const mapWithStart = ioMapsToTest.find((map) => map.isPointInside(start));
1640
- const wemapOsmRouterOptions = !options || !("useStairs" in options) && options.useStairs ? WemapOsmRouterOptions.DEFAULT : WemapOsmRouterOptions.WITHOUT_STAIRS;
1639
+ const wemapOsmRouterOptions = !options || !("useStairs" in options) || options.useStairs ? WemapOsmRouterOptions.DEFAULT : WemapOsmRouterOptions.WITHOUT_STAIRS;
1641
1640
  if (mapWithStart && mapWithStart.isPointInside(end)) {
1642
1641
  try {
1643
1642
  ioMapItinerary = mapWithStart.getItineraryInsideMap(start, end, wemapOsmRouterOptions);
@@ -1786,14 +1785,17 @@ class CustomNetworkMap {
1786
1785
  });
1787
1786
  this.entryPoints = entryPoints;
1788
1787
  if (bounds) {
1789
- this.bounds = polygon([bounds.map((coords) => [coords.lng, coords.lat])]);
1788
+ this.bounds = bounds;
1790
1789
  } else {
1791
- const polygon2 = [network.nodes.map((node) => [node.coords.lng, node.coords.lat])];
1792
- const convexHull = convexHullFn({ type: "polygon", coordinates: polygon2 });
1790
+ const polygon = [network.nodes.map((node) => [node.coords.lng, node.coords.lat])];
1791
+ const convexHull = convexHullFn({ type: "polygon", coordinates: polygon });
1793
1792
  if (!convexHull) {
1794
1793
  throw new Error(`Cannot calculate convexHull of network "${name}"`);
1795
1794
  }
1796
- this.bounds = convexHull;
1795
+ this.bounds = {
1796
+ type: "MultiPolygon",
1797
+ coordinates: [convexHull.geometry.coordinates]
1798
+ };
1797
1799
  }
1798
1800
  }
1799
1801
  static fromOsmXml(osmXmlString, name = null) {
@@ -1803,11 +1805,25 @@ class CustomNetworkMap {
1803
1805
  if (entryPoints.some((el) => el === null) || new Set(entryPoints).size !== entryPoints.length) {
1804
1806
  throw new Error("Cannot parse wemap:routing-io correctly");
1805
1807
  }
1806
- const wayBounds = osmModel.ways.find(({ tags }) => tags["wemap:routing-bounds"]);
1807
- if (!wayBounds) {
1808
+ const bounds = {
1809
+ type: "MultiPolygon",
1810
+ coordinates: []
1811
+ };
1812
+ osmModel.ways.filter(({ tags }) => tags["wemap:routing-bounds"]).forEach((way) => {
1813
+ bounds.coordinates.push([
1814
+ way.nodes.reduce((acc, node) => {
1815
+ acc.push([node.coords.lng, node.coords.lat]);
1816
+ return acc;
1817
+ }, [])
1818
+ ]);
1819
+ });
1820
+ osmModel.relations.filter((rel) => rel.tags["wemap:routing-bounds"] && rel.isMultipolygon()).forEach((rel) => {
1821
+ const polygon = rel.getGeoJsonPolygon();
1822
+ polygon && bounds.coordinates.push(polygon.coordinates);
1823
+ });
1824
+ if (!bounds.coordinates.length) {
1808
1825
  throw new Error('Search bounds is undefined. Please use OSM tag : "wemap:routing-bounds=yes"');
1809
1826
  }
1810
- const bounds = wayBounds.nodes.map((node) => node.coords);
1811
1827
  return new CustomNetworkMap(network, entryPoints, bounds, name);
1812
1828
  }
1813
1829
  isPointInside(coordinates) {