UNPKG

rc-bmap

Version:

<p align="center"> <img src="https://bmap.jser-club.com/home.png" width="200px"> </p> <p align="center">基于 React 的百度地图组件</p>

42 lines (33 loc) 728 B
import BMapUtil from '../utils/map'; class TrafficLayer { constructor(config, map) { this.map = map; this.init(config); } init(config = {}) { const now = new Date(); if (!config.weekday) { config.weekday = now.getDay(); } if (!config.hour) { config.hour = now.getHours(); } this.instance = BMapUtil.BTrafficLayer({ predictDate: { weekday: config.weekday, hour: config.hour, }, }); this.map.addTileLayer(this.instance); } repaint = (config = {}) => { this.destroy(); this.init(config); } destroy = () => { if (this.instance) { this.map.removeTileLayer(this.instance); } } } export default TrafficLayer;