All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.maplibre.geojson.shifter.CoordinateShifterManager Maven / Gradle / Ivy

There is a newer version: 6.0.1
Show newest version
package org.maplibre.geojson.shifter;

import org.maplibre.geojson.Point;

import java.util.Arrays;
import java.util.List;

/**
 * CoordinateShifterManager keeps track of currently set CoordinateShifter.
 *
 * @since 4.2.0
 */
public final class CoordinateShifterManager {

  private static final CoordinateShifter DEFAULT = new CoordinateShifter() {
    @Override
    public List shiftLonLat(double lon, double lat) {
      return Arrays.asList(lon, lat);
    }

    @Override
    public List shiftLonLatAlt(double lon, double lat, double alt) {
      return Double.isNaN(alt)
              ? Arrays.asList(lon, lat) :
              Arrays.asList(lon, lat, alt);
    }

    @Override
    public List unshiftPoint(Point point) {
      return point.coordinates();
    }

    @Override
    public List unshiftPoint(List coordinates) {
      return coordinates;
    }
  };

  private static volatile CoordinateShifter coordinateShifter = DEFAULT;

  /**
   * Currently set CoordinateShifterManager.
   *
   * @return Currently set CoordinateShifterManager
   * @since 4.2.0
   */
  public static CoordinateShifter getCoordinateShifter() {
    return coordinateShifter;
  }

  /**
   * Sets CoordinateShifterManager.
   *
   * @param coordinateShifter CoordinateShifterManager to be set
   * @since 4.2.0
   */
  public static void setCoordinateShifter(CoordinateShifter coordinateShifter) {
    CoordinateShifterManager.coordinateShifter =
      coordinateShifter == null ? DEFAULT : coordinateShifter;
  }

  /**
   * Check whether the current shifter is the default one.
   * @return true if using default shifter.
   */
  public static boolean isUsingDefaultShifter() {
    return coordinateShifter == DEFAULT;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy