proximiio-js-library 1.7.1 → 1.7.2

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.
@@ -466,38 +466,42 @@ export class Wayfinding {
466
466
  }
467
467
 
468
468
  levelChanger.properties.fixedPointMap = new Map();
469
- levelChanger.properties.levels.forEach(level => {
470
- let point = this._copyPoint(levelChanger);
471
- point.properties.level = level;
472
- let fixedPoint = this._getFixPointInArea(point);
473
- fixedPoint.id = levelChanger.id;
474
- fixedPoint.properties.amenity = levelChanger.properties.amenity;
475
- fixedPoint.properties.direction = levelChanger.properties.direction;
476
- fixedPoint.properties.id = levelChanger.properties.id;
477
- fixedPoint.properties.level = level;
478
- fixedPoint.properties.type = levelChanger.properties.type;
479
- if (fixedPoint.properties.neighbours === undefined) fixedPoint.properties.neighbours = [];
480
-
481
- // Do not fix level changers that are further than 5 meters from any path or area
482
- if (this._distance(point, fixedPoint) > 5) {
483
- return;
484
- }
485
-
486
- // Store fixed point into the level changer
487
- levelChanger.properties.fixedPointMap.set(level, fixedPoint);
488
-
489
- // Add neighbourhood for corridor
490
- if (fixedPoint.properties.onCorridor) {
491
- // fixedPoint.properties.neighbours = [...this.corridorLinePointPairs[fixedPoint.properties.corridorIndex], ...segmentIntersectionPointMap.get(fixedPoint.properties.corridorIndex)];
492
- if (fixedPoint.properties.neighboursLeadingTo !== undefined) {
493
- fixedPoint.properties.neighboursLeadingTo.forEach(neighbour => {
494
- if (neighbour.properties.neighbours === undefined) neighbour.properties.neighbours = [];
495
- neighbour.properties.neighbours.push(fixedPoint);
496
- });
497
- this.corridorLineFeatures[fixedPoint.properties.corridorIndex].properties.intersectionPointList.push(fixedPoint);
469
+ if (levelChanger.properties.levels) {
470
+ levelChanger.properties.levels.forEach(level => {
471
+ let point = this._copyPoint(levelChanger);
472
+ point.properties.level = level;
473
+ let fixedPoint = this._getFixPointInArea(point);
474
+ if (fixedPoint) {
475
+ fixedPoint.id = levelChanger.id;
476
+ fixedPoint.properties.amenity = levelChanger.properties.amenity;
477
+ fixedPoint.properties.direction = levelChanger.properties.direction;
478
+ fixedPoint.properties.id = levelChanger.properties.id;
479
+ fixedPoint.properties.level = level;
480
+ fixedPoint.properties.type = levelChanger.properties.type;
481
+ if (fixedPoint.properties.neighbours === undefined) fixedPoint.properties.neighbours = [];
482
+
483
+ // Do not fix level changers that are further than 5 meters from any path or area
484
+ if (this._distance(point, fixedPoint) > 5) {
485
+ return;
486
+ }
487
+
488
+ // Store fixed point into the level changer
489
+ levelChanger.properties.fixedPointMap.set(level, fixedPoint);
490
+
491
+ // Add neighbourhood for corridor
492
+ if (fixedPoint.properties.onCorridor) {
493
+ // fixedPoint.properties.neighbours = [...this.corridorLinePointPairs[fixedPoint.properties.corridorIndex], ...segmentIntersectionPointMap.get(fixedPoint.properties.corridorIndex)];
494
+ if (fixedPoint.properties.neighboursLeadingTo !== undefined) {
495
+ fixedPoint.properties.neighboursLeadingTo.forEach(neighbour => {
496
+ if (neighbour.properties.neighbours === undefined) neighbour.properties.neighbours = [];
497
+ neighbour.properties.neighbours.push(fixedPoint);
498
+ });
499
+ this.corridorLineFeatures[fixedPoint.properties.corridorIndex].properties.intersectionPointList.push(fixedPoint);
500
+ }
501
+ }
498
502
  }
499
- }
500
- });
503
+ });
504
+ }
501
505
  });
502
506
 
503
507
  levelChangerGroupMap.forEach( (lcList, groupId) => {
@@ -1447,100 +1451,101 @@ export class Wayfinding {
1447
1451
 
1448
1452
  _getFixPointInArea(point) {
1449
1453
  let floorData = this.floorData.get(point.properties.level);
1450
-
1451
- // If point is located without accessible area, do nothing
1452
- let areaList = floorData.areas;
1453
- for (let index in areaList) {
1454
- let polygon = areaList[index];
1455
- if (turf.booleanContains(polygon, point)) {
1456
- return point;
1454
+ if (floorData) {
1455
+ // If point is located without accessible area, do nothing
1456
+ let areaList = floorData.areas;
1457
+ for (let index in areaList) {
1458
+ let polygon = areaList[index];
1459
+ if (turf.booleanContains(polygon, point)) {
1460
+ return point;
1461
+ }
1457
1462
  }
1458
- }
1459
1463
 
1460
- // Find nearest wall to stick to
1461
- let bestWall = null;
1462
- let bestWallDistance = Infinity;
1463
- floorData.wallFeatures.forEach(wall => {
1464
- let distance = turf.pointToLineDistance(point.geometry.coordinates, wall, {units: 'meters'});
1465
- if (distance < bestWallDistance) {
1466
- bestWall = wall;
1467
- bestWallDistance = distance;
1468
- }
1469
- });
1464
+ // Find nearest wall to stick to
1465
+ let bestWall = null;
1466
+ let bestWallDistance = Infinity;
1467
+ floorData.wallFeatures.forEach(wall => {
1468
+ let distance = turf.pointToLineDistance(point.geometry.coordinates, wall, {units: 'meters'});
1469
+ if (distance < bestWallDistance) {
1470
+ bestWall = wall;
1471
+ bestWallDistance = distance;
1472
+ }
1473
+ });
1470
1474
 
1471
- let levelCorridorFeatures = this.corridorLineFeatures.filter(corridorLine => corridorLine.properties.level === point.properties.level);
1472
- let bestCorridorIndex = null;
1473
- let bestCorridorDistance = Infinity;
1474
- levelCorridorFeatures.forEach(corridor => {
1475
- let corridorIndex = this.corridorLineFeatures.indexOf(corridor);
1476
- let corridorDistance = turf.pointToLineDistance(point.geometry.coordinates, corridor, {units: 'meters'});
1477
- if (corridorDistance < bestCorridorDistance) {
1478
- bestCorridorIndex = corridorIndex;
1479
- bestCorridorDistance = corridorDistance;
1480
- }
1481
- });
1475
+ let levelCorridorFeatures = this.corridorLineFeatures.filter(corridorLine => corridorLine.properties.level === point.properties.level);
1476
+ let bestCorridorIndex = null;
1477
+ let bestCorridorDistance = Infinity;
1478
+ levelCorridorFeatures.forEach(corridor => {
1479
+ let corridorIndex = this.corridorLineFeatures.indexOf(corridor);
1480
+ let corridorDistance = turf.pointToLineDistance(point.geometry.coordinates, corridor, {units: 'meters'});
1481
+ if (corridorDistance < bestCorridorDistance) {
1482
+ bestCorridorIndex = corridorIndex;
1483
+ bestCorridorDistance = corridorDistance;
1484
+ }
1485
+ });
1482
1486
 
1483
- // Test if area or corridor is closer, create appropriate fixed point
1484
- if (bestWall === null && bestCorridorIndex === null) {
1485
- // could not find neither close area or corridor
1486
- return point;
1487
- } else {
1488
- let fixedPoint;
1487
+ // Test if area or corridor is closer, create appropriate fixed point
1488
+ if (bestWall === null && bestCorridorIndex === null) {
1489
+ // could not find neither close area or corridor
1490
+ return point;
1491
+ } else {
1492
+ let fixedPoint;
1489
1493
 
1490
- // Corridor is closer
1491
- if (bestCorridorIndex !== undefined && bestCorridorDistance < bestWallDistance) {
1494
+ // Corridor is closer
1495
+ if (bestCorridorIndex !== undefined && bestCorridorDistance < bestWallDistance) {
1492
1496
 
1493
- // Create fixed point on line itself
1494
- let line = this.corridorLineFeatures[bestCorridorIndex];
1495
- fixedPoint = turf.nearestPointOnLine(line, point);
1497
+ // Create fixed point on line itself
1498
+ let line = this.corridorLineFeatures[bestCorridorIndex];
1499
+ fixedPoint = turf.nearestPointOnLine(line, point);
1496
1500
 
1497
- // Mark this fixed point is on corridor, preset neighbours
1498
- fixedPoint.properties.onCorridor = true;
1499
- fixedPoint.properties.corridorIndex = bestCorridorIndex;
1500
- if (!fixedPoint.properties.neighbours) {
1501
- fixedPoint.properties.neighbours = [];
1502
- }
1503
- if (this.corridorLineFeatures[bestCorridorIndex].properties.bidirectional != false) {
1504
- fixedPoint.properties.neighbours.push(this.corridorLinePointPairs[bestCorridorIndex][0], this.corridorLinePointPairs[bestCorridorIndex][1]);
1505
- fixedPoint.properties.neighbours.push(...line.properties.intersectionPointList);
1506
- fixedPoint.properties.neighboursLeadingTo = [
1507
- this.corridorLinePointPairs[bestCorridorIndex][0],
1508
- this.corridorLinePointPairs[bestCorridorIndex][1],
1509
- ...line.properties.intersectionPointList
1510
- ];
1511
- } else if (this.corridorLineFeatures[bestCorridorIndex].properties.swapDirection != true) {
1512
- fixedPoint.properties.neighbours.push(this.corridorLinePointPairs[bestCorridorIndex][0]);
1513
- // include only intersection points after this point
1514
- let distance = this._distance(fixedPoint, this.corridorLinePointPairs[bestCorridorIndex][0]);
1515
- let pointsBefore = line.properties.intersectionPointList.filter(point => this._distance(point, this.corridorLinePointPairs[bestCorridorIndex][0]) < distance);
1516
- let pointsAfter = line.properties.intersectionPointList.filter(point => this._distance(point, this.corridorLinePointPairs[bestCorridorIndex][0]) >= distance);
1517
- fixedPoint.properties.neighbours.push(...pointsAfter);
1518
- fixedPoint.properties.neighboursLeadingTo = pointsBefore;
1519
- } else {
1520
- fixedPoint.properties.neighbours.push(this.corridorLinePointPairs[bestCorridorIndex][1]);
1521
- // include only intersection points before this point
1522
- let distance = this._distance(fixedPoint, this.corridorLinePointPairs[bestCorridorIndex][0]);
1523
- let pointsBefore = line.properties.intersectionPointList.filter(point => this._distance(point, this.corridorLinePointPairs[bestCorridorIndex][0]) <= distance);
1524
- let pointsAfter = line.properties.intersectionPointList.filter(point => this._distance(point, this.corridorLinePointPairs[bestCorridorIndex][0]) > distance);
1525
- fixedPoint.properties.neighbours.push(...pointsBefore);
1526
- fixedPoint.properties.neighboursLeadingTo = pointsAfter;
1527
- }
1501
+ // Mark this fixed point is on corridor, preset neighbours
1502
+ fixedPoint.properties.onCorridor = true;
1503
+ fixedPoint.properties.corridorIndex = bestCorridorIndex;
1504
+ if (!fixedPoint.properties.neighbours) {
1505
+ fixedPoint.properties.neighbours = [];
1506
+ }
1507
+ if (this.corridorLineFeatures[bestCorridorIndex].properties.bidirectional != false) {
1508
+ fixedPoint.properties.neighbours.push(this.corridorLinePointPairs[bestCorridorIndex][0], this.corridorLinePointPairs[bestCorridorIndex][1]);
1509
+ fixedPoint.properties.neighbours.push(...line.properties.intersectionPointList);
1510
+ fixedPoint.properties.neighboursLeadingTo = [
1511
+ this.corridorLinePointPairs[bestCorridorIndex][0],
1512
+ this.corridorLinePointPairs[bestCorridorIndex][1],
1513
+ ...line.properties.intersectionPointList
1514
+ ];
1515
+ } else if (this.corridorLineFeatures[bestCorridorIndex].properties.swapDirection != true) {
1516
+ fixedPoint.properties.neighbours.push(this.corridorLinePointPairs[bestCorridorIndex][0]);
1517
+ // include only intersection points after this point
1518
+ let distance = this._distance(fixedPoint, this.corridorLinePointPairs[bestCorridorIndex][0]);
1519
+ let pointsBefore = line.properties.intersectionPointList.filter(point => this._distance(point, this.corridorLinePointPairs[bestCorridorIndex][0]) < distance);
1520
+ let pointsAfter = line.properties.intersectionPointList.filter(point => this._distance(point, this.corridorLinePointPairs[bestCorridorIndex][0]) >= distance);
1521
+ fixedPoint.properties.neighbours.push(...pointsAfter);
1522
+ fixedPoint.properties.neighboursLeadingTo = pointsBefore;
1523
+ } else {
1524
+ fixedPoint.properties.neighbours.push(this.corridorLinePointPairs[bestCorridorIndex][1]);
1525
+ // include only intersection points before this point
1526
+ let distance = this._distance(fixedPoint, this.corridorLinePointPairs[bestCorridorIndex][0]);
1527
+ let pointsBefore = line.properties.intersectionPointList.filter(point => this._distance(point, this.corridorLinePointPairs[bestCorridorIndex][0]) <= distance);
1528
+ let pointsAfter = line.properties.intersectionPointList.filter(point => this._distance(point, this.corridorLinePointPairs[bestCorridorIndex][0]) > distance);
1529
+ fixedPoint.properties.neighbours.push(...pointsBefore);
1530
+ fixedPoint.properties.neighboursLeadingTo = pointsAfter;
1531
+ }
1528
1532
 
1529
- // Wall is closer
1530
- } else if (bestWall !== null) {
1533
+ // Wall is closer
1534
+ } else if (bestWall !== null) {
1531
1535
 
1532
- // Create fixed point inside area
1533
- let nearestPoint = turf.nearestPointOnLine(bestWall, point);
1534
- let bearing = turf.bearing(point, nearestPoint);
1535
- fixedPoint = turf.destination(point.geometry.coordinates, bestWallDistance + 0.05, bearing, {units: 'meters'});
1536
- }
1536
+ // Create fixed point inside area
1537
+ let nearestPoint = turf.nearestPointOnLine(bestWall, point);
1538
+ let bearing = turf.bearing(point, nearestPoint);
1539
+ fixedPoint = turf.destination(point.geometry.coordinates, bestWallDistance + 0.05, bearing, {units: 'meters'});
1540
+ }
1537
1541
 
1538
- // Mark level of fixed point
1539
- fixedPoint.properties.level = point.properties.level;
1542
+ // Mark level of fixed point
1543
+ fixedPoint.properties.level = point.properties.level;
1540
1544
 
1541
- // Return created point
1542
- return fixedPoint;
1545
+ // Return created point
1546
+ return fixedPoint;
1543
1547
 
1548
+ }
1544
1549
  }
1545
1550
  }
1546
1551