import { linear } from 'ol/easing';
import { transform } from 'ol/proj';

export function centerAndZoom (map, opts = {}) {
    const transformedCoords = transform([Number(opts.x), Number(opts.y)], 'EPSG:4326', map.getView().getProjection().getCode())
  
    map.getView().setCenter(transformedCoords)
    map.getView().setZoom(opts.zoom)
  
    return transformedCoords
};

export function zoomDelta (map, delta, duration, easing = linear) {
    const newDuration = typeof duration === 'number' ? duration : 350
    const newEasing = typeof duration === 'function' ? duration : easing
    const view = map.getView()
    const currentResolution = view.getResolution()

    if (currentResolution && typeof view.animate === 'function') {
        view.animate({
          zoom: view.getZoom() + delta,
          duration: newDuration,
          easing: newEasing
        });
    }
};
