"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,o,r){return o&&e(t.prototype,o),r&&e(t,r),t}}(),_get=function e(t,o,r){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,o);if(void 0===i){var s=Object.getPrototypeOf(t);return null===s?void 0:e(s,o,r)}if("value"in i)return i.value;var n=i.get;return void 0!==n?n.call(r):void 0};function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}!function(e){DRTS.Map.googlemaps={styles:{}},DRTS.Map.googlemaps.map=function(t){function o(t,r){_classCallCheck(this,o);var i=_possibleConstructorReturn(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,r));i.markerClusterer=null,i.overlay=null,i.currentCircle=null;var s=[];for(var n in google.maps.MapTypeId)s.push(google.maps.MapTypeId[n]);var a={mapTypeId:-1!==e.inArray(i.options.type,s)?i.options.type:google.maps.MapTypeId.ROADMAP,mapTypeControl:!(void 0!==i.options.map_type_control&&!i.options.map_type_control),zoomControl:!0,streetViewControl:i.options.street_view_control||!1,scaleControl:!1,rotateControl:!1,fullscreenControl:i.options.fullscreen_control||!1,center:new google.maps.LatLng(i.options.default_location.lat,i.options.default_location.lng),scrollwheel:i.options.scrollwheel,styles:i.options.style&&DRTS.Map.googlemaps.styles[i.options.style]?DRTS.Map.googlemaps.styles[i.options.style]:[{featureType:"poi",stylers:[{visibility:"off"}]}],zoom:i.options.default_zoom};if(a.mapTypeControl&&(a.mapTypeControlOptions={style:google.maps.MapTypeControlStyle.DROPDOWN_MENU,mapTypeIds:s,position:google.maps.ControlPosition.TOP_RIGHT}),i.map=new google.maps.Map(i.$map.get(0),a),i.options.marker_clusters){var l=i.options.marker_cluster_color||null,p={render:function(e,t){var o=e.count,r=e.position,i=l||(o>Math.max(10,t.clusters.markers.mean)?"#ff0000":"#0000ff"),s=window.btoa('\n  <svg fill="'+i+'" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240">\n    <circle cx="120" cy="120" opacity=".6" r="70" />\n    <circle cx="120" cy="120" opacity=".3" r="90" />\n    <circle cx="120" cy="120" opacity=".2" r="110" />\n  </svg>');return new google.maps.Marker({position:r,icon:{url:"data:image/svg+xml;base64,"+s,scaledSize:new google.maps.Size(45,45)},label:{text:String(o),color:"rgba(255,255,255,0.9)",fontSize:"12px"},title:"Cluster of "+o+" markers",zIndex:Number(google.maps.Marker.MAX_ZINDEX)+o})}};i.markerClusterer=new markerClusterer.MarkerClusterer({map:i.map,renderer:p})}if(i.options.infobox){i.getPopover(),i.getOverlay();var c=function(){i.getPopover().sabaiPopover("hide"),i.currentMarker=null};google.maps.event.addListener(i.map,"dragstart",c),google.maps.event.addListener(i.map,"zoom_changed",c),e(window).on("resize",c)}return i.map.getStreetView().setOptions({disableDefaultUI:!0,enableCloseButton:a.streetViewControl,zoomControl:!0,visible:!1,addressControlOptions:{position:google.maps.ControlPosition.RIGHT_TOP}}),google.maps.event.addListener(i.map,"click",(function(e){i.container.trigger("map_clicked.sabai",{map:i.map,latlng:[e.latLng.lat(),e.latLng.lng()]})})),google.maps.event.addListener(i.map,"zoom_changed",(function(e){i.container.trigger("map_zoom_changed.sabai",{map:i.map,zoom:i.map.getZoom()})})),google.maps.event.addListener(i.map,"dragend",(function(e){i.container.trigger("map_dragend.sabai",{map:i.map})})),google.maps.event.addListener(i.map,"mousedown",(function(e){i.container.trigger("map_mousedown.sabai",{map:i.map,latlng:[e.latLng.lat(),e.latLng.lng()]})})),i}return _inherits(o,DRTS.Map.map),_createClass(o,[{key:"clearMarkers",value:function(){for(var e in this.markers)this.markers.hasOwnProperty(e)&&this.markers[e].setMap(null);return this.markerClusterer&&this.markerClusterer.clearMarkers(),_get(o.prototype.__proto__||Object.getPrototypeOf(o.prototype),"clearMarkers",this).call(this)}},{key:"addMarker",value:function(t){if(!t.lat||!t.lng)return this;var o=void 0,r=void 0;if(this.options.marker_custom)if(t.icon){var i={html:t.icon.url?e("<img/>").attr("src",t.icon.url)[0].outerHTML:null,icon:t.icon.icon||this.options.marker_icon,icon_color:t.icon.icon_color||this.options.marker_icon_color,full:!!t.icon.is_full,size:t.icon.size||this.options.marker_size,color:t.icon.color||this.options.marker_color||"#fff",event:this.options.infobox_event};o=new DRTS.Map.googlemaps.map.marker(i)}else void 0===r&&(r={icon:this.options.marker_icon||"",icon_color:this.options.marker_icon_color,size:this.options.marker_size,color:this.options.marker_color||"#fff",event:this.options.infobox_event}),o=new DRTS.Map.googlemaps.map.marker(r);else o=new google.maps.Marker;return o.setPosition(new google.maps.LatLng(t.lat,t.lng)),o.set("id",t.entity_id+"-"+t.index),o.set("content",t.content),o.set("entity_id",t.entity_id),o.set("key",t.index),this.markers[o.get("id")]=o,this}},{key:"getMarkerLatlng",value:function(e){if(null==e){var t=Object.keys(this.markers)[0];e=this.markers[t]}var o=e.getPosition();return[o.lat(),o.lng()]}},{key:"getMarkerContent",value:function(e){return e.get("content")}},{key:"getMarkerPosition",value:function(e){if(this.getOverlay()&&this.getOverlay().getProjection())return this.getOverlay().getProjection().fromLatLngToContainerPixel(e.getPosition())}},{key:"getMarkerHeight",value:function(e){return e.get("marker_height")}},{key:"getMarkerEntityId",value:function(e){return e.get("entity_id")}},{key:"getMarkerKey",value:function(e){return e.get("key")}},{key:"draw",value:function(t){var o=this;if(t=t||{},this.currentMarker=null,this.currentCircle&&this.currentCircle.setMap(null),Object.keys(this.markers).length>0){var r=void 0;for(var i in(void 0===t.fit_bounds?this.options.fit_bounds:t.fit_bounds)&&Object.keys(this.markers).length>1&&(r=new google.maps.LatLngBounds),this.markers)if(this.markers.hasOwnProperty(i)){if(this.markerClusterer||this.markers[i].setMap(this.map),r){var s=this.markers[i].getPosition();r.extend(s),t.center&&r.extend(new google.maps.LatLng(2*t.center[0]-s.lat(),2*t.center[1]-s.lng()))}google.maps.event.addListener(this.markers[i],this.options.infobox_event,function(e){return function(t){o.clickMarker(e)}}(this.markers[i])),Object.keys(this.markers).length<=100&&(this.markers[i].setAnimation(google.maps.Animation.BOUNCE),setTimeout(function(e){return function(){e.setAnimation(null)}}(this.markers[i]),500))}if(this.markerClusterer&&this.markerClusterer.addMarkers(Object.values(this.markers)),r)this.map.fitBounds(r,void 0===t.fit_bounds_padding?this.options.fit_bounds_padding:t.fit_bounds_padding);else if(!t.center)if(this.options.center_default)t.center=[this.options.default_location.lat,this.options.default_location.lng];else{var n=this.markers[Object.keys(this.markers)[0]].getPosition();t.center=[n.lat(),n.lng()]}t.street_view&&this.drawStreetView("object"===_typeof(t.street_view)?t.street_view:this.markers[Object.keys(this.markers)[0]])}if(t.center){var a=new google.maps.LatLng(t.center[0],t.center[1]);this.map.setZoom(t.zoom||this.options.default_zoom||10),this.map.panTo(a),t.circle&&(this.currentCircle=new google.maps.Circle({strokeColor:t.circle.stroke_color||"#99f",strokeOpacity:.8,strokeWeight:1,fillColor:t.circle.fill_color||"#99f",fillOpacity:.3,map:this.map,center:a,radius:t.circle.radius}))}return e(DRTS).trigger("map_drawn.sabai",{map:this}),this}},{key:"clickMarker",value:function(e,t){if(this.currentMarker){if(this.currentMarker.get("id")===e.get("id"))return this.showMarkerContent(e,t),this.currentMarker=e,void(t||this.container.trigger("marker_click.sabai",{map:this,marker:e}));this.currentMarker.setZIndex(0)}e.setZIndex(1),this.markerClusterer&&(this.currentMarker&&this.markerClusterer.addMarker(this.currentMarker),this.markerClusterer.removeMarker(e),e.setMap(this.map)),this.map.getBounds()&&!this.map.getBounds().contains(e.getPosition())&&this.map.panTo(e.getPosition()),this.markerClusterer?setTimeout(function(){this.showMarkerContent(e,t)}.bind(this),100):this.showMarkerContent(e,t),this.currentMarker=e,t||this.container.trigger("marker_click.sabai",{map:this,marker:e})}},{key:"animateMarker",value:function(e){e.setAnimation(google.maps.Animation.BOUNCE),setTimeout((function(){e.setAnimation(null)}),1e3)}},{key:"onResized",value:function(){return this.getOverlay(!0),google.maps.event.trigger(this.map,"resize"),this}},{key:"getZoom",value:function(){return this.map.getZoom()}},{key:"getSouthWest",value:function(){var e=this.map.getBounds();return[e.getSouthWest().lat(),e.getSouthWest().lng()]}},{key:"getNorthEast",value:function(){var e=this.map.getBounds();return[e.getNorthEast().lat(),e.getNorthEast().lng()]}},{key:"getOverlay",value:function(e){return this.overlay&&!e||(this.overlay=new google.maps.OverlayView,this.overlay.draw=function(){},this.overlay.setMap(this.map)),this.overlay}},{key:"drawStreetView",value:function(e,t,o){var r=new google.maps.StreetViewService,i=this.map,s=void 0;return e.setMap&&(s=e,e=e.getPosition()),r.getPanorama({location:e,radius:t||50},(function(t,r){if(r===google.maps.StreetViewStatus.OK){var n=i.getStreetView();if(n.setPosition(t.location.latLng),s){var a=google.maps.geometry.spherical.computeHeading(t.location.latLng,e);n.setPov({heading:a,pitch:0,zoom:1}),s.setMap(n)}n.setVisible(!0),n.setOptions({enableCloseButton:!1})}else o&&alert("No street map view is available for this location."),console.log(r)})),this}}]),o}(),DRTS.Map.api.getMap=function(e,t){return new DRTS.Map.googlemaps.map(e,t)},DRTS.Map.googlemaps.map.marker=function(e){this.options=e||{},this.visible=!0,this.classes=this.options.full?["drts-map-marker drts-map-marker-full"]:["drts-map-marker"],this.div=null},DRTS.Map.googlemaps.map.marker.prototype=new google.maps.OverlayView,DRTS.Map.googlemaps.map.marker.prototype.onAdd=function(){var e=this;if(this.div=document.createElement("div"),this.div.className=this.classes.join(" "),this.options.full)this.div.innerHTML=this.options.html;else{var t=this.options.size||38,o=document.createElement("div");this.div.style.width=t+"px",this.div.style.height=t+"px",this.div.style.marginTop="-"+(t*Math.sqrt(2)-DRTS.Map.markerHeight(t))+"px",this.options.color&&(this.div.style.backgroundColor=this.div.style.color=o.style.borderColor=this.options.color),this.options.html?o.innerHTML=this.options.html:this.options.icon?(o.innerHTML='<i class="'+this.options.icon+'"></i>',this.options.icon_color&&(o.style.backgroundColor=this.options.icon_color)):(o.style.boxShadow="none",this.options.icon_color&&(o.style.backgroundColor=this.options.icon_color)),this.div.appendChild(o),this.set("marker_height",DRTS.Map.markerHeight(t))}this.options.data&&(this.div.dataset=this.options.data),this.getPanes().overlayImage.appendChild(this.div);var r=this.options.event;this.div.addEventListener(r,(function(t){google.maps.event.trigger(e,r)})),this.setPosition(this.position)},DRTS.Map.googlemaps.map.marker.prototype.draw=function(){this.setPosition(this.position)},DRTS.Map.googlemaps.map.marker.prototype.setPosition=function(e){if(this.position=e,this.div){var t=this.getProjection().fromLatLngToDivPixel(this.position);t&&(this.div.style.left=t.x+"px",this.div.style.top=t.y+"px")}},DRTS.Map.googlemaps.map.marker.prototype.onRemove=function(){this.div&&this.div.parentNode.removeChild(this.div),this.div=null},DRTS.Map.googlemaps.map.marker.prototype.getPosition=function(){return this.position},DRTS.Map.googlemaps.map.marker.prototype.setDraggable=function(e){this.draggable=e},DRTS.Map.googlemaps.map.marker.prototype.getDraggable=function(){this.draggable},DRTS.Map.googlemaps.map.marker.prototype.getVisible=function(){return this.visible},DRTS.Map.googlemaps.map.marker.prototype.setVisible=function(e){this.div&&(this.div.style.display=e?"inline-block":"none"),this.visible=e},DRTS.Map.googlemaps.map.marker.prototype.getDraggable=function(){return this.draggable},DRTS.Map.googlemaps.map.marker.prototype.setDraggable=function(e){this.draggable=e},DRTS.Map.googlemaps.map.marker.prototype.setZIndex=function(e){this.zIndex=e,this.div&&(this.div.style.zIndex=this.zIndex)},DRTS.Map.googlemaps.map.marker.prototype.setAnimation=function(e){var t="drts-map-marker-bounce";if(e)-1===this.classes.indexOf(t)&&this.classes.push(t);else{var o=this.classes.indexOf(t);o>-1&&this.classes.splice(o,1)}this.div&&(this.div.className=this.classes.join(" "))}}(jQuery);