Skip to content

Commit

Permalink
Merge pull request #133 from rainbowflesh/patch-1
Browse files Browse the repository at this point in the history
feat: add walking route
  • Loading branch information
Junior2Ran authored Jan 2, 2024
2 parents 6fba716 + 1337af2 commit 01c9889
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/components/walking-route.js
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);
}
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export {default as MapvglView} from './components/mapvgl-view';
* 服务组件
*/
export {default as DrivingRoute} from './components/driving-route';
export {default as WalkingRoute} from './components/walking-route';

/**
* PointLabel组件
Expand Down

0 comments on commit 01c9889

Please sign in to comment.