Skip to content

Commit d05e2c7

Browse files
committed
fix: error occured while resetControl button is called frequently
1 parent 314ccb4 commit d05e2c7

6 files changed

Lines changed: 34 additions & 8 deletions

File tree

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.9.0",
3+
"version": "2.9.1",
44
"description": "",
55
"author": "Howard.Zuo",
66
"typings": "typings/index.d.ts",

src/FengmapBase.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ class FengmapBase extends Component {
125125
})
126126
}
127127

128+
_destroyAllChildren = map => {
129+
const { fengmapSDK } = this.props
130+
const { refs } = this
131+
if (!isArray(refs)) {
132+
return
133+
}
134+
refs.forEach(ref => {
135+
ref.current.unload(map, fengmapSDK, this)
136+
})
137+
}
138+
128139
componentDidMount() {
129140
this._loadMap(this.props.mapId)
130141
if (this.loadingTxt && this.loadingTxt.current) {
@@ -145,6 +156,9 @@ class FengmapBase extends Component {
145156
if (!this.mapInstance) {
146157
return
147158
}
159+
160+
this._destroyAllChildren(this.mapInstance)
161+
148162
EVENTS.forEach(e => {
149163
this.mapInstance.off(e)
150164
})

src/bases/FengmapBaseControl.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import React from 'react'
22

3-
export default class FengmapBaseControl extends React.Component {}
3+
export default class FengmapBaseControl extends React.Component {
4+
load = () => {}
5+
unload = () => {}
6+
}

src/components/HorizontalButtonGroupsControl/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class HorizontalButtonGroupsControl extends React.Component {
155155
const { showGroups } = this.state
156156
const { showBtnCount } = ctrlOptions
157157

158-
if (!showGroups) {
158+
if (!showGroups || !map || !map.listFloors) {
159159
return null
160160
}
161161

src/components/VerticalButtonGroupsControl/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class VerticalButtonGroupsControl extends React.Component {
151151
const { showGroups } = this.state
152152
const { showBtnCount } = ctrlOptions
153153

154-
if (!showGroups) {
154+
if (!showGroups || !map || !map.listFloors) {
155155
return null
156156
}
157157

src/controls/FengmapFloorControl.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ class FengmapFloorControl extends FengmapBaseControl {
3737
}
3838

3939
this.resizeHandler = () => {
40-
setTimeout(() => {
41-
this.setState({
42-
showHorizontal: map.height < 450
43-
})
40+
this.resizeTimer = setTimeout(() => {
41+
try {
42+
this.setState({
43+
showHorizontal: map.height < 450
44+
})
45+
} catch (error) {
46+
console.warn(error.message)
47+
}
4448
}, 1000)
4549
}
4650

@@ -55,6 +59,11 @@ class FengmapFloorControl extends FengmapBaseControl {
5559
setTimeout(this.resizeHandler, 500)
5660
}
5761

62+
unload = (map, fengmapSDK, parent) => {
63+
clearTimeout(this.resizeTimer)
64+
window.removeEventListener('resize', this.resizeHandler)
65+
}
66+
5867
componentWillUnmount() {
5968
window.removeEventListener('resize', this.resizeHandler)
6069
}

0 commit comments

Comments
 (0)