import React, { useEffect, useRef, useState } from “react”
import { observer } from “mobx-react”
import { toJS } from “mobx”
import { Scene, PolygonLayer, LineLayer, MarkerLayer, Marker } from “@antv/l7”
import { GaodeMap } from “@antv/l7-maps”
import $state from “./state”
const L7map = () => {
//利用useRef可以跨生命周期的特性,定义标识,为true标识添加过一次图层,就不继续添加图层了
const mapIsInited = useRef()
//销毁时重置标识
useEffect(() => {
$state.query_city_list() //查询城市名借口
return () => {
mapIsInited.current = false
}
}, [])
//查询到城市名后加载L7地图
useEffect(() => {
gaodeMapInit($state.cityList)
mapIsInited.current = true
}, [$state.cityList])
const gaodeMapInit = (citys) => {
//定义地图
const scene = new Scene({
id: 'l7-map-id',
logoVisible: 'normal',
map: new GaodeMap.Map({
pitch: 0,
style: 'narmal&#