{"version":3,"sources":["directives/map.js"],"names":["opts","center","lat","lng","zoom","angular","module","service","$q","$timeout","$window","$http","load","mapsUrl","deferred","defer","scriptEl","google","undefined","maps","lazyLoadCallback","resolve","document","createElement","src","indexOf","querySelector","body","appendChild","promise","getStyles","styleJsonPath","get","then","data","directive","gMapApi","restrict","replace","transclude","scope","Model","template","controller","$scope","gmapUrl","apiKey","link","el","styles","onStylesLoaded","pathToStylesJson","loadMap","mapholder","initMap","map","Map","Markers","markers","length","forEach","marker","_marker","position","title","imgPath","icon","newMarker","Marker","infoWindow","_infoWindow","mapCard","line","address","newInfoWindow","InfoWindow","content","addListener","open"],"mappings":";;AAAA,CAAC,YAAY;AACT;;;AAGA;AACA,MAAIA,IAAI,GAAG;AACPC,IAAAA,MAAM,EAAE;AACJC,MAAAA,GAAG,EAAE,SADD;AAEJC,MAAAA,GAAG,EAAE,CAAC;AAFF,KADD;AAKPC,IAAAA,IAAI,EAAE;AALC,GAAX;AAQAC,EAAAA,OAAO,CAACC,MAAR,CAAgB,KAAhB,EAAuB,EAAvB,EACKC,OADL,CACa,SADb,EACwB,CAAC,IAAD,EAAO,UAAP,EAAmB,SAAnB,EAA8B,OAA9B,EAChB,UAASC,EAAT,EAAaC,QAAb,EAAuBC,OAAvB,EAAgCC,KAAhC,EAAuC;AACnC,WAAO;AACH;;;;;;AAMAC,MAAAA,IAAI,EAAE,cAAAC,OAAO,EAAI;AACb,YAAIC,QAAQ,GAAGN,EAAE,CAACO,KAAH,EAAf;AACA,YAAIC,QAAJ,CAFa,CAIb;;AACA,YAAGN,OAAO,CAACO,MAAR,KAAmBC,SAAnB,IAAgCR,OAAO,CAACO,MAAR,CAAeE,IAAf,KAAwBD,SAA3D,EAAsE;AAElE;AACAR,UAAAA,OAAO,CAACU,gBAAR,GAA2B,YAAM;AAE7B;AACAX,YAAAA,QAAQ,CAAC,YAAM;AACX;AACAK,cAAAA,QAAQ,CAACO,OAAT,CAAiBX,OAAO,CAACO,MAAzB;AACH,aAHO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,sLAGiBK,WAAW,CAACL,OAH7B,+IAJI,+HAaRK,WAAW,CAACvB,IAAZ,yLAGoBuB,WAAW,CAACvB,IAHhC,4NAbQ;AAwBpB,sBAAI2B,aAAa,GAAG,IAAIzD,MAAM,CAACE,IAAP,CAAYwD,UAAhB,CAA2B;AAC3CC,oBAAAA,OAAO,EAAEN,WAAW,CAACC;AADsB,mBAA3B,CAApB,CAxCmB,CA4CnB;;AACAJ,kBAAAA,SAAS,CAACU,WAAV,CAAsB,OAAtB,EAA+B;AAAA,2BAAMH,aAAa,CAACI,IAAd,CAAmBtC,KAAK,CAACe,GAAzB,EAA8BY,SAA9B,CAAN;AAAA,mBAA/B,EA7CmB,CA+CnB;;AACA,sBAAIN,MAAM,CAACQ,UAAP,CAAkBS,IAAtB,EAA4B;AAAEJ,oBAAAA,aAAa,CAACI,IAAd,CAAmBtC,KAAK,CAACe,GAAzB,EAA8BY,SAA9B;AAA2C;AAC5E;AACJ,eAvED;AAwEH;AAEJ,WAxFD;AAyFH;AACJ;AAtHE,KAAP;AAyHH,GA3Ha,CAzDtB;AAuLH,CApMD","sourcesContent":["(function () {\r\n /**\r\n * @TODO - create proper defaults and merge with what's passed into the model\r\n */\r\n // default map options\r\n var opts = {\r\n center: {\r\n lat: 51.443286,\r\n lng: -2.567456\r\n },\r\n zoom: 17\r\n };\r\n\r\n angular.module ('map', [])\r\n .service('gMapApi', ['$q', '$timeout', '$window', '$http',\r\n function($q, $timeout, $window, $http) {\r\n return {\r\n /**\r\n * load() will check if Google Maps exists on the window\r\n * create and append script tag with correct url for gmap\r\n * return a promise when complete\r\n * @param { string } mapsUrl \r\n */\r\n load: mapsUrl => {\r\n var deferred = $q.defer();\r\n var scriptEl;\r\n\r\n // Check if google maps already is part of the window\r\n if($window.google === undefined || $window.google.maps === undefined) {\r\n\r\n // Declare function to be called on google maps loading\r\n $window.lazyLoadCallback = () => {\r\n \r\n // Ensure it's loaded\r\n $timeout(() => {\r\n // Resolve Promise\r\n deferred.resolve($window.google);\r\n }, 100);\r\n };\r\n\r\n // Create the script tag\r\n scriptEl = document.createElement('script');\r\n // Set script src.\r\n // Check whether there is already a query string\r\n // If there is append (&) or add to (?) if not\r\n // Add the callback function\r\n scriptEl.src = mapsUrl + (mapsUrl.indexOf('?') > -1 ? '&' : '?') + 'callback=lazyLoadCallback';\r\n\r\n if(!document.querySelector('script[src=\"' + scriptEl.src + '\"]')) {\r\n // Add script tag to the body if not already there\r\n document.body.appendChild(scriptEl);\r\n }\r\n\r\n } else {\r\n // If window already has google resolve promise.\r\n deferred.resolve($window.google);\r\n }\r\n\r\n return deferred.promise;\r\n },\r\n getStyles: styleJsonPath => {\r\n // Get map style json from file\r\n return $http.get(styleJsonPath).then(data => {\r\n return data;\r\n });\r\n \r\n }\r\n };\r\n }\r\n ])\r\n .directive('map', ['gMapApi', '$timeout', '$window',\r\n function(gMapApi, $timeout, $window) {\r\n return {\r\n restrict: 'AE',\r\n replace: true,\r\n transclude: false,\r\n scope: {\r\n Model: '=model',\r\n },\r\n template: '
',\r\n controller: ['$scope',\r\n function($scope) {\r\n $scope.opts = $scope.Model.opts ? $scope.Model.opts : opts;\r\n $scope.gmapUrl = `https://maps.googleapis.com/maps/api/js?key=${$scope.Model.apiKey}`;\r\n }\r\n ],\r\n link: function(scope, el) {\r\n\r\n let styles;\r\n // Callback function - set style when getStyles promise returns\r\n function onStylesLoaded(data) {\r\n styles = data.data;\r\n }\r\n if(scope.Model.pathToStylesJson) {\r\n gMapApi.getStyles(scope.Model.pathToStylesJson).then(onStylesLoaded).then(loadMap);\r\n } else {\r\n loadMap();\r\n }\r\n\r\n function loadMap() {\r\n gMapApi.load(scope.gmapUrl).then(function() {\r\n\r\n if (styles) {\r\n // pass styles if there are any\r\n scope.opts.styles = styles;\r\n }\r\n\r\n // Load the map\r\n scope.mapholder = el[0];\r\n scope.initMap = () => scope.map = new google.maps.Map(scope.mapholder, scope.opts);\r\n scope.initMap();\r\n\r\n // Add Markers\r\n if(scope.Model.Markers && scope.Model.markers.length > 0) {\r\n angular.forEach(scope.Model.markers, (marker) => {\r\n\r\n // create temporary marker reference\r\n let _marker = {};\r\n\r\n // Set markers options\r\n if (marker.position) { _marker.position = marker.position; }\r\n if (marker.title) { _marker.title = marker.title; }\r\n if (marker.imgPath) { _marker.icon = marker.imgPath; }\r\n _marker.map = scope.map;\r\n\r\n // Add marker\r\n let newMarker = new google.maps.Marker(_marker);\r\n\r\n \r\n /**\r\n * Add the markers info window\r\n * @TODO Maybe split this out into a seperate directive\r\n * This could be useful for using different templates\r\n * Would also mean we can get rid of all the below html\r\n */\r\n if (marker.infoWindow) {\r\n let _infoWindow = marker.infoWindow;\r\n\r\n _infoWindow.mapCard = `\r\n`;\r\n \r\n for(let line in _infoWindow.address) {\r\n if (line) { _infoWindow.mapCard += _infoWindow.address[line] + '
'; }\r\n }\r\n\r\n _infoWindow.mapCard +=\r\n `