Skip to content

Commit

Permalink
feat: make focusFloor writable
Browse files Browse the repository at this point in the history
  • Loading branch information
leftstick committed Jan 14, 2019
1 parent cee1c42 commit d83a4ee
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
4 changes: 3 additions & 1 deletion example/src/pages/api/fengmap-floorcontrol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class FengmapFloorControlDoc extends Component {
position: fengmapSDK.controlPositon.RIGHT_BOTTOM,
showBtnCount: 7
}}
onFloorChange={this.changeFloor}
onFloorChange={floor => {
console.log(`Changed floor to: `, floor)
}}
/>
</FengmapBase>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-fengmap",
"version": "2.2.1",
"version": "2.2.2",
"description": "",
"author": "leftstick",
"typings": "typings/index.d.ts",
Expand Down
8 changes: 2 additions & 6 deletions src/FengmapBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import { isChildrenValid } from './helpers/validator'
import { isArray } from './helpers/object'
import { isOrderIE } from './helpers/browser'
import { setFloorsByGroupId, setFloorsToMapInstance } from './helpers/map'
import { initFloorsToMapInstance } from './helpers/map'

const EVENTS = [
'focusGroupIDChanged',
Expand Down Expand Up @@ -83,11 +83,7 @@ class FengmapBase extends Component {
this.loadingTxt.current.style['zIndex'] = -10
this._configGestureEnableController()
this._initAllChildren(this.mapInstance)
setFloorsByGroupId(this.mapInstance)
setFloorsToMapInstance(this.mapInstance)
}
if (e === 'focusGroupIDChanged') {
setFloorsByGroupId(this.mapInstance)
initFloorsToMapInstance(this.mapInstance)
}
if (events && events[e]) {
events[e](event, this.mapInstance)
Expand Down
7 changes: 1 addition & 6 deletions src/controls/FengmapFloorControl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import FengmapBaseControl from '../bases/FengmapBaseControl'
import PropTypes from 'prop-types'

import { getFloors } from '../helpers/map'

class FengmapFloorControl extends FengmapBaseControl {
static propTypes = {
ctrlOptions: PropTypes.shape({
Expand All @@ -29,11 +27,8 @@ class FengmapFloorControl extends FengmapBaseControl {
if (!onFloorChange) {
return
}

const availableFloors = getFloors(map)

onFloorChange({
floorLevel: availableFloors ? availableFloors[map.focusGroupID - 1] : undefined,
floorLevel: map.focusFloor,
groupId: map.focusGroupID
})
})
Expand Down
30 changes: 27 additions & 3 deletions src/helpers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,35 @@ export function getFloors(map) {
})
}

export function setFloorsToMapInstance(map) {
if (!map.listGroups || !map.listGroups.length) {
export function initFloorsToMapInstance(map) {
if (!map) {
return
}
map.listFloors = getFloors(map)

Object.defineProperty(map, 'focusFloor', {
get: function() {
return getFloors(map)[map.groupIDs.indexOf(map.focusGroupID)]
},
set: function(floor) {
const floors = getFloors(map)
const focusGroupID = map.groupIDs[floors.indexOf(floor)]
map.visibleGroupIDs = [focusGroupID]
map.focusGroupID = focusGroupID
},
enumerable: true,
configurable: true
})

Object.defineProperty(map, 'listFloors', {
get: function() {
return getFloors(map)
},
set: function(floor) {
throw new Error('listFloors is not writable')
},
enumerable: true,
configurable: true
})
}

export function setFloorsByGroupId(map) {
Expand Down

0 comments on commit d83a4ee

Please sign in to comment.