yavsc/Yavsc/wwwroot/js/google-geoloc.min.js

1 line
1.8 KiB
JavaScript

if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(t,e){t.widget("psc.googlegeocode",{options:{mapId:"map",longId:"Longitude",latId:"Latitude",addrValidationId:"AddressError",formValidId:"ValidationSummary",locComboId:"LocationCombo"},marker:null,gmap:null,_create:function(){this.element.addClass("googlegeocode"),this.gmap=new e.Map(document.getElementById(this.options.mapId),{zoom:16,center:{lat:48.862854,lng:2.2056466}});var o=this;this.element.rules("add",{remote:{url:"https://maps.googleapis.com/maps/api/geocode/json",type:"get",data:{sensor:!1,address:function(){return o.element.val()}},dataType:"json",dataFilter:function(e){t("#"+o.options.locComboId).html("");var a=JSON.parse(e);return a.results.forEach(function(e){e.formatted_address!==o.element.val()&&t("<li>"+e.formatted_address+"</li>").data("geoloc",e).click(function(){o.chooseLoc("user",e)}).css("cursor","pointer").appendTo(t("#"+o.options.locComboId))}),"OK"===a.status&&1==a.results.length?!0:!1},error:function(){return!1}}})},chooseLoc:function(o,a){"user"===o&&this.element.val(a.formatted_address);var n=a.geometry.location,r=new Number(n.lat),i=new Number(n.lng);return t(document.getElementById(this.options.latId)).val(r.toLocaleString("en")),t(document.getElementById(this.options.longId)).val(i.toLocaleString("en")),this.gmap.setCenter(n),this.marker&&this.marker.setMap(null),this.marker=new e.Marker({map:this.gmap,draggable:!0,animation:e.Animation.DROP,position:n}),e.event.addListener(this.marker,"dragend",function(){var e=this.marker.getPosition();t("#"+this.options.latId).val(e.lat),t("#"+this.options.longId).val(e.lng)}),this.element.valid(),t("#"+this.options.addrValidationId).empty(),t("#"+this.options.formValidId).empty(),t("#"+this.options.locComboId).empty(),this}})}(jQuery,google.maps);