silverstripe-webpack/app/client/dist/js/app_Site.Controllers.MapElementController.js
2020-12-28 06:37:21 +07:00

1 line
14 KiB
JavaScript

!function(){"use strict";var e={609:function(e){e.exports=jQuery}},o={};function __webpack_require__(t){if(o[t])return o[t].exports;var n=o[t]={exports:{}};return e[t](n,n.exports,__webpack_require__),n.exports}__webpack_require__.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return __webpack_require__.d(o,{a:o}),o},__webpack_require__.d=function(e,o){for(var t in o)__webpack_require__.o(o,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},__webpack_require__.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},function(){var e=__webpack_require__(609),o=__webpack_require__.n(e),t="ajax-load",n="load",a="map-loaded",r="map-api-loaded",i="map-marker-click",c="map-popup-close";function _typeof(e){return(_typeof="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function _typeof(e){return typeof e}:function _typeof(e){return e&&"function"===typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _defineProperties(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _setPrototypeOf(e,o){return(_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(e,o){return e.__proto__=o,e})(e,o)}function _createSuper(e){var o=function _isNativeReflectConstruct(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function _createSuperInternal(){var t,n=_getPrototypeOf(e);if(o){var a=_getPrototypeOf(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return _possibleConstructorReturn(this,t)}}function _possibleConstructorReturn(e,o){return!o||"object"!==_typeof(o)&&"function"!==typeof o?_assertThisInitialized(e):o}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var l={init:function init(){return function(e){!function _inherits(e,o){if("function"!==typeof o&&null!==o)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(o&&o.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),o&&_setPrototypeOf(e,o)}(GoogleMapsHtmlOverlay,google.maps.OverlayView);var t=_createSuper(GoogleMapsHtmlOverlay);function GoogleMapsHtmlOverlay(e){var o;!function _classCallCheck(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,GoogleMapsHtmlOverlay);var n=_assertThisInitialized(o=t.call(this));return n.setMap(e.map),n.position=e.position,n.html=e.html?e.html:'<div class="mapboxgl-marker"><i class="marker-icon fas fa-map-marker-alt"></i></div>',n.divClass=e.divClass,n.align=e.align,n.isDebugMode=e.debug,n.onClick=e.onClick,n.onMouseOver=e.onMouseOver,n.isBoolean=function(e){return"boolean"===typeof e},n.isNotUndefined=function(e){return"undefined"!==typeof e},n.hasContent=function(e){return e.length>0},n.isString=function(e){return"string"===typeof e},n.isFunction=function(e){return"function"===typeof e},o}return function _createClass(e,o,t){return o&&_defineProperties(e.prototype,o),t&&_defineProperties(e,t),e}(GoogleMapsHtmlOverlay,[{key:"onAdd",value:function onAdd(){var e=this;e.div=document.createElement("div"),e.div.style.position="absolute",e.isNotUndefined(e.divClass)&&e.hasContent(e.divClass)&&(e.div.className=e.divClass),e.isNotUndefined(e.html)&&e.hasContent(e.html)&&e.isString(e.html)&&(e.div.innerHTML=e.html),e.isBoolean(e.isDebugMode)&&e.isDebugMode&&(e.div.className="debug-mode",e.div.innerHTML='<div style="height: 10px; width: 10px; background: red; border-radius: 100%;"></div><div style="position: absolute; top: 5px; padding: 5px; width: 130px; text-align: center; font-size: 18px; text-transform: uppercase; font-weight: bolder; background: red; color: white; font-family: Arial;">Debug mode</div>',e.div.setAttribute("style","position: absolute;border: 5px dashed red;height: 150px;width: 150px;display: flex;justify-content: center;align-items: center;")),e.getPanes().overlayMouseTarget.appendChild(e.div),google.maps.event.addDomListener(e.div,"click",(function(o){google.maps.event.trigger(e,"click"),e.isFunction(e.onClick)&&e.onClick(),o.stopPropagation()})),google.maps.event.addDomListener(e.div,"mouseover",(function(o){google.maps.event.trigger(e,"mouseover"),e.isFunction(e.onMouseOver)&&e.onMouseOver(),o.stopPropagation()}))}},{key:"draw",value:function draw(){var e=this,t=o()(e.div).find(".mapboxgl-marker,.marker-pin,.mapboxgl-popup,.popup");t.length||(t=o()(e.div));var n=e.getProjection().fromLatLngToDivPixel(new google.maps.LatLng(e.position)),a={y:void 0,x:void 0},r=t.outerWidth(),i=t.outerHeight();switch(Array.isArray(e.align)?e.align.join(" "):""){case"left top":a.y=i,a.x=r;break;case"left center":a.y=i/2,a.x=r;break;case"left bottom":a.y=0,a.x=r;break;case"center top":a.y=i,a.x=r/2;break;case"center center":a.y=i/2,a.x=r/2;break;case"center bottom":a.y=0,a.x=r/2;break;case"right top":a.y=i,a.x=0;break;case"right center":a.y=i/2,a.x=0;break;case"right bottom":a.y=0,a.x=0;break;default:a.y=i/2,a.x=r/2}e.div.style.top="".concat(n.y-a.y,"px"),e.div.style.left="".concat(n.x-a.x,"px")}},{key:"getPosition",value:function getPosition(){return this.position}},{key:"getDiv",value:function getDiv(){return this.div}},{key:"setPosition",value:function setPosition(e,o){var t=this;t.position=e,t.align=o,t.draw()}}]),GoogleMapsHtmlOverlay}()}};function _map_google_defineProperties(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var $,s={ENVS:["xs","sm","md","lg","xl","xxl","xxxl"],MAP_DRIVER:($=o(),function(){function GoogleMapsDriver(){!function _map_google_classCallCheck(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,GoogleMapsDriver)}return function _map_google_createClass(e,o,t){return o&&_map_google_defineProperties(e.prototype,o),t&&_map_google_defineProperties(e,t),e}(GoogleMapsDriver,[{key:"getName",value:function getName(){return"GoogleMapsDriver"}},{key:"init",value:function init(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],t=this,n=window;t.$el=e,t.config=o,t.markers=[],n["init".concat(t.getName())]=function(){t.googleApiLoaded()},$("body").append('<script async defer src="https://maps.googleapis.com/maps/api/js?key='.concat(o.key,"&callback=init").concat(t.getName(),'"><\/script>'))}},{key:"googleApiLoaded",value:function googleApiLoaded(){var e=this,o=e.$el,t=e.config,n=o.find(".mapAPI-map"),a=t.mapZoom?t.mapZoom:10,i=t.center?{lat:t.center[1],lng:t.center[0]}:{lat:0,lng:0},c=t.style?t.style:null;console.log("".concat(e.getName(),": API is loaded")),e.MarkerUI=l.init($),e.map=new google.maps.Map(n[0],{zoom:a,center:i,fullscreenControl:!0,styles:c}),e.default_zoom=a,n.addClass("mapboxgl-map"),e.popup=new e.MarkerUI({map:e.map,align:["center","top"],divClass:"mapboxgl-popup popup mapboxgl-popup-anchor-bottom d-none",html:'<div class="mapboxgl-popup-tip"></div><div class="mapboxgl-popup-content"><div class="mapboxgl-popup-close-button" type="button" aria-label="Close popup">\xd7</div><div class="html"></div></div>'}),e.geocoder=new google.maps.Geocoder,o.trigger(r)}},{key:"addMarker",value:function addMarker(e,o){var t=this,n={lat:e[1],lng:e[0]},a=new t.MarkerUI({position:n,map:t.map,align:["center","top"],html:'<div class="mapboxgl-marker"><div id="Marker'.concat(o.id,'" data-id="').concat(o.id,'" class="marker">').concat(o.icon,"</div></div>"),onClick:function onClick(){var e=$("#Marker".concat(o.id));t.showPopup(n,o.content),e.trigger(i)}});return t.markers.push(a),a}},{key:"showPopup",value:function showPopup(e,o){var t=this,n=$(t.popup.getDiv());t.config.flyToMarker&&(t.map.setCenter(e),t.config.noZoom||t.map.setZoom(18)),n.css({opacity:"0"}),n.removeClass("d-none"),n.find(".mapboxgl-popup-content .html").html(o),n.find(".mapboxgl-popup-close-button").on("click",(function(e){e.preventDefault(),t.hidePopup()})),t.popup.setPosition(e,["center","top"]),n.css({"margin-top":"-1rem",opacity:"1"})}},{key:"hidePopup",value:function hidePopup(){var e=this;$(e.popup.getDiv()).addClass("d-none"),e.config.noRestoreBounds&&!e.config.flyToBounds||e.restoreBounds(),e.$el.trigger(c)}},{key:"geocode",value:function geocode(e,o){var t=this;t.geocoder.geocode({address:e},(function(e,n){if("OK"===n)return"function"===typeof o&&o(e),e;console.error("".concat(t.getName(),": Geocode was not successful for the following reason: ").concat(n))}))}},{key:"reverseGeocode",value:function reverseGeocode(e,o){var t=this;t.geocoder.geocode({location:latlng},(function(e,n){if("OK"===n)return"function"===typeof o&&o(e),e;console.error("".concat(t.getName(),": Reverse Geocoding was not successful for the following reason: ").concat(n))}))}},{key:"addGeoJson",value:function addGeoJson(e){var o=this,t=(e.geojson.features[0].geometry.coordinates,new google.maps.LatLngBounds);e.geojson.features.forEach((function(n){var a=n.id,r=n.geometry.coordinates,i=n.properties.content;o.addMarker(r,{id:a,content:i,icon:n.icon,flyToMarker:e.flyToMarker}),t.extend({lat:r[1],lng:r[0]})})),o.markers.length>1?o.map.fitBounds(t,{padding:30}):o.markers[0]&&o.map.setCenter(o.markers[0].getPosition()),o.default_bounds=t,o.default_zoom=o.map.getZoom()}},{key:"getMap",value:function getMap(){return this.map}},{key:"getPopup",value:function getPopup(){return this.popup}},{key:"restoreBounds",value:function restoreBounds(){var e=this;e.default_bounds&&e.markers.length>1?e.map.fitBounds(e.default_bounds,{padding:30}):(e.markers[0]&&e.map.setCenter(e.markers[0].getPosition()),e.restoreZoom())}},{key:"restoreZoom",value:function restoreZoom(){this.map.setZoom(this.default_zoom)}}]),GoogleMapsDriver}())},jQuery=__webpack_require__(609);function _ui_map_api_defineProperties(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}!function($){var e="jsMapAPI",o=e,i=$("body"),c=s.MAP_DRIVER,l=window,p=function(){function MapAPI(t){!function _ui_map_api_classCallCheck(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,MapAPI);var n=this,l=new c;n.$el=$(t);var s=n.$el,p=s.data();p.center=[p.lng?p.lng:i.data("default-lng"),p.lat?p.lat:i.data("default-lat")],p.style=p.style?jQuery.parseJSON(p.style):null,p["font-family"]=i.css("font-family"),p.icon||(p.icon='<i class="fas fa-map-marker-alt"></i>'),console.log("".concat(e,": init ").concat(l.getName(),"...")),l.init(s,p),n.drv=l,s.on(r,(function(t){if(n.map=l.getMap(),p.geojson)console.log("".concat(e,": setting up geocode data")),l.addGeoJson(p);else if(p.address)console.log(p.address),console.log("".concat(e,": setting up address marker")),l.geocode(p.address,(function(o){console.log(o);var t=o[0].geometry.location.lat(),a=o[0].geometry.location.lng();console.log("".concat(e,": setting up single lat/lng marker lat: ").concat(t," lng: ").concat(a)),l.addMarker([a,t],p),n.map.setCenter({lat:t,lng:a})}));else if(p.lat&&p.lng){var r=p.lat,i=p.lng;console.log("".concat(e,": setting up single lat/lng marker lat: ").concat(r," lng: ").concat(i)),l.addMarker([i,r],p)}s.data(o,n),s.addClass("".concat(e,"-active")),s.trigger(a),console.log("".concat(e,": Map is loaded"))}))}return function _ui_map_api_createClass(e,o,t){return o&&_ui_map_api_defineProperties(e.prototype,o),t&&_ui_map_api_defineProperties(e,t),e}(MapAPI,[{key:"getMap",value:function getMap(){return ui.map}},{key:"dispose",value:function dispose(){var t=this;t.$el=null,$.removeData(t.$el[0],o),t.$el.removeClass("".concat(e,"-active"))}}],[{key:"_jQueryInterface",value:function _jQueryInterface(){var e=this;if("undefined"!==typeof l.localStorage)return this.each((function(){var t=$(e),n=t.data(o);n||(n=new MapAPI(e),t.data(o,n))}))}}]),MapAPI}();$.fn[e]=p._jQueryInterface,$.fn[e].Constructor=p,$.fn[e].noConflict=function(){return $.fn[e]=JQUERY_NO_CONFLICT,p._jQueryInterface},$(l).on("".concat(t," ").concat(n),(function(){$(".mapAPI-map-container").jsMapAPI()}))}(o());function Site_Controllers_MapElementController_defineProperties(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}!function($){var e=window,o=(document,$("body")),r="LocationUI",l=function(){function LocationUI(){!function Site_Controllers_MapElementController_classCallCheck(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,LocationUI)}return function Site_Controllers_MapElementController_createClass(e,o,t){return o&&Site_Controllers_MapElementController_defineProperties(e.prototype,o),t&&Site_Controllers_MapElementController_defineProperties(e,t),e}(LocationUI,null,[{key:"init",value:function init(){this.dispose(),console.log("Initializing: ".concat(r))}},{key:"initMap",value:function initMap(){$(".mapAPI-map-container").find(".marker").on("".concat(i),(function(e){var t=$(e.currentTarget).data("id");o.find(".locations .location").removeClass("active"),o.find('.locations .location[data-id="'.concat(t,'"]')).addClass("active")})),o.find(".locations .location").on("click",(function(e){var t=$(e.currentTarget).data("id");o.find("#Marker".concat(t)).click()})),$(".mapAPI-map-container").on(c,(function(e){o.find(".locations .location").removeClass("active")}))}},{key:"dispose",value:function dispose(){console.log("Destroying: ".concat(r))}}]),LocationUI}();$(e).on("".concat(t," ").concat(n),(function(){l.init()})),$(e).on(a,(function(){l.initMap()}))}(o())}()}();