map.js 996 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import {
  findRefById,
  invokeVmMethod,
  invokeVmMethodWithoutArgs
} from '../util'

class MapContext {
  constructor (id, ctx) {
    this.id = id
    this.ctx = ctx
  }

  getCenterLocation (cbs) {
    return invokeVmMethodWithoutArgs(this.ctx, 'getCenterLocation', cbs)
  }

  moveToLocation () {
    return invokeVmMethodWithoutArgs(this.ctx, 'moveToLocation')
  }

  translateMarker (args) {
    return invokeVmMethod(this.ctx, 'translateMarker', args, ['animationEnd'])
  }

  includePoints (args) {
    return invokeVmMethod(this.ctx, 'includePoints', args)
  }

  getRegion (cbs) {
    return invokeVmMethodWithoutArgs(this.ctx, 'getRegion', cbs)
  }

  getScale (cbs) {
    return invokeVmMethodWithoutArgs(this.ctx, 'getScale', cbs)
  }
}

export function createMapContext (id, vm) {
  const ref = findRefById(id, vm)
  if (!ref) {
    global.nativeLog('Can not find `' + id + '`', '__WARN')
  }
  return new MapContext(id, vm.$refs[ref])
}