-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from rainbowflesh/patch-1
feat: add walking route
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @file 步行路径导航 | ||
* @author github.com/rainbowflesh | ||
*/ | ||
|
||
import Component from "./component"; | ||
|
||
export default class WalkingRoute extends Component { | ||
constructor(args) { | ||
super(args); | ||
this.state = {}; | ||
} | ||
|
||
static get defaultProps() { | ||
return {}; | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
this.initialize(); | ||
} | ||
|
||
componentDidMount() { | ||
this.initialize(); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.destroy(); | ||
} | ||
|
||
destroy() { | ||
this.walking && this.walking.clearResults(); | ||
this.walking = null; | ||
} | ||
|
||
initialize() { | ||
var map = this.props.map; | ||
if (!map) { | ||
return; | ||
} | ||
this.destroy(); | ||
|
||
if (!this.walking) { | ||
this.walking = new BMap.WalkingRoute(map, { | ||
renderOptions: { | ||
map: map, | ||
autoViewport: this.props.autoViewport !== undefined ? this.props.autoViewport : true, | ||
viewportOptions: { zoomFactor: -1 }, | ||
}, | ||
}); | ||
} | ||
|
||
var start = this.props.start; | ||
var end = this.props.end; | ||
|
||
if (start.lng && start.lat) { | ||
start = new BMap.Point(start.lng, start.lat); | ||
} | ||
|
||
if (end.lng && end.lat) { | ||
end = new BMap.Point(end.lng, end.lat); | ||
} | ||
|
||
this.walking.search(start, end); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters