import { zoomAnimationDuraton } from '../config';
import EventEmitter from 'eventemitter3';
import { LocationManager } from './LocationManager';
export class Map {
  emitter = new EventEmitter();
  get locationManager() {
    return this.locManager;
  }
  constructor(map) {
    if (map) {
      this.map = map;
    }
    this.locManager = new LocationManager();
  }
  async getCenter() {
    return await this.map?.getCenter();
  }
  async getPointInView(location) {
    return await this.map?.getPointInView(location);
  }
  async getCoordinateFromView(location) {
    return await this.map?.getCoordinateFromView(location);
  }
  async getVisibleBounds() {
    const bounds = await this.map?.getVisibleBounds();
    return bounds;
  }
  off(event, listener) {
    this.emitter.off(event, listener);
  }
  on(event, listener) {
    this.emitter.on(event, listener);
  }
  emit(event, ...args) {
    this.emitter.emit(event, ...args);
  }
  async getZoom() {
    return await this.map?.getZoom();
  }
  setMap(map) {
    this.map = map;
  }
  setCamera(rnCamera) {
    this.camera = rnCamera;
  }
  setCenter(location) {
    this.camera?.moveTo(location);
  }
  setSourceVisibility(visible, sourceId, sourceLayerId) {
    this.map?.setSourceVisibility(visible, sourceId, sourceLayerId);
  }
  async zoomTo(step, duration) {
    const zoom = await this.map?.getZoom();
    this.camera?.zoomTo(zoom + step, duration !== undefined ? duration : zoomAnimationDuraton);
  }
  async flyTo(center, duration) {
    duration = duration !== undefined ? duration : 100;
    this.camera?.flyTo(center, duration);
  }

  /**
   * 按来源查询feature集合
   *
   * @param sourceId
   * @param filter FilterExpression
   * @param layerIDs 图层ID
   * @returns Promise<GeoJSON.FeatureCollection>
   */
  async querySourceFeatures(sourceId, filter = [], layerIDs = []) {
    const features = (await this.map?.querySourceFeatures(sourceId, filter, layerIDs))?.features || [];
    return {
      type: 'FeatureCollection',
      features
    };
  }

  /**
   * 按bbox查询可视区域feature集合
   *
   * @param bbox 查询范围，像素坐标范围
   * @param filter FilterExpression
   * @param layerIDs 图层ID
   * @returns Promise<GeoJSON.FeatureCollection>
   */
  async queryRenderFeatures(bbox, filter = [], layerIDs) {
    const features = (await this.map?.queryRenderedFeaturesInRect(bbox, filter, layerIDs))?.features || [];
    return {
      type: 'FeatureCollection',
      features
    };
  }
  updateStyle(style) {}
}
//# sourceMappingURL=Map.js.map