text: !function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/build/",t(t.s=5)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=(t.KrakowCoords={lat:50.06168,lng:19.9429},t.R=6371),i=t.degToRadians=function(e){return e*(Math.PI/180)};t.resultBox=document.getElementById("result"),t.infoMessage="You can select only 2 points in TRANSIT mode!",t.minPointsMessage="Select minimum 2 points on the map!",t.uuid=function(){var e=function(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)};return""+e()+e()+e()+e()},t.calcDirectDistance=function(e,t){var n=i(e.lat),o=i(t.lat),a=i(t.lat-e.lat),s=i(t.lng-e.lng),l=Math.sin(a/2)*Math.sin(a/2)+Math.cos(n)*Math.cos(o)*Math.sin(s/2)*Math.sin(s/2),u=2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),c=r*u;return Math.round(100*c)/100},t.getCoordsFromMarker=function(e){return{lat:e.getPosition().lat(),lng:e.getPosition().lng()}}},function(e,t,n){"use strict";var r=n(3),i=n(0),o=function(){var e=document.getElementById("map"),t=new r.Map({mapBox:e,mapOptions:{center:i.KrakowCoords,zoom:14}});document.getElementById("resetBtn").addEventListener("click",function(){t.reset()}),document.getElementById("calculateBtn").addEventListener("click",function(){t.renderResults()})};"complete"===document.readyState||"loading"!==document.readyState?o():document.addEventListener("DOMContentLoaded",o)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.Calculate=void 0;var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(0),a=function(e){var t=[];return e.forEach(function(e,n,r){n<r.length-1&&t.push([e,r[n+1]])}),t},s=function(e){return e.reduce(function(e,t){return e+t},0)};t.Calculate=function(){function e(){r(this,e)}return i(e,[{key:"getDirectDistance",value:function(e){var t=[];return a(e).forEach(function(e){var n=(0,o.getCoordsFromMarker)(e[0]),r=(0,o.getCoordsFromMarker)(e[1]);t.push((0,o.calcDirectDistance)(n,r))}),Math.round(100*s(t))/100}},{key:"getRouteDistance",value:function(e){var t=0;return e.routes[0].legs.forEach(function(e){t+=e.distance.value}),Math.round(t/10)/100}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.Map=void 0;var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(2),a=n(4),s=n(0),l=new o.Calculate,u=new a.Mode;t.Map=function(){function e(t){r(this,e),this.mapBox=t.mapBox,this.mapOptions=t.mapOptions,this.map=null,this.markers=[],this.result=s.minPointsMessage,this.directionsDisplay=null,this.polyline=new google.maps.Polyline({geodesic:!0,strokeColor:"#19B88A",strokeOpacity:1,strokeWeight:3}),this.directionsService=new google.maps.DirectionsService,this.routeRendered=!1,this.polylineRendered=!1,this.initMap(this.mapBox,this.mapOptions)}return i(e,[{key:"initMap",value:function(e,t){var n=this;this.directionsDisplay=new google.maps.DirectionsRenderer({suppressMarkers:!0}),this.map=new google.maps.Map(e,t),this.polyline.setMap(this.map),this.directionsDisplay.setMap(this.map),google.maps.event.addListener(this.map,"click",function(e){var t=u.getCurrentMode();switch(t){case"DIRECT":n.addMarker(e.latLng),n.addPointToPolyline(e.latLng);break;case"WALKING":case"BICYCLING":case"DRIVING":n.addMarker(e.latLng),n.markers.length>1&&n.calcRoute({mode:t});break;case"TRANSIT":n.markers.length>1?n.showAlert("info",s.infoMessage):(n.addMarker(e.latLng),n.markers.length>1&&n.calcRoute({mode:t}))}})}},{key:"calcRoute",value:function(e){var t=this,n=this.markers,r=this.markers[0].getPosition(),i=this.markers[this.markers.length-1].getPosition(),o=[];n.slice(1,-1).forEach(function(e){o.push({location:e.getPosition(),stopover:!0})});var a={origin:r,destination:i,travelMode:e.mode,region:"PL"};o.length&&(a.waypoints=o),this.directionsService.route(a,function(e,n){"OK"==n?(t.directionsDisplay.setMap(t.map),t.directionsDisplay.setDirections(e),t.result=l.getRouteDistance(e)+"km",s.resultBox.innerHTML=t.result,t.routeRendered=!0):(t.showAlert("error",n),t.reset())})}},{key:"addMarker",value:function(e){var t=this,n=new google.maps.Geocoder,r=new google.maps.InfoWindow({maxWidth:200}),i=new google.maps.Marker({position:e,map:this.map,icon:"img/marker.svg",id:(0,s.uuid)()});i.addListener("click",function(){n.geocode({latLng:i.getPosition()},function(e,t){t===google.maps.GeocoderStatus.OK&&e[0]&&(r.setContent(e[0].formatted_address),r.open(this.map,i))})}),i.addListener("rightclick",function(){var e=u.getCurrentMode();"DIRECT"===e?(t.removePolylineAllPoints(),t.deleteMarker(i),t.updatePolyline()):"TRANSIT"===e?(t.deleteMarker(i),2===t.markers.length?t.calcRoute({mode:e}):t.deleteRoute()):(t.deleteMarker(i),t.markers.length>1?t.calcRoute({mode:e}):t.deleteRoute())}),this.markers.push(i)}},{key:"addPointToPolyline",value:function(e){this.polyline.getPath().push(e),this.polylineRendered=!0}},{key:"updatePolyline",value:function(){for(var e=0;e<this.markers.length;e++){var t=this.markers[e].getPosition();this.polyline.getPath().push(t)}this.polylineRendered=!0}},{key:"removePolylineAllPoints",value:function(){for(var e=0;e<this.markers.length;e++){var t=this.markers[e].getPosition();this.polyline.getPath().removeAt(t)}this.polylineRendered=!1}},{key:"setMapOnAll",value:function(e){for(var t=0;t<this.markers.length;t++)this.markers[t].setMap(e)}},{key:"deleteMarker",value:function(e){e.setMap(null);for(var t=0;t<this.markers.length;t++)this.markers[t].id===e.id&&this.markers.splice(t,1)}},{key:"deleteAllMarkers",value:function(){this.setMapOnAll(null),this.removePolylineAllPoints(),this.markers=[],this.polylineRendered=!1}},{key:"deleteRoute",value:function(){this.directionsDisplay.setMap(null),this.routeRendered=!1}},{key:"reset",value:function(){this.deleteRoute(),this.deleteAllMarkers(),s.resultBox.innerHTML=""}},{key:"calculate",value:function(){var e=this.markers;if(e.length>1){var t=u.getCurrentMode();switch(t){case"DIRECT":this.routeRendered&&this.deleteRoute(),this.polylineRendered||this.updatePolyline(),this.result=l.getDirectDistance(e)+"km";break;case"WALKING":case"BICYCLING":case"DRIVING":this.removePolylineAllPoints(),this.calcRoute({mode:t});break;case"TRANSIT":this.polylineRendered&&this.removePolylineAllPoints(),e.length>2?this.showAlert("info",s.infoMessage):this.calcRoute({mode:t});break;default:this.result=l.getDirectDistance(e)+"km"}}else this.result=s.minPointsMessage,s.resultBox.innerHTML=this.result}},{key:"renderResults",value:function(){this.calculate(),"DIRECT"===u.getCurrentMode()&&(s.resultBox.innerHTML=this.result)}},{key:"showAlert",value:function(e,t){var n=document.getElementById("alert");if(!n.classList.contains("visible")){switch(e){case"info":n.classList.add("alert-info");break;case"error":n.classList.add("alert-error");break;default:n.classList.add("alert-error")}n.querySelector(".alert__content").innerHTML=t,n.classList.add("visible"),setTimeout(function(){n.classList.remove("visible")},5e3)}}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.Mode=function(){function e(){r(this,e),this.mode="DIRECT",this.radio=document.querySelectorAll('input[name="mode"]'),this.onChange()}return i(e,[{key:"setCurrentMode",value:function(e){this.mode=e}},{key:"getCurrentMode",value:function(){return this.mode}},{key:"onChange",value:function(){var e=this;this.radio.forEach(function(t){t.addEventListener("change",function(t){var n=t.target.dataset.mode;e.setCurrentMode(n)})})}}]),e}()},function(e,t,n){e.exports=n(1)}]);