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KrBhB,EAAQzE,iHAM1B,YAAjByE,EAAQ/E,OACV8F,GAAQ,yIAG6Bf,EAAQlE,MAAMkF,QAAQ,0NAKtBhB,EAAQpE,qHAM/CG,KAAKkF,mBAAmB,WAAYF,GAEtC5D,aAAaiC,GACX,MAAM8B,EAAY9B,EAAE+B,OAAOjC,QAAQ,YAGnC,GAFAtB,QAAQC,IAAIqD,IAEPA,EAAW,OAEhB,MAAMlB,EAAUlF,MAAK8B,EAAUwE,MAC7B9C,GAAQA,EAAKhE,KAAO4G,EAAUG,QAAQ/G,KAGxCQ,MAAK2B,EAAKsB,QAAQiC,EAAQrF,OAAQG,MAAK4B,EAAe,CACpD4E,SAAS,EACTC,IAAK,CACH1G,SAAU,KAQhBuF,mBACEoB,aAAaC,QAAQ,WAAYC,KAAKC,UAAU7G,MAAK8B,IAGvDE,mBACE,MAAM8E,EAAOF,KAAKG,MAAML,aAAaM,QAAQ,aAExCF,IAEL9G,MAAK8B,EAAYgF,EAEjB9G,MAAK8B,EAAUyB,SAAQC,IACrBxD,KAAKqF,eAAe7B,OAIxByD,QACEP,aAAaQ,WAAW,YACxBC,SAASC,UAIb,MAAMC,IAAM,IAAI3F","sources":["script.js"],"sourcesContent":["'use strict';\n\n// prettier-ignore\nconst months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];\n\nclass Workout {\n date = new Date();\n id = (Date.now() + '').slice(-10);\n clicks = 0;\n\n constructor(coords, distance, duration) {\n this.coords = coords; // [lat, lng]\n this.distance = distance; // km\n this.duration = duration; // min\n }\n\n _setDescription() {\n // prettier-ignore\n const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];\n\n this.description = `${this.type[0].toUpperCase()}${this.type.slice(1)} on ${\n months[this.date.getMonth()]\n } ${this.date.getDate()}`;\n }\n\n click() {\n this.clicks++;\n }\n}\n\nclass Running extends Workout {\n type = 'running';\n constructor(coords, distance, duration, cadence) {\n super(coords, distance, duration);\n this.cadence = cadence;\n this.caclPace();\n this._setDescription();\n }\n\n caclPace() {\n // min/km\n this.pace = this.duration / this.distance;\n return this.pace;\n }\n}\n\nclass Cycling extends Workout {\n type = 'cycling';\n constructor(coords, distance, duration, elevationGain) {\n super(coords, distance, duration);\n this.elevationGain = elevationGain;\n this.calcSpeed();\n this._setDescription();\n }\n\n calcSpeed() {\n // km/h\n this.speed = this.distance / (this.duration / 60);\n return this.speed;\n }\n}\n\n// const run1 = new Running([39, -12], 5.2, 24, 178);\n// const cycling1 = new Cycling([39, -12], 27, 95, 523);\n// console.log(run1, cycling1);\n\n//////////////////////////////////////////////////////////\n// Application Architecture\n\nconst form = document.querySelector('.form');\nconst containerWorkouts = document.querySelector('.workouts');\nconst inputType = document.querySelector('.form__input--type');\nconst inputDistance = document.querySelector('.form__input--distance');\nconst inputDuration = document.querySelector('.form__input--duration');\nconst inputCadence = document.querySelector('.form__input--cadence');\nconst inputElevation = document.querySelector('.form__input--elevation');\n\nclass App {\n #map;\n #mapZoomLevel = 13;\n #mapEvent;\n #workouts = [];\n constructor() {\n // Get User's Position\n this._getPosition();\n\n // Get Data from Local Storage\n this._getLocalStorage();\n\n // Attach Event Handlers\n form.addEventListener('submit', this._newWorkout.bind(this));\n inputType.addEventListener('change', this._toggleEleveationField);\n containerWorkouts.addEventListener('click', this._moveToPopup.bind(this));\n }\n _getPosition() {\n if (navigator.geolocation)\n navigator.geolocation.getCurrentPosition(\n this._loadMap.bind(this),\n function () {\n alert('Could not get your position.');\n }\n );\n }\n _loadMap(position) {\n const { latitude } = position.coords;\n const { longitude } = position.coords;\n console.log(`https://www.google.com/maps/@${latitude},${longitude}`);\n\n const coords = [latitude, longitude];\n\n this.#map = L.map('map').setView(coords, this.#mapZoomLevel);\n\n L.tileLayer('https://{s}.tile.openstreetmap.fr/hot//{z}/{x}/{y}.png', {\n attribution:\n '© OpenStreetMap contributors',\n }).addTo(this.#map);\n\n // Handling Clicks on Map\n this.#map.on('click', this._showForm.bind(this));\n\n this.#workouts.forEach(work => {\n this._renderWorkoutMarker(work);\n });\n }\n _showForm(mapE) {\n this.#mapEvent = mapE;\n form.classList.remove('hidden');\n inputDistance.focus();\n }\n\n _hideForm() {\n // Empty inputs\n inputDistance.value =\n inputDuration.value =\n inputElevation.value =\n inputCadence.value =\n '';\n form.style.display = 'none';\n form.classList.add('hidden');\n setTimeout(() => (form.style.display = 'grid'), 1000);\n }\n\n _toggleEleveationField() {\n inputElevation.closest('.form__row').classList.toggle('form__row--hidden');\n inputCadence.closest('.form__row').classList.toggle('form__row--hidden');\n }\n _newWorkout(e) {\n const validInputs = (...inputs) =>\n inputs.every(inp => Number.isFinite(inp));\n const allPositive = (...inputs) => inputs.every(inp => inp > 0);\n e.preventDefault();\n\n // Get Data from Form\n const type = inputType.value;\n const distance = +inputDistance.value;\n const duration = +inputDuration.value;\n const { lat, lng } = this.#mapEvent.latlng;\n let workout;\n // Check if Data is Valid\n\n // If workout is running, create running object\n if (type === 'running') {\n const cadence = +inputCadence.value;\n // Check if data is valid\n if (\n // !Number.isFinite(distance) ||\n // !Number.isFinite(duration) ||\n // !Number.isFinite(cadence)\n !validInputs(distance, duration, cadence) ||\n !allPositive(distance, duration, cadence)\n )\n return alert('Inputs have to be positive numbers!');\n\n workout = new Running([lat, lng], distance, duration, cadence);\n }\n // If workout is cycling, create cycling object\n if (type === 'cycling') {\n const elevation = +inputElevation.value;\n // Check if data is valid\n if (\n !validInputs(distance, duration, elevation) ||\n !allPositive(distance, duration)\n )\n return alert('Inputs have to be positive numbers!');\n workout = new Cycling([lat, lng], distance, duration, elevation);\n }\n // Add new object to workout array\n this.#workouts.push(workout);\n\n // Render workout on map as a marker\n this._renderWorkoutMarker(workout);\n\n // Render workout on list\n this._renderWorkout(workout);\n\n // Hide Form + Clear Input Fields\n this._hideForm();\n\n // Set Local Storage to All Workouts\n this._setLocalStorage();\n }\n _renderWorkoutMarker(workout) {\n L.marker(workout.coords)\n .addTo(this.#map)\n .bindPopup(\n L.popup({\n maxWidth: 250,\n minWidth: 100,\n autoClose: false,\n closeOnClick: false,\n className: `${workout.type}-popup`,\n })\n )\n .setPopupContent(\n `${workout.type === 'running' ? 'πββοΈ' : 'π΄ββοΈ'} ${workout.description}`\n )\n .openPopup();\n }\n\n _renderWorkout(workout) {\n let html = `\n