Source: bemap-services-v2/routing/bemap-routing-destination.js

/**
 * BeNomad BeMap JavaScript API - RoutingDestination
 *
 * One point in a routing request (origin, intermediate via, or final
 * destination). The order in `RoutingRequest.destinations` is significant:
 * the first is the start, the last is the end, anything between is a via.
 *
 * Wire shape mirrors the BeMap server contract (cross-checked against
 * `bemap-flutter-api/lib/service/routing/model/request/routing_destination.dart`):
 *
 *   { coordinateSat, radius?, ignorePoint?, ignoreTrafficDirections?,
 *     ignoreRoadBlocks?, ignoreRestrictions?, avoidUTurn?, useStartAngle?,
 *     useStopRoadSide?, keptByMinimalWp?, customData? }
 *
 * The constructor is tolerant: pass a `bemap.Coordinate`, a
 * `bemap.CoordinateSat`, or a plain `{lon, lat, ...}` object — it is
 * auto-promoted to `bemap.CoordinateSat`.
 *
 * @since 1.5.0
 * @public
 * @constructor
 * @param {Object} [options]
 * @param {bemap.CoordinateSat|bemap.Coordinate|Object} [options.coordinateSat]
 * @param {Number} [options.radius]                    Maximum snap radius in metres.
 * @param {Boolean} [options.ignorePoint]              Skip this waypoint in the calculation.
 * @param {Boolean} [options.ignoreTrafficDirections]  Ignore one-way / turn restrictions before next waypoint.
 * @param {Boolean} [options.ignoreRoadBlocks]         Ignore road blocks before next waypoint.
 * @param {Boolean} [options.ignoreRestrictions]       Ignore forbidden manoeuvres before next waypoint.
 * @param {Object|String} [options.avoidUTurn]         RoutingDestinationStatus passthrough.
 * @param {Object|String} [options.useStartAngle]      RoutingDestinationStatus passthrough.
 * @param {Object|String} [options.useStopRoadSide]    RoutingDestinationStatus passthrough.
 * @param {Boolean} [options.keptByMinimalWp]          Keep waypoint in response when NO_MINIMAL_WAYPOINTS is not set. (Backend field `mandatory`; both accepted via alias.)
 * @param {Number} [options.stopDuration]              Dwell/stop time at this waypoint, in seconds.
 * @param {Array.<Object>} [options.customData]        Custom key/value pairs.
 */
bemap.RoutingDestination = function(options) {
    var opts = options || {};

    this.coordinateSat = bemap.RoutingDestination._coerceCoordinateSat(opts.coordinateSat);
    this.radius = (typeof opts.radius === 'number') ? opts.radius : null;
    this.ignorePoint = (typeof opts.ignorePoint === 'boolean') ? opts.ignorePoint : null;
    this.ignoreTrafficDirections = (typeof opts.ignoreTrafficDirections === 'boolean') ? opts.ignoreTrafficDirections : null;
    this.ignoreRoadBlocks = (typeof opts.ignoreRoadBlocks === 'boolean') ? opts.ignoreRoadBlocks : null;
    this.ignoreRestrictions = (typeof opts.ignoreRestrictions === 'boolean') ? opts.ignoreRestrictions : null;
    this.avoidUTurn = opts.avoidUTurn || null;
    this.useStartAngle = opts.useStartAngle || null;
    this.useStopRoadSide = opts.useStopRoadSide || null;
    this.keptByMinimalWp = (typeof opts.keptByMinimalWp === 'boolean') ? opts.keptByMinimalWp : null;
    this.stopDuration = (typeof opts.stopDuration === 'number') ? opts.stopDuration : null;
    this.customData = Array.isArray(opts.customData) ? opts.customData.slice() : null;
};

/** @private */
bemap.RoutingDestination._coerceCoordinateSat = function(input) {
    if (!input) return null;
    if (input instanceof bemap.CoordinateSat) return input;
    if (input instanceof bemap.Coordinate) {
        return new bemap.CoordinateSat({ lon: input.lon, lat: input.lat });
    }
    if (typeof input.lon === 'number' && typeof input.lat === 'number') {
        return new bemap.CoordinateSat({
            lon: input.lon, lat: input.lat,
            alt: input.alt, heading: input.heading, speed: input.speed,
            time: input.time,
            satellites: (input.sat !== undefined) ? input.sat : input.satellites
        });
    }
    return null;
};

bemap.RoutingDestination.prototype.setCoordinateSat = function(v) {
    this.coordinateSat = bemap.RoutingDestination._coerceCoordinateSat(v);
    return this;
};
bemap.RoutingDestination.prototype.setRadius = function(v) { this.radius = v; return this; };
bemap.RoutingDestination.prototype.setKeptByMinimalWp = function(v) { this.keptByMinimalWp = !!v; return this; };
bemap.RoutingDestination.prototype.setStopDuration = function(v) { this.stopDuration = (typeof v === 'number') ? v : null; return this; };
bemap.RoutingDestination.prototype.setIgnorePoint = function(v) { this.ignorePoint = (typeof v === 'boolean') ? v : null; return this; };
bemap.RoutingDestination.prototype.setIgnoreTrafficDirections = function(v) { this.ignoreTrafficDirections = (typeof v === 'boolean') ? v : null; return this; };
bemap.RoutingDestination.prototype.setIgnoreRoadBlocks = function(v) { this.ignoreRoadBlocks = (typeof v === 'boolean') ? v : null; return this; };
bemap.RoutingDestination.prototype.setIgnoreRestrictions = function(v) { this.ignoreRestrictions = (typeof v === 'boolean') ? v : null; return this; };
bemap.RoutingDestination.prototype.setAvoidUTurn = function(v) { this.avoidUTurn = v || null; return this; };
bemap.RoutingDestination.prototype.setUseStartAngle = function(v) { this.useStartAngle = v || null; return this; };
bemap.RoutingDestination.prototype.setUseStopRoadSide = function(v) { this.useStopRoadSide = v || null; return this; };
bemap.RoutingDestination.prototype.setCustomData = function(a) { this.customData = Array.isArray(a) ? a.slice() : null; return this; };

bemap.RoutingDestination.prototype.toJson = function() {
    var out = {};
    if (this.coordinateSat) out.coordinateSat = this.coordinateSat.toJson();
    if (this.radius !== null) out.radius = this.radius;
    if (this.ignorePoint !== null) out.ignorePoint = this.ignorePoint;
    if (this.ignoreTrafficDirections !== null) out.ignoreTrafficDirections = this.ignoreTrafficDirections;
    if (this.ignoreRoadBlocks !== null) out.ignoreRoadBlocks = this.ignoreRoadBlocks;
    if (this.ignoreRestrictions !== null) out.ignoreRestrictions = this.ignoreRestrictions;
    if (this.avoidUTurn !== null) out.avoidUTurn = this.avoidUTurn;
    if (this.useStartAngle !== null) out.useStartAngle = this.useStartAngle;
    if (this.useStopRoadSide !== null) out.useStopRoadSide = this.useStopRoadSide;
    if (this.keptByMinimalWp !== null) out.keptByMinimalWp = this.keptByMinimalWp;
    if (this.stopDuration !== null) out.stopDuration = this.stopDuration;
    if (this.customData && this.customData.length) out.customData = this.customData.slice();
    return out;
};