-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmap-input-widget.min.js
1 lines (1 loc) · 2.85 KB
/
map-input-widget.min.js
1
function MapInputWidgetManager(){const t=".kolyunya-map-input-widget";var n=Array(),e=function(t){if(!$(t).data("initialized")){var n=new MapInputWidget(t);return n.initialize(),n}return null},a=function(t){var e=t.getId();n[e]=t};this.initializeWidgets=function(){$(t).each(function(t,n){var i=e(n);i&&a(i)})},this.getWidget=function(t){var e=n[t];return e}}function MapInputWidget(t){const n="input.kolyunya-map-input-widget-input",e="input.kolyunya-map-input-widget-search-bar",a="div.kolyunya-map-input-widget-canvas";var i,o,r,u,l=this,p=function(){i=$(t).find(n).get(0),o=$(t).find(e).get(0),r=$(t).find(a).get(0)},d=function(){u=new google.maps.Map(r,{mapTypeId:$(t).data("map-type"),center:h(),zoom:$(t).data("zoom"),styles:[{featureType:"poi",stylers:[{visibility:"off"}]}],mapTypeControlOptions:{mapTypeIds:[]}}),google.maps.event.addListener(u,"click",function(t){l.setPosition({latitude:t.latLng.lat(),longitude:t.latLng.lng()})})},g=function(){var n=m();l.setPosition(n),$(t).data("initialized",!0)},s=function(){var n=$(t).data("enable-search-bar"),e=!n;$(o).prop("hidden",e),searchBarAutocomplete=new google.maps.places.Autocomplete(o),u.controls[google.maps.ControlPosition.TOP_LEFT].push(o),google.maps.event.addListener(searchBarAutocomplete,"place_changed",function(){var t=this.getPlace(),n=t.geometry;if(n){var e=n.location;l.setPosition(e)}})},c=function(t){var n=y(),e=L(t);return n=n.replace(/%latitude%/g,e.lat()),n=n.replace(/%longitude%/g,e.lng())},f=function(){var t=""!=$(i).prop("value");return t},m=function(){var t,n=y(),e=$(i).prop("value");if(""!==e){var a=n.indexOf("%latitude%"),o=n.indexOf("%longitude%"),r=o>a,u=r?0:1,l=r?1:0,p=e.match(/-?\d+(\.\d+)?/g)[u],d=e.match(/-?\d+(\.\d+)?/g)[l];t=new google.maps.LatLng(p,d)}else t=null;return t},v=function(){var n=$(t).data("latitude"),e=$(t).data("longitude"),a=new google.maps.LatLng(n,e);return a},h=function(){var t;return t=f()?m():v()},y=function(){var n=$(t).data("pattern");return n},L=function(t){var n;if(void 0!==t.latitude&&void 0!==t.longitude){var e=t.latitude,a=t.longitude;n=new google.maps.LatLng(e,a)}else n=t;return n};this.initialize=function(){$(t).trigger("initialize:before"),p(),d(),g(),s(),$(t).trigger("initialize:after",{MapInputWidget:this})},this.getId=function(){var n=$(t).prop("id");return n},this.setPosition=function(n){if(u.marker&&u.marker.setMap(null),null===n)return void $(i).prop("disabled",!0);$(i).prop("disabled",!1);var e=L(n);1===$(t).data("align-map-center")&&u.panTo(e);var a=null;1===$(t).data("animate-marker")&&(a=google.maps.Animation.DROP),u.marker=new google.maps.Marker({map:u,position:e,draggable:!0,animation:a}),google.maps.event.addListener(u.marker,"dragend",function(){l.setPosition(this.getPosition())});var o=($(t).data("pattern"),c(e));$(i).prop("value",o)},this.panTo=function(t){var n=L(t);u.panTo(n)},this.setZoom=function(t){u.setZoom(t)},this.getMap=function(){return u}}