| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- export default {
- _caller: null, // 调用方指针
-
- // *** 非指针复制 ***
- storePlayers: [{
- id: 0, // 玩家ID
- marker: null, // 玩家标识
- trail: null, // 玩家轨迹
- trailData: [], // 玩家轨迹信息(数据会追加并定时清理过期数据)
- interval_creatCircleMarker: null,
- interval_showTrail: null,
- }],
-
- map: null,
- map_layer: null,
-
- players: [], // 玩家信息(指针复制 每次grpc获取数据后之前旧数据会丢弃)
- players_position: [], // 玩家当前位置信息(指针复制 每次grpc获取数据后之前旧数据会丢弃)
-
- focusPlayerId: 0, // 当前选中的玩家ID
- checkPoints: [], // 检查点列表(指针复制 每次grpc获取数据后之前旧数据会丢弃)
- routes: [], // 路线列表(指针复制 每次grpc获取数据后之前旧数据会丢弃)
-
- init() {
- this._caller = null
- this.storePlayers.length = 0 // 清空数组
- this.map = null
- this.map_layer = null
- this.players.length = 0 // 清空数组
- this.players_position.length = 0 // 清空数组
- this.focusPlayerId = 0
- this.checkPoints.length = 0 // 清空数组
- this.routes.length = 0 // 清空数组
- },
- setCaller(data) {
- this._caller = data // 指针复制,是同一个对象
- },
- setPlayers(data) {
- this.players = data // 指针复制,是同一个对象
- },
- setPlayersPosition(data) {
- this.players_position = data // 指针复制,是同一个对象
- },
- // *** 非指针复制 ***
- // storePlayersTrail(data) {
- // this.storePlayers.trail.push(data)
- // },
- setCheckPoints(data) {
- this.checkPoints = data // 指针复制,是同一个对象
- },
- setRoutes(data) {
- this.routes = data // 指针复制,是同一个对象
- },
- getPlayerById(playerId) {
- if (!(playerId > 0)) return
-
- var player = null
- if (this.players != null && this.players.length > 0) {
- player = this.players.find(o => o.id === playerId)
- }
- // console.log("[getPlayerById]", playerId, player)
- return player
- },
- getPlayerPositionById(playerId) {
- if (!(playerId > 0)) return
-
- var player_position = null
- if (this.players_position != null && this.players_position.length > 0) {
- player_position = this.players_position.find(o => o.id === playerId)
- }
- // console.log("[getPlayerPositionById]", playerId, player_position)
- return player_position
- },
- getStorePlayersById(playerId) {
- if (!(playerId > 0)) return
-
- var storePlayer = null
- if (this.storePlayers != null && this.storePlayers.length > 0) {
- storePlayer = this.storePlayers.find(o => o.id === playerId)
- }
- // console.log("[getStorePlayersById]", playerId, storePlayer)
- return storePlayer
- },
- getCheckPointById(cpId) {
- if (!(cpId > 0)) return
-
- var checkPoint = null
- if (this.checkPoints != null && this.checkPoints.length > 0) {
- checkPoint = this.checkPoints.find(o => o.cp_id === cpId)
- }
- // console.log("[getCheckPointById]", cpId, checkPoint)
- return checkPoint
- },
- getRouteById(rtId) {
- if (!(rtId > 0)) return
-
- var route = null
- if (this.routes != null && this.routes.length > 0) {
- route = this.routes.find(o => o.id === rtId)
- }
- // console.log("[getCheckPointById]", rtId, route)
- return route
- },
- // 处理过期数据
- dealStaleData() {
- for (let i = 0; i < this.storePlayers.length; i++) {
- var storePlayer = this.storePlayers[i]
-
- if (storePlayer == null || !(storePlayer.id > 0)) {
- continue
- }
-
- // 查找最新的玩家记录列表
- var player = this.getPlayerById(storePlayer.id)
- if (player == null) { // 未找到 说明记录已过期
- // console.warn('[dealStaleData] 发现过期数据', storePlayer)
-
- if (storePlayer.marker != null) {
- storePlayer.marker.removeFrom(storePlayer.markerLayerGroup)
- storePlayer.marker = null
- }
-
- if (storePlayer.trail != null) {
- storePlayer.trail.removeFrom(storePlayer.trailLayerGroup)
- storePlayer.trail2.removeFrom(storePlayer.trailLayerGroup)
- storePlayer.trail = null
- storePlayer.trail2 = null
- storePlayer.trailData = []
- }
-
- if (storePlayer.interval_creatCircleMarker != null) {
- clearInterval(storePlayer.interval_creatCircleMarker)
- }
-
- if (storePlayer.interval_creatCircleMarker != null) {
- clearInterval(storePlayer.interval_showTrail)
- }
-
- // delete删除元素之后数组长度不变,只是被删除元素被置为empty
- // delete this.storePlayers[i]
- }
- }
- },
- }
|