Skip to content

Commit

Permalink
feat: remove map options & add callback options
Browse files Browse the repository at this point in the history
  • Loading branch information
yue1123 committed Nov 16, 2022
1 parent 79dd423 commit f519946
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions packages/hooks/useIpLocation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref, watch } from 'vue'
import { ref, Ref } from 'vue'
import { Point } from './usePoint'

interface Location {
Expand All @@ -9,34 +9,20 @@ interface Location {
/**
* ip定位
*/
export function useIpLocation(map?: any) {
export function useIpLocation(cal?: (location: Ref<Location>) => void) {
const location = ref<Location>({} as Location)
const isLoading = ref<boolean>(true)

let mapComponentInstance: any
map &&
watch(
() => map.value,
(n) => {
mapComponentInstance = n
}
)

const init = () => {
isLoading.value = true
const options: Record<string, any> = {}
if (map) {
options.renderOptions = {
map: mapComponentInstance.getMapInstance()
}
}

new BMapGL.LocalCity(options).get((res: any) => {
new BMapGL.LocalCity().get((res: any) => {
isLoading.value = false
res.point = res.center
Reflect.deleteProperty(res, 'level')
Reflect.deleteProperty(res, 'center')
location.value = res
location.value = {
code: res.code,
point: res.center,
name: res.name
}
cal && cal(location)
})
}

Expand Down

0 comments on commit f519946

Please sign in to comment.