-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
2 lines (2 loc) · 6.28 KB
/
index.js
File metadata and controls
2 lines (2 loc) · 6.28 KB
1
2
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("lodash/partial")):"function"==typeof define&&define.amd?define(["lodash/partial"],t):(n=n||self).GoogleMapHelper=t(n.partial)}(this,function(u){"use strict";function t(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),e.push.apply(e,r)}return e}function i(o){for(var n=1;n<arguments.length;n++){var a=null!=arguments[n]?arguments[n]:{};n%2?t(Object(a),!0).forEach(function(n){var t,e,r;t=o,r=a[e=n],e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(a)):t(Object(a)).forEach(function(n){Object.defineProperty(o,n,Object.getOwnPropertyDescriptor(a,n))})}return o}function c(n){return function(n){if(Array.isArray(n)){for(var t=0,e=new Array(n.length);t<n.length;t++)e[t]=n[t];return e}}(n)||function(n){if(Symbol.iterator in Object(n)||"[object Arguments]"===Object.prototype.toString.call(n))return Array.from(n)}(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}u=u&&u.hasOwnProperty("default")?u.default:u;function l(n){var t;n&&(t=JSON.parse(n));var o=i({autozoom:!1,boundmap:!1,centermap:!1,draggable:!0,optimized:!1,mapTypeControl:!1,scrollwheel:!1,type:"ROADMAP",zoom:15,zoomControl:!0},t,{},function(n){var t=n.pins,e=n.lng,r=n.lat,o=Array.isArray(t)?t:[t];return 0===o.length?{pins:o}:(console.log(o),1<o.length&&!e&&!r?{pins:o,boundmap:!0}:e&&r?{pins:o,lng:e,lat:r}:{pins:o,lng:o[0].lng,lat:o[0].lat})}(t)),a={addType:function(n){var t=n||o.type;return o.mapTypeId=google.maps.MapTypeId[t],a},addCenter:function(n,t){var e=n||o.lat,r=t||o.lng;return o.center=new google.maps.LatLng(e,r),a},get:function(n){return o[n]},getAll:function(){return o},update:function(n){return o=i({},o,{},n),a}};return a}function p(n,t,e){return"undefined"!=typeof InfoBubble?function(n,t,e){var r=i({shadowStyle:0,padding:0,backgroundColor:"#55a440",borderRadius:0,arrowSize:2,borderWidth:0,borderColor:"#2c2c2c",disableAutoPan:!1,hideCloseButton:!0,arrowPosition:50,minHeight:220,backgroundClassName:"infowindow clearfix",arrowStyle:2,maps:n,content:t},e);return new InfoBubble(r)}(n,t,e):new google.maps.InfoWindow({content:t})}function f(e,n,r){var o=function(r,o){return function(t,e){var n=document.getElementById("pin-".concat(o));if(null===n)return null;google.maps.event.addDomListener(n,"click",function(n){n.preventDefault(),e.close(r,t)})}}(e,n);return function(n,t){google.maps.event.addListener(n,"click",function(){r.closeAllWindows(),t.open(e,n),"undefined"!=typeof InfoBubble&&(google.maps.event.trigger(e,"resize"),setTimeout(function(){o(n,t)},500))})}}function d(o){var a,i;return o?function(n,e){console.log("options",e.getAll());var t=function(t){var e=[];return{addMarkers:function(n){Array.isArray(n)?e=e.concat(n):e.push(n)},closeAllWindows:function(){e.forEach(function(n){n.hasOwnProperty("info")&&n.hasOwnProperty("marker")&&n.info.close(t,n.marker)})},getAll:function(){return e}}}(a=new n(o,e.getAll())),r=function(e,r){return function(n){var t=e(n);return r.addMarkers(t),t}}(function(a,i,u){return function(n){var t,e=n.lng,r=n.lat,o=new google.maps.Marker({position:new google.maps.LatLng(r,e),map:a});return function(n,t){!function(n){return"function"==typeof n.setIcon}(n)||t.picture&&t.width&&t.height&&n.setIcon(t.picture,[t.width,t.height])}(o,n),n.infowindow&&(t=p(a,n.infowindow,u),f(a,n.id,i)(o,t)),{marker:o,info:t}}}(a,t),t);return i=function(n,t){return Array.isArray(n)?n.map(function(n){return t(n)}):[t(n)]}(e.get("pins"),r),{centerMap:function(e,r){return function(n){var t=new n;r.forEach(function(n){t.extend(n.marker.getPosition())}),e.fitBounds(t)}}(a,i),getMap:function(){return a},setPosition:function(n){var t=n({lat:e.get("lat"),lng:e.get("lng")});a.setCenter(t)},setZoom:function(e,r){return function(n){var t=n.addListener(e,"idle",function(){e.getZoom()!==r&&e.setZoom(r),n.removeListener(t)})}}(a,e.get("zoom"))}}:null}function r(n,t){var e=document.createElement("script");return e.id=t,e.type="text/javascript",e.src=n,e}function s(n){var t=[],e={addPlugins:function(n){return Array.isArray(n)?t=t.concat(n):"string"==typeof n&&t.push(n),e},load:function(){document.getElementById("gmapsScripts")||(document.body.appendChild(r(n,"gmapsScripts")),function(n){Array.isArray(n)&&0<n.length&&n.forEach(function(n,t){void 0!==n&&document.body.appendChild(r(n,"plugin".concat(t)))})}(t))}};return e}Array.isArray||(Array.isArray=function(n){return"[object Array]"===Object.prototype.toString.call(n)});return function(n){var t=c(document.querySelectorAll("[data-map]"));if(0!==t.length){var e=function(n){var t,e,r;t="https://maps.google.com/maps/api/js?",t+="key=".concat(n),e=[],r="uk";var o={addLibrary:function(n){return e.push(n),o},addRegion:function(n){return r=n,o},getPath:function(n){return 0<e.length&&(t+="&libraries=".concat(e.join(","))),t+="&async=2",t+="®ion=".concat(r),t+="&callback=".concat(n)}};return o}(n),r=t.map(function(n){return{options:l(n.dataset.map),map:d(n),id:n.id}}),o=function(t){return function(e){var n=t.find(function(n){var t=n.id;return e===t});if(n)return n.options}}(r),a=function(n){var e=Array.isArray(n)?n:[n];return function(n){var t=e.map(function(n){var t=n.map,e=n.options;e.addType(),e.addCenter();var r=t(google.maps.Map,e);return e.get("boundmap")&&r.centerMap(google.maps.LatLngBounds),e.get("autozoom")&&r.setZoom(google.maps.event),r.getMap()});"function"==typeof n&&n(t)}}(r);window.mapLoaded=a;var i={addCallback:function(n){return window.mapLoaded=u(a,n),i},addCenter:function(n,t,e){var r=o(n);return r&&r.update({lat:t,lng:e,centermap:!0}),i},addConfig:function(n,t){var e=o(n);return e&&e.update(t),i},addLibraries:function(n,t){var e=o(n);return e&&e.update({libraries:t}),i},addType:function(n,t){var e=o(n);return e&&e.update({type:t}),i},getMaps:function(){return r},load:function(){var n=r.reduce(function(n,t){var e=t.options;return n.concat(e.get("libraries"))},[]);s(e.getPath("mapLoaded")).addPlugins(n).load()},setBounds:function(n){var t=o(n);return t&&t.update({boundmap:!0}),i},setZoom:function(n,t){var e=o(n);return e&&e.update({zoom:t,autozoom:!0}),i}};return i}}});
//# sourceMappingURL=index.js.map