Sebastiankay/eft_group_map_websocket
0
1import L from 'leaflet';2 3import { formattedTarkovTime } from '../components/Time.jsx';4 5let updateTimeInterval = false;6 7L.Control.RaidInfo = L.Control.extend({8 onAdd: function(map) {9 clearInterval(updateTimeInterval);10 const wrapper = L.DomUtil.create('div');11 wrapper.classList.add('time-wrapper', 'leaflet-control-raid-info');12 if (this.options.map.normalizedName !== 'the-lab') {13 const timeLeftDiv = L.DomUtil.create('div');14 const timeRightDiv = L.DomUtil.create('div');15 16 if (this.options.map.normalizedName === 'factory' || this.options.map.normalizedName === 'night-factory') {17 timeLeftDiv.innerText = '15:28:00';18 timeRightDiv.innerText = '03:28:00';19 } else {20 const updateTimes = () => {21 timeLeftDiv.innerText = formattedTarkovTime(true);22 timeRightDiv.innerText = formattedTarkovTime(false);23 };24 updateTimeInterval = setInterval(updateTimes, 50);25 }26 27 wrapper.append(timeLeftDiv);28 wrapper.append(timeRightDiv);29 }30 const duration = L.DomUtil.create('div');31 const durLabel = this.options.durationLabel ? this.options.durationLabel : 'Duration';32 duration.innerText = `${durLabel}: ${this.options.map.duration}`;33 wrapper.append(duration);34 35 const players = L.DomUtil.create('div');36 const playersLabel = this.options.playersLabel ? this.options.playersLabel : 'Players';37 players.innerText = `${playersLabel}: ${this.options.map.players}`;38 wrapper.append(players);39 40 if (this.options.map.author) {41 const author = L.DomUtil.create('div');42 const byLabel = this.options.byLabel ? this.options.byLabel : 'By';43 author.innerText = `${byLabel}: `;44 const authorLink = L.DomUtil.create('a');45 authorLink.setAttribute('href', this.options.map.authorLink);46 authorLink.setAttribute('target', '_blank');47 authorLink.setAttribute('re', 'noopener noreferrer');48 authorLink.innerText = this.options.map.author;49 author.append(authorLink);50 wrapper.append(author);51 }52 53 return wrapper;54 },55 56 onRemove: function(map) {57 // Nothing to do here58 }59});60 61L.control.raidInfo = function(opts) {62 return new L.Control.RaidInfo(opts);63}