Skip to content

Commit 314ccb4

Browse files
committed
refactor: enhance implementation of resetControl
1 parent e60c7cc commit 314ccb4

4 files changed

Lines changed: 68 additions & 59 deletions

File tree

example/src/pages/api/fengmap-resetcontrol/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class FengmapResetControlDoc extends Component {
1515
render() {
1616
const { screenWidth } = this.props
1717
const contentWidth = screenWidth > 1000 ? screenWidth - 280 - 24 * 4 - 40 : screenWidth
18-
console.log(fengmapSDK.controlPositon.RIGHT_BOTTOM)
1918
return (
2019
<React.Fragment>
2120
<Highlight language="jsx">
@@ -50,11 +49,6 @@ class FengmapResetControlDoc extends Component {
5049
</a>
5150
</React.Fragment>
5251
)
53-
},
54-
{
55-
prop: 'delayed',
56-
type: 'number',
57-
description: <React.Fragment>延时点击时间,属于ctrlOpts中的属性</React.Fragment>
5852
}
5953
]}
6054
/>
@@ -121,8 +115,7 @@ export default function Example(props) {
121115
<FengmapResetControl
122116
ctrlOptions={{
123117
position: fengmapSDK.controlPositon.LEFT_TOP,
124-
imgURL: resolvePublicPath('/assets/reset.png'),
125-
delayed:5000
118+
imgURL: resolvePublicPath('/assets/reset.png')
126119
}}
127120
/>
128121
)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-fengmap",
3-
"version": "2.8.0",
3+
"version": "2.9.0",
44
"description": "",
55
"author": "Howard.Zuo",
66
"typings": "typings/index.d.ts",

src/FengmapBase.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,41 @@ class FengmapBase extends Component {
6868
}
6969

7070
_loadMap = mapId => {
71-
const { mapOptions, events, fengmapSDK } = this.props
72-
if (!mapId || !fengmapSDK || isOrderIE()) {
73-
return
74-
}
75-
if (this.mapInstance) {
76-
this.mapContainer.current.innerHTML = ''
77-
}
78-
this.mapInstance = new fengmapSDK.FMMap(Object.assign({}, mapOptions, { container: this.mapContainer.current }))
79-
EVENTS.forEach(e => {
80-
this.mapInstance.on(e, event => {
81-
if (e === 'loadComplete') {
82-
this.loadingTxt.current.style['zIndex'] = -10
83-
this._configGestureEnableController()
84-
this._initAllChildren(this.mapInstance)
85-
initFloorsToMapInstance(this.mapInstance)
86-
}
87-
88-
if (events && events[e]) {
89-
events[e](event, this.mapInstance)
90-
}
91-
if (!this.mapInstance) {
92-
return
93-
}
94-
if (events && events.mapHoverNode) {
95-
this.mapInstance.gestureEnableController.enableMapHover = true
96-
} else {
97-
this.mapInstance.gestureEnableController.enableMapHover = false
98-
}
71+
return new Promise((resolve, reject) => {
72+
const { mapOptions, events, fengmapSDK } = this.props
73+
if (!mapId || !fengmapSDK || isOrderIE()) {
74+
return resolve()
75+
}
76+
if (this.mapInstance) {
77+
this.mapContainer.current.innerHTML = ''
78+
}
79+
this.mapInstance = new fengmapSDK.FMMap(Object.assign({}, mapOptions, { container: this.mapContainer.current }))
80+
EVENTS.forEach(e => {
81+
this.mapInstance.on(e, event => {
82+
if (e === 'loadComplete') {
83+
this.loadingTxt.current.style['zIndex'] = -10
84+
this._configGestureEnableController()
85+
this._initAllChildren(this.mapInstance)
86+
initFloorsToMapInstance(this.mapInstance)
87+
resolve()
88+
}
89+
90+
if (events && events[e]) {
91+
events[e](event, this.mapInstance)
92+
}
93+
if (!this.mapInstance) {
94+
return
95+
}
96+
if (events && events.mapHoverNode) {
97+
this.mapInstance.gestureEnableController.enableMapHover = true
98+
} else {
99+
this.mapInstance.gestureEnableController.enableMapHover = false
100+
}
101+
})
99102
})
100-
})
101103

102-
this.mapInstance.openMapById(mapId)
104+
this.mapInstance.openMapById(mapId)
105+
})
103106
}
104107

105108
_configGestureEnableController = () => {

src/controls/FengmapResetControl.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import FengmapBaseControl from '../bases/FengmapBaseControl'
33
import PropTypes from 'prop-types'
4+
45
const RESET_STYLE = {
56
position: 'absolute',
67
width: '42PX',
@@ -10,7 +11,7 @@ const RESET_STYLE = {
1011
cursor: 'pointer',
1112
backgroundColor: '#fff'
1213
}
13-
let clickMark = true
14+
1415
class FengmapResetControl extends FengmapBaseControl {
1516
static propTypes = {
1617
ctrlOptions: PropTypes.shape({
@@ -21,53 +22,65 @@ class FengmapResetControl extends FengmapBaseControl {
2122
})
2223
}).isRequired
2324
}
25+
2426
constructor(props) {
2527
super(props)
2628
this.state = {
2729
ctrlOptions: null,
28-
parent: null
30+
parent: null,
31+
map: null
2932
}
33+
this.btnRef = React.createRef()
3034
}
35+
3136
load = (map, fengmapSDK, parent) => {
3237
const { ctrlOptions } = this.props
3338
this.setState({
39+
map,
3440
ctrlOptions,
3541
parent
3642
})
3743
}
44+
3845
resetMap = () => {
39-
const {
40-
parent,
41-
ctrlOptions: { delayed }
42-
} = this.state
43-
if (parent && clickMark) {
44-
clickMark = false
45-
parent._loadMap(parent.props.mapId)
46-
setTimeout(() => {
47-
clickMark = true
48-
}, delayed || 10000)
49-
}
46+
const original = this.btnRef.current.style['pointer-events'] || 'auto'
47+
this.btnRef.current.style['pointer-events'] = 'none'
48+
49+
const { parent } = this.state
50+
51+
parent._destroy()
52+
parent._loadMap(parent.props.mapId).then(() => {
53+
this.btnRef.current.style['pointer-events'] = original
54+
})
5055
}
56+
5157
render() {
52-
const { ctrlOptions } = this.state
53-
let resetPosition = ''
54-
if (ctrlOptions) {
55-
resetPosition = setResetPosition(ctrlOptions)
58+
const { ctrlOptions, map } = this.state
59+
if (!map) {
60+
return null
5661
}
57-
return <div onClick={this.resetMap} style={Object.assign({}, RESET_STYLE, resetPosition)} />
62+
return (
63+
<div
64+
ref={this.btnRef}
65+
onClick={this.resetMap}
66+
style={Object.assign({}, RESET_STYLE, getResetPosition(ctrlOptions))}
67+
/>
68+
)
5869
}
5970
}
6071

6172
export default FengmapResetControl
62-
function setResetPosition(ctrlOptions) {
73+
74+
function getResetPosition(ctrlOptions) {
6375
let x = 0
6476
let y = 0
6577
const { position } = ctrlOptions
6678
if (ctrlOptions.hasOwnProperty('offset')) {
6779
x = ctrlOptions.offset.x
6880
y = ctrlOptions.offset.y
6981
}
70-
let { imgURL } = ctrlOptions
82+
83+
const { imgURL } = ctrlOptions
7184

7285
switch (position) {
7386
case 1:

0 commit comments

Comments
 (0)