How to use the @terrestris/base-util/dist/MathUtil/MathUtil.mod function in @terrestris/base-util

To help you get started, we’ve selected a few @terrestris/base-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terrestris / react-geo / src / Button / GeoLocationButton / GeoLocationButton.tsx View on Github external
onGeolocationChange = () => {
    const position = this._geoLocationInteraction.getPosition();
    const accuracy = this._geoLocationInteraction.getAccuracy();
    let heading = this._geoLocationInteraction.getHeading() || 0;
    const speed = this._geoLocationInteraction.getSpeed() || 0;

    const x = position[0];
    const y = position[1];
    const fCoords = this._positions.getCoordinates();
    const previous = fCoords[fCoords.length - 1];
    const prevHeading = previous && previous[2];
    if (prevHeading) {
      let headingDiff = heading - MathUtil.mod(prevHeading);

      // force the rotation change to be less than 180°
      if (Math.abs(headingDiff) > Math.PI) {
        var sign = (headingDiff >= 0) ? 1 : -1;
        headingDiff = -sign * (2 * Math.PI - Math.abs(headingDiff));
      }
      heading = prevHeading + headingDiff;
    }
    this._positions.appendCoordinate([x, y, heading, Date.now()]);

    // only keep the 20 last coordinates
    this._positions.setCoordinates(this._positions.getCoordinates().slice(-20));

    this.updateView();

    this.props.onGeolocationChange({