import { clamp } from '@math.gl/core';
import Controller from './controller';
import { MapState } from './map-controller';
import { mod } from '../utils/math-utils';
import LinearInterpolator from '../transitions/linear-interpolator';

class GlobeState extends MapState {
  applyConstraints(props) {
    const {
      maxZoom,
      minZoom,
      zoom
    } = props;
    props.zoom = clamp(zoom, minZoom, maxZoom);
    const {
      longitude,
      latitude
    } = props;

    if (longitude < -180 || longitude > 180) {
      props.longitude = mod(longitude + 180, 360) - 180;
    }

    props.latitude = clamp(latitude, -89, 89);
    return props;
  }

}

export default class GlobeController extends Controller {
  constructor(...args) {
    super(...args);
    this.ControllerState = GlobeState;
    this.transition = {
      transitionDuration: 300,
      transitionInterpolator: new LinearInterpolator(['longitude', 'latitude', 'zoom'])
    };
    this.dragMode = 'pan';
  }

  setProps(props) {
    super.setProps(props);
    this.dragRotate = false;
    this.touchRotate = false;
  }

}
//# sourceMappingURL=globe-controller.js.map