Skip to content

Commit

Permalink
Merge pull request #2 from Daredzik/feature/truck_restrictions
Browse files Browse the repository at this point in the history
Add truckRestrictions attributes
  • Loading branch information
Daredzik authored Sep 6, 2019
2 parents 3fc2463 + 45a09bb commit 5379887
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 11 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ Since the 1.1.0 version, you can calculate the route witch attributes of the rou

### WARNING
`generateMode` is by default `false` - Leaflet will calculate route using manually inserted mode (default `fastest;car;`)

## TruckRestriction `truckRestriction`
Since the 1.2.0 version, you can calculate the route witch attributes of the truck. To achieve this set `routeRestriction.vehicleType: 'truck'` and fill options under `truckRestriction` object using properties from below.

| Property | Type | HumanType | Min | Max |
| ------ | ---- | --------- | --- | --- |
| height | int | meters | 0 | 50 |
| width | int | meters | 0 | 50 |
| length | int | meters | 0 | 300 |
| limitedWeight| int | tons | 0 | 1000|
| weightPerAxle| int | tons | 0 | 1000|

### WARNING
Property will not be added if its value is empty (`''` or `null`).

When TruckRestrictions are enabled, property `truckType`(read-only) will automatically added to request witch value `'truck'`.
34 changes: 30 additions & 4 deletions dist/lrm-here.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,16 @@ if (typeof module !== 'undefined' && module.exports) {
representation: 'navigation',
mode: this._buildRouteMode(this.options),
alternatives: alternatives
}, this.options.urlParameters), baseUrl);
}, this.options.urlParameters, this._attachTruckRestrictions(this.options)), baseUrl);
},

_buildRouteMode: function(options) {
if (options.generateMode === false) {
return options.mode;
}
const modes = [];
const avoidness = [];
const avoidnessLevel = '-3'; //strictExclude
var modes = [];
var avoidness = [];
var avoidnessLevel = '-3'; //strictExclude

if (options.hasOwnProperty('routeRestriction')
&& options.routeRestriction.hasOwnProperty('routeType')) {
Expand Down Expand Up @@ -380,6 +380,32 @@ if (typeof module !== 'undefined' && module.exports) {
return modes.join(';');
},

_attachTruckRestrictions: function(options) {
var _truckRestrictions = {};
var allowedParameters = ['height', 'width', 'length', 'limitedWeight', 'weightPerAxle'];

if (!options.hasOwnProperty('routeRestriction')
|| !options.hasOwnProperty('truckRestriction')
|| !options.routeRestriction.hasOwnProperty('vehicleType')
|| options.routeRestriction.vehicleType !== 'truck') {
return _truckRestrictions;
}

for (var property in options.truckRestriction) {
if (!options.truckRestriction.hasOwnProperty(property)
|| allowedParameters.indexOf(property) === -1
|| options.truckRestriction[property] === ''
|| options.truckRestriction[property] === null) {
continue;
}

_truckRestrictions[property] = options.truckRestriction[property];
}
_truckRestrictions.truckType = 'truck';

return _truckRestrictions;
},

_convertInstruction: function(instruction, coordinates, startingSearchIndex) {
var i,
distance,
Expand Down
2 changes: 1 addition & 1 deletion dist/lrm-here.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5379887

Please sign in to comment.