-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery-geopicker.min.js
More file actions
1 lines (1 loc) · 3.75 KB
/
jquery-geopicker.min.js
File metadata and controls
1 lines (1 loc) · 3.75 KB
1
!function(e){function t(){}var a;e.fn.geoPicker=function(t,r,n,i){var c={address2geo:function(e,t){GMaps.geocode({address:e,callback:t})},setSearchMarker:function(t,r,n,i,c){t.setCenter(n,i),t.setZoom(c?c:6),s.searchMarker&&t.removeMarker(s.searchMarker),s.searchMarker=t.addMarker({lat:n,lng:i,title:e(inputElement).data("geopicker").searchTitle,icon:e(inputElement).data("geopicker").searchIcon,click:function(e){a({latLng:e.position}),t.removeMarker(s.searchMarker)}})}};switch(typeof t){case"undefined":case"object":return this.each(function(){var r,n,i,c,o;if(!e(this).data().hasOwnProperty("geopicker")){var l=function(){e(c).geoPicker("search",this.value)};if(c=e(this),s=e.extend({id:c.attr("id")+"-geopicker",insertAfter:c},e.fn.geoPicker.defaults,t||{},{searchMarker:i}),s.el=s.id,o=e(s.template.replace(/:id/g,s.id).replace(":class",s.class).replace(":style",s.style)).insertAfter(s.insertAfter),r=new GMaps(s),s.addSearch&&(r.addControl({content:s.searchTemplate.replace(":searchLabel",s.searchLabel).replace(":searchPlaceholder",s.searchPlaceholder),position:"top_right"}),e(o).on("change","input.geopicker-search",l),e(o).on("click","button.geopicker-btn",function(){l.call(e(this).parent().children("input.geopicker-search").get(0))}),e(o).on("keypress","input.geopicker-search",function(e){13==e.keyCode&&(e.stopPropagation(),e.preventDefault(),l.call(this))})),e(this).data("geopicker",s).data("gmap",r).data("map",o),e(o).data("input",c),c.val()){var p=c.val().split(",");n=r.addMarker({lat:p[0],lng:p[1],icon:s.chooseIcon}),r.setCenter(p[0],p[1])}a=function(e){s.hasOwnProperty("onPick")&&"function"==typeof s.onPick&&s.onPick.call(c,[e.latLng.lat(),e.latLng.lng()],e)===!1||(n&&r.removeMarker(n),n=r.addMarker({title:s.pickedTitle,lng:e.latLng.lng(),lat:e.latLng.lat(),icon:s.chooseIcon}),r.setCenter(e.latLng.lat(),e.latLng.lng()),c.val(e.latLng.lat()+","+e.latLng.lng()),c.data("marker",n))},r.on("click",a)}});case"string":switch(t){case"gmap":return e(this).first().data("gmap");case"set":return a({latLng:new google.maps.LatLng(r,n)}),this;case"options":return e(this).first().data("geopicker");case"map":return e(this).first().data("map");case"remove":return this.each(function(){var t=e(this).data("map");t&&(t.remove(),e(this).removeData("geopicker").removeData("gmap").removeData("map"))});case"search":if(inputElement=e(this).first(),e(inputElement).data().hasOwnProperty("geopicker")){var s=e(inputElement).data("geopicker"),o=e(inputElement).data("gmap");c.address2geo(r,function(t,a){if("OK"===a){if(0===t.length)return;var r=t[0].geometry.location;c.setSearchMarker(o,s.searchMarker,r.lat(),r.lng(),10),o.fitLatLngBounds([t[0].geometry.viewport.getNorthEast(),t[0].geometry.viewport.getSouthWest()]),e(inputElement).data("geopicker",s)}})}return this;case"suggest":if(inputElement=e(this).first(),e(inputElement).data().hasOwnProperty("geopicker")&&r&&n){var s=e(inputElement).data("geopicker"),o=e(inputElement).data("gmap");lat=r,lng=n,c.setSearchMarker(o,s.searchMarker,lat,lng,i?i:10),e(inputElement).data("geopicker",s)}return this;case"unsetGeolocation":var l=e(this).data("gmap"),p=e(this).data("marker");return l&&p&&(l.removeMarker(p),p=null,e(this).removeData("marker")),this}}},e.fn.geoPicker.defaults={template:"<div id=':id' style=':style' class='geopicker-container :class'></div>",searchTemplate:"<input class='geopicker-search' placeholder=':searchPlaceholder' /><button class='geopicker-btn' type='button'>:searchLabel</button>",searchLabel:"Search",searchPlaceholder:"Search",searchTitle:"Search result",searchIcon:"http://maps.google.com/mapfiles/ms/icons/green-dot.png","class":"gllpMaps",style:"height: 200px; width: 100%; position: relative;",lat:21.4224843,lng:39.8262017,zoom:12,autoFit:!0,disableDefaultUI:!1,streetViewControl:!1,mapTypeControl:!1,onPick:t,addSearch:!0}}(jQuery);