/**
|
* 动态效果封装
|
*/
|
class AnimalService {
|
constructor (config) {
|
this.intervals = [] // 定时器列表
|
// todo 这种情况一般用 window级的L、map还是传递呢
|
this.L = config.L
|
this.layer = window.map
|
this.times = config.times || 5
|
this.colors = ['#98FB98', '#ff0000']
|
}
|
|
/**
|
* 脉冲效果
|
*/
|
pulseEffect (xy) {
|
// 插件 效果实现
|
var pulsingIcon = this.L.icon.pulse({
|
iconSize: [20, 20],
|
color: this.colors[0],
|
fillColor: ''
|
})
|
var picGroupMarker = this.L.marker(xy, { icon: pulsingIcon }).addTo(this.layer)
|
var times = this.times
|
// 定时
|
var timeInterval = setInterval(() => {
|
if (times > 0) {
|
times--
|
} else {
|
clearInterval(timeInterval)
|
picGroupMarker.remove()
|
}
|
}, 1000)
|
}
|
|
/**
|
* 设置弹窗平移位置
|
* @param pos
|
* @param value
|
*/
|
setPanTo = (pos, value) => {
|
var position = pos
|
position = this.layer.latLngToLayerPoint(position)
|
position.y += value
|
position = this.layer.layerPointToLatLng(position)
|
this.layer.flyTo(position)
|
}
|
}
|
|
export default AnimalService
|