@ -5,13 +5,15 @@ import { useState } from 'react';
import { DatePicker } from 'antd' ;
import Bounds from './bounds' ;
import moment from 'moment' ;
import { getReportList } from '../../actions/patrol'
const { RangePicker } = DatePicker ;
function PatrolGis ( props ) {
const { reportList , userId , dispatch } = props ;
const [ mapComplete , setMapComplete ] = useState ( false ) ;
const [ mapObj , setMapObj ] = useState ( ) ;
const [ dateRange , setDateRange ] = useState ( ) ;
let markers = [ ] ;
let PATH = [ ] ;
useEffect ( ( ) => {
if ( AMap ) loadMap ( ) ;
return ( ) => {
@ -24,8 +26,20 @@ function PatrolGis(props) {
} , [ true ] )
useEffect ( ( ) => {
if ( mapObj ) {
mapObj . remove ( markers ) ;
mapObj . remove ( PATH ) ;
}
let query = { userId , reportType : 'patrol' }
if ( userId ) {
if ( ( dateRange && dateRange instanceof Array ) ) {
query . startTime = moment ( dateRange [ 0 ] ) . startOf ( 'day' ) . format ( 'YYYY-MM-DD HH:mm:ss' )
query . endTime = moment ( dateRange [ 1 ] ) . endOf ( 'day' ) . format ( 'YYYY-MM-DD HH:mm:ss' )
}
dispatch ( getReportList ( query ) ) ;
} else {
query . isTop = true ;
dispatch ( getReportList ( query ) ) ;
}
} , [ userId , dateRange ] )
@ -91,6 +105,7 @@ function PatrolGis(props) {
}
} ) ;
// marker.setTitle(s.name);
markers . push ( marker ) ;
map . add ( marker ) ;
} )
}
@ -111,6 +126,7 @@ function PatrolGis(props) {
if ( longitude && latitude )
path . push ( [ item . longitude , item . latitude ] )
} ) ;
PATH = path ;
var polyline1 = new AMap . Polyline ( {
map : map ,
path : path , // 设置线覆盖物路径
@ -122,9 +138,13 @@ function PatrolGis(props) {
}
return (
< div style = { { width : '100%' , backgroundColor : '#101824' , height : '100%' , minHeight : 700 } } >
< div style = { { width : '100%' , backgroundColor : '#101824' , height : '100%' , minHeight : 700 , position : 'relative' } } >
< div id = 'amapId' style = { { width : '100%' , height : '100%' , background : "#101824" , minHeight : 700 } } / >
< RangePicker onChange = { ( date , dateString ) => { setDateRange ( dateString ) } } / >
< div style = { { position : 'absolute' , top : 8 , left : 20 , display : userId ? 'block' : 'none' } } >
< RangePicker
onChange = { ( date , dateString ) => { setDateRange ( dateString ) } }
/ >
< / d i v >
{ mapObj ? < Bounds map = { mapObj } / > : '' }
< / d i v >
)