From 5ef835e59baaaee4db4ad5ac4acfd8f8a990f8d8 Mon Sep 17 00:00:00 2001 From: Mohamed Dardouri Date: Sun, 3 May 2015 14:47:11 +0100 Subject: [PATCH 1/5] allowed update inputs Inputs now can be updated from javascript & locationNameInput update where lat/long inputs updated --- src/locationpicker.jquery.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/locationpicker.jquery.js b/src/locationpicker.jquery.js index c1d8df2..6451fe2 100644 --- a/src/locationpicker.jquery.js +++ b/src/locationpicker.jquery.js @@ -151,24 +151,24 @@ if (!inputBinding) return; var currentLocation = GmUtility.locationFromLatLng(gmapContext.location); if (inputBinding.latitudeInput) { - inputBinding.latitudeInput.val(currentLocation.latitude).change(); + inputBinding.latitudeInput.val(currentLocation.latitude).trigger("change", true); } if (inputBinding.longitudeInput) { - inputBinding.longitudeInput.val(currentLocation.longitude).change(); + inputBinding.longitudeInput.val(currentLocation.longitude).trigger("change", true); } if (inputBinding.radiusInput) { - inputBinding.radiusInput.val(gmapContext.radius).change(); + inputBinding.radiusInput.val(gmapContext.radius).trigger("change", true); } if (inputBinding.locationNameInput) { - inputBinding.locationNameInput.val(gmapContext.locationName).change(); + inputBinding.locationNameInput.val(gmapContext.locationName).trigger("change", true); } } function setupInputListenersInput(inputBinding, gmapContext) { if (inputBinding) { if (inputBinding.radiusInput){ - inputBinding.radiusInput.on("change", function(e) { - if (!e.originalEvent) { return } + inputBinding.radiusInput.on("change", function(e, isInternal) { + if (isInternal) { return } gmapContext.radius = $(this).val(); GmUtility.setPosition(gmapContext, gmapContext.location, function(context){ context.settings.onchanged.apply(gmapContext.domContainer, @@ -193,12 +193,12 @@ }); }); if(gmapContext.settings.enableAutocompleteBlur) { - inputBinding.locationNameInput.on("change", function(e) { - if (!e.originalEvent) { return } + inputBinding.locationNameInput.on("change", function(e, isInternal) { + if (isInternal) { return } blur = true; }); - inputBinding.locationNameInput.on("blur", function(e) { - if (!e.originalEvent) { return } + inputBinding.locationNameInput.on("blur", function(e, isInternal) { + if (isInternal) { return } setTimeout(function() { var address = $(inputBinding.locationNameInput).val(); if (address.length > 5 && blur) { @@ -218,21 +218,26 @@ } } if (inputBinding.latitudeInput) { - inputBinding.latitudeInput.on("change", function(e) { - if (!e.originalEvent) { return } + inputBinding.latitudeInput.on("change", function(e, isInternal) { + if (isInternal) { return } GmUtility.setPosition(gmapContext, new google.maps.LatLng($(this).val(), gmapContext.location.lng()), function(context){ context.settings.onchanged.apply(gmapContext.domContainer, [GmUtility.locationFromLatLng(context.location), context.radius, false]); + updateInputValues(inputBinding, gmapContext); }); + + }); } if (inputBinding.longitudeInput) { - inputBinding.longitudeInput.on("change", function(e) { - if (!e.originalEvent) { return } + inputBinding.longitudeInput.on("change", function(e, isInternal) { + if (isInternal) { return } GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.location.lat(), $(this).val()), function(context){ context.settings.onchanged.apply(gmapContext.domContainer, [GmUtility.locationFromLatLng(context.location), context.radius, false]); + updateInputValues(inputBinding, gmapContext); }); + }); } } @@ -402,4 +407,4 @@ onlocationnotfound: function(locationName) {}, oninitialized: function (component) {} } -}( jQuery )); \ No newline at end of file +}( jQuery )); From 65eabc3289257e2e3be55bc3dbce35aeae554edd Mon Sep 17 00:00:00 2001 From: Mohamed Dardouri Date: Sun, 3 May 2015 14:48:20 +0100 Subject: [PATCH 2/5] allowed update inputs Inputs now can be updated from javascript & locationNameInput update where lat/long inputs updated --- dist/locationpicker.jquery.js | 261 ++++++++++++++++++++-------------- 1 file changed, 152 insertions(+), 109 deletions(-) diff --git a/dist/locationpicker.jquery.js b/dist/locationpicker.jquery.js index bb1dff7..d361469 100644 --- a/dist/locationpicker.jquery.js +++ b/dist/locationpicker.jquery.js @@ -1,5 +1,4 @@ -/*! jquery-locationpicker - v0.1.12 - 2015-01-05 */ -(function($) { +(function ( $ ) { function GMapContext(domElement, options) { var _map = new google.maps.Map(domElement, options); var _marker = new google.maps.Marker({ @@ -29,7 +28,7 @@ settings: options.settings, domContainer: domElement, geodecoder: new google.maps.Geocoder() - }; + } } var GmUtility = { drawCircle: function(gmapContext, center, radius, options) { @@ -40,10 +39,10 @@ radius *= 1; options = $.extend({ strokeColor: "#0000FF", - strokeOpacity: .35, + strokeOpacity: 0.35, strokeWeight: 2, fillColor: "#0000FF", - fillOpacity: .2 + fillOpacity: 0.20 }, options); options.map = gmapContext.map; options.radius = radius; @@ -59,12 +58,11 @@ gMapContext.map.panTo(location); this.drawCircle(gMapContext, location, gMapContext.radius, {}); if (gMapContext.settings.enableReverseGeocode) { - gMapContext.geodecoder.geocode({ - latLng: gMapContext.location - }, function(results, status) { - if (status == google.maps.GeocoderStatus.OK && results.length > 0) { + gMapContext.geodecoder.geocode({latLng: gMapContext.location}, function(results, status){ + if (status == google.maps.GeocoderStatus.OK && results.length > 0){ gMapContext.locationName = results[0].formatted_address; - gMapContext.addressComponents = GmUtility.address_component_from_google_geocode(results[0].address_components); + gMapContext.addressComponents = + GmUtility.address_component_from_google_geocode(results[0].address_components); } if (callback) { callback.call(this, gMapContext); @@ -77,33 +75,36 @@ } }, locationFromLatLng: function(lnlg) { - return { - latitude: lnlg.lat(), - longitude: lnlg.lng() - }; + return {latitude: lnlg.lat(), longitude: lnlg.lng()} }, address_component_from_google_geocode: function(address_components) { var result = {}; - for (var i = address_components.length - 1; i >= 0; i--) { + for (var i = address_components.length-1; i>=0; i--) { var component = address_components[i]; - if (component.types.indexOf("postal_code") >= 0) { + if (component.types.indexOf('postal_code') >= 0) { result.postalCode = component.short_name; - } else if (component.types.indexOf("street_number") >= 0) { + } + else if (component.types.indexOf('street_number') >= 0) { result.streetNumber = component.short_name; - } else if (component.types.indexOf("route") >= 0) { + } + else if (component.types.indexOf('route') >= 0) { result.streetName = component.short_name; - } else if (component.types.indexOf("locality") >= 0) { + } + else if (component.types.indexOf('locality') >= 0) { result.city = component.short_name; - } else if (component.types.indexOf("sublocality") >= 0) { + } + else if (component.types.indexOf('sublocality') >= 0) { result.district = component.short_name; - } else if (component.types.indexOf("administrative_area_level_1") >= 0) { + } + else if (component.types.indexOf('administrative_area_level_1') >= 0) { result.stateOrProvince = component.short_name; - } else if (component.types.indexOf("country") >= 0) { + } + else if (component.types.indexOf('country') >= 0) { result.country = component.short_name; } } - result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim(); - result.addressLine2 = ""; + result.addressLine1 = [result.streetNumber, result.streetName].join(' ').trim(); + result.addressLine2 = ''; return result; } }; @@ -113,38 +114,39 @@ function getContextForElement(domObj) { return $(domObj).data("locationpicker"); } - function updateInputValues(inputBinding, gmapContext) { + function updateInputValues(inputBinding, gmapContext){ if (!inputBinding) return; var currentLocation = GmUtility.locationFromLatLng(gmapContext.location); if (inputBinding.latitudeInput) { - inputBinding.latitudeInput.val(currentLocation.latitude).change(); + inputBinding.latitudeInput.val(currentLocation.latitude).trigger("change", true); } if (inputBinding.longitudeInput) { - inputBinding.longitudeInput.val(currentLocation.longitude).change(); + inputBinding.longitudeInput.val(currentLocation.longitude).trigger("change", true); } if (inputBinding.radiusInput) { - inputBinding.radiusInput.val(gmapContext.radius).change(); + inputBinding.radiusInput.val(gmapContext.radius).trigger("change", true); } if (inputBinding.locationNameInput) { - inputBinding.locationNameInput.val(gmapContext.locationName).change(); + inputBinding.locationNameInput.val(gmapContext.locationName).trigger("change", true); } } function setupInputListenersInput(inputBinding, gmapContext) { if (inputBinding) { - if (inputBinding.radiusInput) { - inputBinding.radiusInput.on("change", function(e) { - if (!e.originalEvent) { - return; - } + if (inputBinding.radiusInput){ + inputBinding.radiusInput.on("change", function(e, isInternal) { + if (isInternal) { return } gmapContext.radius = $(this).val(); - GmUtility.setPosition(gmapContext, gmapContext.location, function(context) { - context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]); + GmUtility.setPosition(gmapContext, gmapContext.location, function(context){ + context.settings.onchanged.apply(gmapContext.domContainer, + [GmUtility.locationFromLatLng(context.location), context.radius, false]); }); }); } if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) { + var blur = false; gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0)); - google.maps.event.addListener(gmapContext.autocomplete, "place_changed", function() { + google.maps.event.addListener(gmapContext.autocomplete, 'place_changed', function() { + blur = false; var place = gmapContext.autocomplete.getPlace(); if (!place.geometry) { gmapContext.settings.onlocationnotfound(place.name); @@ -152,98 +154,141 @@ } GmUtility.setPosition(gmapContext, place.geometry.location, function(context) { updateInputValues(inputBinding, context); - context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]); + context.settings.onchanged.apply(gmapContext.domContainer, + [GmUtility.locationFromLatLng(context.location), context.radius, false]); }); }); + if(gmapContext.settings.enableAutocompleteBlur) { + inputBinding.locationNameInput.on("change", function(e, isInternal) { + if (isInternal) { return } + blur = true; + }); + inputBinding.locationNameInput.on("blur", function(e, isInternal) { + if (isInternal) { return } + setTimeout(function() { + var address = $(inputBinding.locationNameInput).val(); + if (address.length > 5 && blur) { + blur = false; + gmapContext.geodecoder.geocode({'address': address}, function(results, status) { + if(status == google.maps.GeocoderStatus.OK && results && results.length) { + GmUtility.setPosition(gmapContext, results[0].geometry.location, function(context) { + updateInputValues(inputBinding, context); + context.settings.onchanged.apply(gmapContext.domContainer, + [GmUtility.locationFromLatLng(context.location), context.radius, false]); + }); + } + }); + } + }, 1000); + }); + } } if (inputBinding.latitudeInput) { - inputBinding.latitudeInput.on("change", function(e) { - if (!e.originalEvent) { - return; - } - GmUtility.setPosition(gmapContext, new google.maps.LatLng($(this).val(), gmapContext.location.lng()), function(context) { - context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]); + inputBinding.latitudeInput.on("change", function(e, isInternal) { + if (isInternal) { return } + GmUtility.setPosition(gmapContext, new google.maps.LatLng($(this).val(), gmapContext.location.lng()), function(context){ + context.settings.onchanged.apply(gmapContext.domContainer, + [GmUtility.locationFromLatLng(context.location), context.radius, false]); + updateInputValues(inputBinding, gmapContext); }); }); } if (inputBinding.longitudeInput) { - inputBinding.longitudeInput.on("change", function(e) { - if (!e.originalEvent) { - return; - } - GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.location.lat(), $(this).val()), function(context) { - context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]); + inputBinding.longitudeInput.on("change", function(e, isInternal) { + if (isInternal) { return } + GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.location.lat(), $(this).val()), function(context){ + context.settings.onchanged.apply(gmapContext.domContainer, + [GmUtility.locationFromLatLng(context.location), context.radius, false]); + updateInputValues(inputBinding, gmapContext); }); }); } } } function autosize(gmapContext) { - google.maps.event.trigger(gmapContext.map, "resize"); + google.maps.event.trigger(gmapContext.map, 'resize'); setTimeout(function() { gmapContext.map.setCenter(gmapContext.marker.position); }, 300); } - $.fn.locationpicker = function(options, params) { - if (typeof options == "string") { + function updateMap(gmapContext, $target, options) { + var settings = $.extend({}, $.fn.locationpicker.defaults, options ), + latNew = settings.location.latitude, + lngNew = settings.location.longitude, + radiusNew = settings.radius, + latOld = gmapContext.settings.location.latitude, + lngOld = gmapContext.settings.location.longitude, + radiusOld = gmapContext.settings.radius; + if (latNew == latOld && lngNew == lngOld && radiusNew == radiusOld) + return; + gmapContext.settings.location.latitude = latNew; + gmapContext.settings.location.longitude = lngNew; + gmapContext.radius = radiusNew; + GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.settings.location.latitude, gmapContext.settings.location.longitude), function(context){ + setupInputListenersInput(gmapContext.settings.inputBinding, gmapContext); + context.settings.oninitialized($target); + }); + } + $.fn.locationpicker = function( options, params ) { + if (typeof options == 'string') { var _targetDomElement = this.get(0); if (!isPluginApplied(_targetDomElement)) return; var gmapContext = getContextForElement(_targetDomElement); switch (options) { - case "location": - if (params == undefined) { - var location = GmUtility.locationFromLatLng(gmapContext.location); - location.radius = gmapContext.radius; - location.name = gmapContext.locationName; - return location; - } else { - if (params.radius) { - gmapContext.radius = params.radius; + case "location": + if (params == undefined) { + var location = GmUtility.locationFromLatLng(gmapContext.location); + location.radius = gmapContext.radius; + location.name = gmapContext.locationName; + return location; + } else { + if (params.radius) { + gmapContext.radius = params.radius; + } + GmUtility.setPosition(gmapContext, new google.maps.LatLng(params.latitude, params.longitude), function(gmapContext) { + updateInputValues(gmapContext.settings.inputBinding, gmapContext); + }); } - GmUtility.setPosition(gmapContext, new google.maps.LatLng(params.latitude, params.longitude), function(gmapContext) { - updateInputValues(gmapContext.settings.inputBinding, gmapContext); - }); - } - break; - - case "subscribe": - if (params == undefined) { - return null; - } else { - var event = params.event; - var callback = params.callback; - if (!event || !callback) { - console.error('LocationPicker: Invalid arguments for method "subscribe"'); + break; + case "subscribe": + if (params == undefined) { return null; + } else { + var event = params.event; + var callback = params.callback; + if (!event || ! callback) { + console.error("LocationPicker: Invalid arguments for method \"subscribe\"") + return null; + } + google.maps.event.addListener(gmapContext.map, event, callback); } - google.maps.event.addListener(gmapContext.map, event, callback); - } - break; - - case "map": - if (params == undefined) { - var locationObj = GmUtility.locationFromLatLng(gmapContext.location); - locationObj.formattedAddress = gmapContext.locationName; - locationObj.addressComponents = gmapContext.addressComponents; - return { - map: gmapContext.map, - marker: gmapContext.marker, - location: locationObj - }; - } else { - return null; - } - - case "autosize": - autosize(gmapContext); - return this; + break; + case "map": + if (params == undefined) { + var locationObj = GmUtility.locationFromLatLng(gmapContext.location); + locationObj.formattedAddress = gmapContext.locationName; + locationObj.addressComponents = gmapContext.addressComponents; + return { + map: gmapContext.map, + marker: gmapContext.marker, + location: locationObj + } + } else { + return null; + } + case "autosize": + autosize(gmapContext); + return this; } return null; } return this.each(function() { var $target = $(this); - if (isPluginApplied(this)) return; - var settings = $.extend({}, $.fn.locationpicker.defaults, options); + if (isPluginApplied(this)){ + updateMap(getContextForElement(this), $(this), options); + return; + } + var settings = $.extend({}, $.fn.locationpicker.defaults, options ); var gmapContext = new GMapContext(this, { zoom: settings.zoom, center: new google.maps.LatLng(settings.location.latitude, settings.location.longitude), @@ -259,13 +304,13 @@ }); $target.data("locationpicker", gmapContext); google.maps.event.addListener(gmapContext.marker, "dragend", function(event) { - GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context) { + GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context){ var currentLocation = GmUtility.locationFromLatLng(gmapContext.location); - context.settings.onchanged.apply(gmapContext.domContainer, [ currentLocation, context.radius, true ]); + context.settings.onchanged.apply(gmapContext.domContainer, [currentLocation, context.radius, true]); updateInputValues(gmapContext.settings.inputBinding, gmapContext); }); }); - GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context) { + GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context){ updateInputValues(settings.inputBinding, gmapContext); setupInputListenersInput(settings.inputBinding, gmapContext); context.settings.oninitialized($target); @@ -273,10 +318,7 @@ }); }; $.fn.locationpicker.defaults = { - location: { - latitude: 40.7324319, - longitude: -73.82480799999996 - }, + location: {latitude: 40.7324319, longitude: -73.82480777777776}, locationName: "", radius: 500, zoom: 15, @@ -288,10 +330,11 @@ locationNameInput: null }, enableAutocomplete: false, + enableAutocompleteBlur: false, enableReverseGeocode: true, draggable: true, onchanged: function(currentLocation, radius, isMarkerDropped) {}, onlocationnotfound: function(locationName) {}, - oninitialized: function(component) {} - }; -})(jQuery); \ No newline at end of file + oninitialized: function (component) {} + } +}( jQuery )); From 3621eb52e30fcb30984d9dcddc4ba2a80cb72026 Mon Sep 17 00:00:00 2001 From: Mohamed Dardouri Date: Sun, 3 May 2015 14:49:33 +0100 Subject: [PATCH 3/5] allowed update inputs Inputs now can be updated from javascript & locationNameInput update where lat/long inputs updated --- dist/locationpicker.jquery.min.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/locationpicker.jquery.min.js b/dist/locationpicker.jquery.min.js index 80653b2..423965f 100644 --- a/dist/locationpicker.jquery.min.js +++ b/dist/locationpicker.jquery.min.js @@ -1,4 +1,4 @@ /*! jquery-locationpicker - v0.1.12 - 2015-01-05 */ -!function(a){function b(a,b){var c=new google.maps.Map(a,b),d=new google.maps.Marker({position:new google.maps.LatLng(54.19335,-3.92695),map:c,title:"Drag Me",draggable:b.draggable});return{map:c,marker:d,circle:null,location:d.position,radius:b.radius,locationName:b.locationName,addressComponents:{formatted_address:null,addressLine1:null,addressLine2:null,streetName:null,streetNumber:null,city:null,district:null,state:null,stateOrProvince:null},settings:b.settings,domContainer:a,geodecoder:new google.maps.Geocoder}}function c(a){return void 0!=d(a)}function d(b){return a(b).data("locationpicker")}function e(a,b){if(a){var c=h.locationFromLatLng(b.location);a.latitudeInput&&a.latitudeInput.val(c.latitude).change(),a.longitudeInput&&a.longitudeInput.val(c.longitude).change(),a.radiusInput&&a.radiusInput.val(b.radius).change(),a.locationNameInput&&a.locationNameInput.val(b.locationName).change()}}function f(b,c){b&&(b.radiusInput&&b.radiusInput.on("change",function(b){b.originalEvent&&(c.radius=a(this).val(),h.setPosition(c,c.location,function(a){a.settings.onchanged.apply(c.domContainer,[h.locationFromLatLng(a.location),a.radius,!1])}))}),b.locationNameInput&&c.settings.enableAutocomplete&&(c.autocomplete=new google.maps.places.Autocomplete(b.locationNameInput.get(0)),google.maps.event.addListener(c.autocomplete,"place_changed",function(){var a=c.autocomplete.getPlace();return a.geometry?void h.setPosition(c,a.geometry.location,function(a){e(b,a),a.settings.onchanged.apply(c.domContainer,[h.locationFromLatLng(a.location),a.radius,!1])}):void c.settings.onlocationnotfound(a.name)})),b.latitudeInput&&b.latitudeInput.on("change",function(b){b.originalEvent&&h.setPosition(c,new google.maps.LatLng(a(this).val(),c.location.lng()),function(a){a.settings.onchanged.apply(c.domContainer,[h.locationFromLatLng(a.location),a.radius,!1])})}),b.longitudeInput&&b.longitudeInput.on("change",function(b){b.originalEvent&&h.setPosition(c,new google.maps.LatLng(c.location.lat(),a(this).val()),function(a){a.settings.onchanged.apply(c.domContainer,[h.locationFromLatLng(a.location),a.radius,!1])})}))}function g(a){google.maps.event.trigger(a.map,"resize"),setTimeout(function(){a.map.setCenter(a.marker.position)},300)}var h={drawCircle:function(b,c,d,e){return null!=b.circle&&b.circle.setMap(null),d>0?(d*=1,e=a.extend({strokeColor:"#0000FF",strokeOpacity:.35,strokeWeight:2,fillColor:"#0000FF",fillOpacity:.2},e),e.map=b.map,e.radius=d,e.center=c,b.circle=new google.maps.Circle(e),b.circle):null},setPosition:function(a,b,c){a.location=b,a.marker.setPosition(b),a.map.panTo(b),this.drawCircle(a,b,a.radius,{}),a.settings.enableReverseGeocode?a.geodecoder.geocode({latLng:a.location},function(b,d){d==google.maps.GeocoderStatus.OK&&b.length>0&&(a.locationName=b[0].formatted_address,a.addressComponents=h.address_component_from_google_geocode(b[0].address_components)),c&&c.call(this,a)}):c&&c.call(this,a)},locationFromLatLng:function(a){return{latitude:a.lat(),longitude:a.lng()}},address_component_from_google_geocode:function(a){for(var b={},c=a.length-1;c>=0;c--){var d=a[c];d.types.indexOf("postal_code")>=0?b.postalCode=d.short_name:d.types.indexOf("street_number")>=0?b.streetNumber=d.short_name:d.types.indexOf("route")>=0?b.streetName=d.short_name:d.types.indexOf("locality")>=0?b.city=d.short_name:d.types.indexOf("sublocality")>=0?b.district=d.short_name:d.types.indexOf("administrative_area_level_1")>=0?b.stateOrProvince=d.short_name:d.types.indexOf("country")>=0&&(b.country=d.short_name)}return b.addressLine1=[b.streetNumber,b.streetName].join(" ").trim(),b.addressLine2="",b}};a.fn.locationpicker=function(i,j){if("string"==typeof i){var k=this.get(0);if(!c(k))return;var l=d(k);switch(i){case"location":if(void 0==j){var m=h.locationFromLatLng(l.location);return m.radius=l.radius,m.name=l.locationName,m}j.radius&&(l.radius=j.radius),h.setPosition(l,new google.maps.LatLng(j.latitude,j.longitude),function(a){e(a.settings.inputBinding,a)});break;case"subscribe":if(void 0==j)return null;var n=j.event,o=j.callback;if(!n||!o)return console.error('LocationPicker: Invalid arguments for method "subscribe"'),null;google.maps.event.addListener(l.map,n,o);break;case"map":if(void 0==j){var p=h.locationFromLatLng(l.location);return p.formattedAddress=l.locationName,p.addressComponents=l.addressComponents,{map:l.map,marker:l.marker,location:p}}return null;case"autosize":return g(l),this}return null}return this.each(function(){var d=a(this);if(!c(this)){var g=a.extend({},a.fn.locationpicker.defaults,i),j=new b(this,{zoom:g.zoom,center:new google.maps.LatLng(g.location.latitude,g.location.longitude),mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:!1,disableDoubleClickZoom:!1,scrollwheel:g.scrollwheel,streetViewControl:!1,radius:g.radius,locationName:g.locationName,settings:g,draggable:g.draggable});d.data("locationpicker",j),google.maps.event.addListener(j.marker,"dragend",function(){h.setPosition(j,j.marker.position,function(a){var b=h.locationFromLatLng(j.location);a.settings.onchanged.apply(j.domContainer,[b,a.radius,!0]),e(j.settings.inputBinding,j)})}),h.setPosition(j,new google.maps.LatLng(g.location.latitude,g.location.longitude),function(a){e(g.inputBinding,j),f(g.inputBinding,j),a.settings.oninitialized(d)})}})},a.fn.locationpicker.defaults={location:{latitude:40.7324319,longitude:-73.82480799999996},locationName:"",radius:500,zoom:15,scrollwheel:!0,inputBinding:{latitudeInput:null,longitudeInput:null,radiusInput:null,locationNameInput:null},enableAutocomplete:!1,enableReverseGeocode:!0,draggable:!0,onchanged:function(){},onlocationnotfound:function(){},oninitialized:function(){}}}(jQuery); -//# sourceMappingURL=locationpicker.jquery.min.map \ No newline at end of file +!function(a){function b(a,b){var c=new google.maps.Map(a,b),d=new google.maps.Marker({position:new google.maps.LatLng(54.19335,-3.92695),map:c,title:"Drag Me",draggable:b.draggable});return{map:c,marker:d,circle:null,location:d.position,radius:b.radius,locationName:b.locationName,addressComponents:{formatted_address:null,addressLine1:null,addressLine2:null,streetName:null,streetNumber:null,city:null,district:null,state:null,stateOrProvince:null},settings:b.settings,domContainer:a,geodecoder:new google.maps.Geocoder}}function d(a){return void 0!=e(a)}function e(b){return a(b).data("locationpicker")}function f(a,b){if(a){var d=c.locationFromLatLng(b.location);a.latitudeInput&&a.latitudeInput.val(d.latitude).trigger("change",!0),a.longitudeInput&&a.longitudeInput.val(d.longitude).trigger("change",!0),a.radiusInput&&a.radiusInput.val(b.radius).trigger("change",!0),a.locationNameInput&&a.locationNameInput.val(b.locationName).trigger("change",!0)}}function g(b,d){if(b){if(b.radiusInput&&b.radiusInput.on("change",function(b,e){e||(d.radius=a(this).val(),c.setPosition(d,d.location,function(a){a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1])}))}),b.locationNameInput&&d.settings.enableAutocomplete){var e=!1;d.autocomplete=new google.maps.places.Autocomplete(b.locationNameInput.get(0)),google.maps.event.addListener(d.autocomplete,"place_changed",function(){e=!1;var a=d.autocomplete.getPlace();return a.geometry?(c.setPosition(d,a.geometry.location,function(a){f(b,a),a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1])}),void 0):(d.settings.onlocationnotfound(a.name),void 0)}),d.settings.enableAutocompleteBlur&&(b.locationNameInput.on("change",function(a,b){b||(e=!0)}),b.locationNameInput.on("blur",function(g,h){h||setTimeout(function(){var g=a(b.locationNameInput).val();g.length>5&&e&&(e=!1,d.geodecoder.geocode({address:g},function(a,e){e==google.maps.GeocoderStatus.OK&&a&&a.length&&c.setPosition(d,a[0].geometry.location,function(a){f(b,a),a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1])})}))},1e3)}))}b.latitudeInput&&b.latitudeInput.on("change",function(e,g){g||c.setPosition(d,new google.maps.LatLng(a(this).val(),d.location.lng()),function(a){a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1]),f(b,d)})}),b.longitudeInput&&b.longitudeInput.on("change",function(e,g){g||c.setPosition(d,new google.maps.LatLng(d.location.lat(),a(this).val()),function(a){a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1]),f(b,d)})})}}function h(a){google.maps.event.trigger(a.map,"resize"),setTimeout(function(){a.map.setCenter(a.marker.position)},300)}function i(b,d,e){var f=a.extend({},a.fn.locationpicker.defaults,e),h=f.location.latitude,i=f.location.longitude,j=f.radius,k=b.settings.location.latitude,l=b.settings.location.longitude,m=b.settings.radius;(h!=k||i!=l||j!=m)&&(b.settings.location.latitude=h,b.settings.location.longitude=i,b.radius=j,c.setPosition(b,new google.maps.LatLng(b.settings.location.latitude,b.settings.location.longitude),function(a){g(b.settings.inputBinding,b),a.settings.oninitialized(d)}))}var c={drawCircle:function(b,c,d,e){return null!=b.circle&&b.circle.setMap(null),d>0?(d*=1,e=a.extend({strokeColor:"#0000FF",strokeOpacity:.35,strokeWeight:2,fillColor:"#0000FF",fillOpacity:.2},e),e.map=b.map,e.radius=d,e.center=c,b.circle=new google.maps.Circle(e),b.circle):null},setPosition:function(a,b,d){a.location=b,a.marker.setPosition(b),a.map.panTo(b),this.drawCircle(a,b,a.radius,{}),a.settings.enableReverseGeocode?a.geodecoder.geocode({latLng:a.location},function(b,e){e==google.maps.GeocoderStatus.OK&&b.length>0&&(a.locationName=b[0].formatted_address,a.addressComponents=c.address_component_from_google_geocode(b[0].address_components)),d&&d.call(this,a)}):d&&d.call(this,a)},locationFromLatLng:function(a){return{latitude:a.lat(),longitude:a.lng()}},address_component_from_google_geocode:function(a){for(var b={},c=a.length-1;c>=0;c--){var d=a[c];d.types.indexOf("postal_code")>=0?b.postalCode=d.short_name:d.types.indexOf("street_number")>=0?b.streetNumber=d.short_name:d.types.indexOf("route")>=0?b.streetName=d.short_name:d.types.indexOf("locality")>=0?b.city=d.short_name:d.types.indexOf("sublocality")>=0?b.district=d.short_name:d.types.indexOf("administrative_area_level_1")>=0?b.stateOrProvince=d.short_name:d.types.indexOf("country")>=0&&(b.country=d.short_name)}return b.addressLine1=[b.streetNumber,b.streetName].join(" ").trim(),b.addressLine2="",b}};a.fn.locationpicker=function(j,k){if("string"==typeof j){var l=this.get(0);if(!d(l))return;var m=e(l);switch(j){case"location":if(void 0==k){var n=c.locationFromLatLng(m.location);return n.radius=m.radius,n.name=m.locationName,n}k.radius&&(m.radius=k.radius),c.setPosition(m,new google.maps.LatLng(k.latitude,k.longitude),function(a){f(a.settings.inputBinding,a)});break;case"subscribe":if(void 0==k)return null;var o=k.event,p=k.callback;if(!o||!p)return console.error('LocationPicker: Invalid arguments for method "subscribe"'),null;google.maps.event.addListener(m.map,o,p);break;case"map":if(void 0==k){var q=c.locationFromLatLng(m.location);return q.formattedAddress=m.locationName,q.addressComponents=m.addressComponents,{map:m.map,marker:m.marker,location:q}}return null;case"autosize":return h(m),this}return null}return this.each(function(){var h=a(this);if(d(this))return i(e(this),a(this),j),void 0;var k=a.extend({},a.fn.locationpicker.defaults,j),l=new b(this,{zoom:k.zoom,center:new google.maps.LatLng(k.location.latitude,k.location.longitude),mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:!1,disableDoubleClickZoom:!1,scrollwheel:k.scrollwheel,streetViewControl:!1,radius:k.radius,locationName:k.locationName,settings:k,draggable:k.draggable});h.data("locationpicker",l),google.maps.event.addListener(l.marker,"dragend",function(){c.setPosition(l,l.marker.position,function(a){var b=c.locationFromLatLng(l.location);a.settings.onchanged.apply(l.domContainer,[b,a.radius,!0]),f(l.settings.inputBinding,l)})}),c.setPosition(l,new google.maps.LatLng(k.location.latitude,k.location.longitude),function(a){f(k.inputBinding,l),g(k.inputBinding,l),a.settings.oninitialized(h)})})},a.fn.locationpicker.defaults={location:{latitude:40.7324319,longitude:-73.82480777777776},locationName:"",radius:500,zoom:15,scrollwheel:!0,inputBinding:{latitudeInput:null,longitudeInput:null,radiusInput:null,locationNameInput:null},enableAutocomplete:!1,enableAutocompleteBlur:!1,enableReverseGeocode:!0,draggable:!0,onchanged:function(){},onlocationnotfound:function(){},oninitialized:function(){}}}(jQuery); +//# sourceMappingURL=locationpicker.jquery.min.map From 004de8d67642e5e26d894d0b379392908cac160d Mon Sep 17 00:00:00 2001 From: Mohamed Dardouri Date: Sun, 3 May 2015 14:58:32 +0100 Subject: [PATCH 4/5] Update locationpicker.jquery.js --- dist/locationpicker.jquery.js | 245 ++++++++++++++-------------------- 1 file changed, 102 insertions(+), 143 deletions(-) diff --git a/dist/locationpicker.jquery.js b/dist/locationpicker.jquery.js index d361469..76d7afa 100644 --- a/dist/locationpicker.jquery.js +++ b/dist/locationpicker.jquery.js @@ -1,4 +1,5 @@ -(function ( $ ) { +/*! jquery-locationpicker - v0.1.13 - 2015-05-03 */ +(function($) { function GMapContext(domElement, options) { var _map = new google.maps.Map(domElement, options); var _marker = new google.maps.Marker({ @@ -28,7 +29,7 @@ settings: options.settings, domContainer: domElement, geodecoder: new google.maps.Geocoder() - } + }; } var GmUtility = { drawCircle: function(gmapContext, center, radius, options) { @@ -39,10 +40,10 @@ radius *= 1; options = $.extend({ strokeColor: "#0000FF", - strokeOpacity: 0.35, + strokeOpacity: .35, strokeWeight: 2, fillColor: "#0000FF", - fillOpacity: 0.20 + fillOpacity: .2 }, options); options.map = gmapContext.map; options.radius = radius; @@ -58,11 +59,12 @@ gMapContext.map.panTo(location); this.drawCircle(gMapContext, location, gMapContext.radius, {}); if (gMapContext.settings.enableReverseGeocode) { - gMapContext.geodecoder.geocode({latLng: gMapContext.location}, function(results, status){ - if (status == google.maps.GeocoderStatus.OK && results.length > 0){ + gMapContext.geodecoder.geocode({ + latLng: gMapContext.location + }, function(results, status) { + if (status == google.maps.GeocoderStatus.OK && results.length > 0) { gMapContext.locationName = results[0].formatted_address; - gMapContext.addressComponents = - GmUtility.address_component_from_google_geocode(results[0].address_components); + gMapContext.addressComponents = GmUtility.address_component_from_google_geocode(results[0].address_components); } if (callback) { callback.call(this, gMapContext); @@ -75,36 +77,33 @@ } }, locationFromLatLng: function(lnlg) { - return {latitude: lnlg.lat(), longitude: lnlg.lng()} + return { + latitude: lnlg.lat(), + longitude: lnlg.lng() + }; }, address_component_from_google_geocode: function(address_components) { var result = {}; - for (var i = address_components.length-1; i>=0; i--) { + for (var i = address_components.length - 1; i >= 0; i--) { var component = address_components[i]; - if (component.types.indexOf('postal_code') >= 0) { + if (component.types.indexOf("postal_code") >= 0) { result.postalCode = component.short_name; - } - else if (component.types.indexOf('street_number') >= 0) { + } else if (component.types.indexOf("street_number") >= 0) { result.streetNumber = component.short_name; - } - else if (component.types.indexOf('route') >= 0) { + } else if (component.types.indexOf("route") >= 0) { result.streetName = component.short_name; - } - else if (component.types.indexOf('locality') >= 0) { + } else if (component.types.indexOf("locality") >= 0) { result.city = component.short_name; - } - else if (component.types.indexOf('sublocality') >= 0) { + } else if (component.types.indexOf("sublocality") >= 0) { result.district = component.short_name; - } - else if (component.types.indexOf('administrative_area_level_1') >= 0) { + } else if (component.types.indexOf("administrative_area_level_1") >= 0) { result.stateOrProvince = component.short_name; - } - else if (component.types.indexOf('country') >= 0) { + } else if (component.types.indexOf("country") >= 0) { result.country = component.short_name; } } - result.addressLine1 = [result.streetNumber, result.streetName].join(' ').trim(); - result.addressLine2 = ''; + result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim(); + result.addressLine2 = ""; return result; } }; @@ -114,7 +113,7 @@ function getContextForElement(domObj) { return $(domObj).data("locationpicker"); } - function updateInputValues(inputBinding, gmapContext){ + function updateInputValues(inputBinding, gmapContext) { if (!inputBinding) return; var currentLocation = GmUtility.locationFromLatLng(gmapContext.location); if (inputBinding.latitudeInput) { @@ -132,21 +131,20 @@ } function setupInputListenersInput(inputBinding, gmapContext) { if (inputBinding) { - if (inputBinding.radiusInput){ + if (inputBinding.radiusInput) { inputBinding.radiusInput.on("change", function(e, isInternal) { - if (isInternal) { return } + if (isInternal) { + return; + } gmapContext.radius = $(this).val(); - GmUtility.setPosition(gmapContext, gmapContext.location, function(context){ - context.settings.onchanged.apply(gmapContext.domContainer, - [GmUtility.locationFromLatLng(context.location), context.radius, false]); + GmUtility.setPosition(gmapContext, gmapContext.location, function(context) { + context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]); }); }); } if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) { - var blur = false; gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0)); - google.maps.event.addListener(gmapContext.autocomplete, 'place_changed', function() { - blur = false; + google.maps.event.addListener(gmapContext.autocomplete, "place_changed", function() { var place = gmapContext.autocomplete.getPlace(); if (!place.geometry) { gmapContext.settings.onlocationnotfound(place.name); @@ -154,51 +152,28 @@ } GmUtility.setPosition(gmapContext, place.geometry.location, function(context) { updateInputValues(inputBinding, context); - context.settings.onchanged.apply(gmapContext.domContainer, - [GmUtility.locationFromLatLng(context.location), context.radius, false]); + context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]); }); }); - if(gmapContext.settings.enableAutocompleteBlur) { - inputBinding.locationNameInput.on("change", function(e, isInternal) { - if (isInternal) { return } - blur = true; - }); - inputBinding.locationNameInput.on("blur", function(e, isInternal) { - if (isInternal) { return } - setTimeout(function() { - var address = $(inputBinding.locationNameInput).val(); - if (address.length > 5 && blur) { - blur = false; - gmapContext.geodecoder.geocode({'address': address}, function(results, status) { - if(status == google.maps.GeocoderStatus.OK && results && results.length) { - GmUtility.setPosition(gmapContext, results[0].geometry.location, function(context) { - updateInputValues(inputBinding, context); - context.settings.onchanged.apply(gmapContext.domContainer, - [GmUtility.locationFromLatLng(context.location), context.radius, false]); - }); - } - }); - } - }, 1000); - }); - } } if (inputBinding.latitudeInput) { inputBinding.latitudeInput.on("change", function(e, isInternal) { - if (isInternal) { return } - GmUtility.setPosition(gmapContext, new google.maps.LatLng($(this).val(), gmapContext.location.lng()), function(context){ - context.settings.onchanged.apply(gmapContext.domContainer, - [GmUtility.locationFromLatLng(context.location), context.radius, false]); + if (isInternal) { + return; + } + GmUtility.setPosition(gmapContext, new google.maps.LatLng($(this).val(), gmapContext.location.lng()), function(context) { + context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]); updateInputValues(inputBinding, gmapContext); }); }); } if (inputBinding.longitudeInput) { inputBinding.longitudeInput.on("change", function(e, isInternal) { - if (isInternal) { return } - GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.location.lat(), $(this).val()), function(context){ - context.settings.onchanged.apply(gmapContext.domContainer, - [GmUtility.locationFromLatLng(context.location), context.radius, false]); + if (isInternal) { + return; + } + GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.location.lat(), $(this).val()), function(context) { + context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]); updateInputValues(inputBinding, gmapContext); }); }); @@ -206,89 +181,71 @@ } } function autosize(gmapContext) { - google.maps.event.trigger(gmapContext.map, 'resize'); + google.maps.event.trigger(gmapContext.map, "resize"); setTimeout(function() { gmapContext.map.setCenter(gmapContext.marker.position); }, 300); } - function updateMap(gmapContext, $target, options) { - var settings = $.extend({}, $.fn.locationpicker.defaults, options ), - latNew = settings.location.latitude, - lngNew = settings.location.longitude, - radiusNew = settings.radius, - latOld = gmapContext.settings.location.latitude, - lngOld = gmapContext.settings.location.longitude, - radiusOld = gmapContext.settings.radius; - if (latNew == latOld && lngNew == lngOld && radiusNew == radiusOld) - return; - gmapContext.settings.location.latitude = latNew; - gmapContext.settings.location.longitude = lngNew; - gmapContext.radius = radiusNew; - GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.settings.location.latitude, gmapContext.settings.location.longitude), function(context){ - setupInputListenersInput(gmapContext.settings.inputBinding, gmapContext); - context.settings.oninitialized($target); - }); - } - $.fn.locationpicker = function( options, params ) { - if (typeof options == 'string') { + $.fn.locationpicker = function(options, params) { + if (typeof options == "string") { var _targetDomElement = this.get(0); if (!isPluginApplied(_targetDomElement)) return; var gmapContext = getContextForElement(_targetDomElement); switch (options) { - case "location": - if (params == undefined) { - var location = GmUtility.locationFromLatLng(gmapContext.location); - location.radius = gmapContext.radius; - location.name = gmapContext.locationName; - return location; - } else { - if (params.radius) { - gmapContext.radius = params.radius; - } - GmUtility.setPosition(gmapContext, new google.maps.LatLng(params.latitude, params.longitude), function(gmapContext) { - updateInputValues(gmapContext.settings.inputBinding, gmapContext); - }); + case "location": + if (params == undefined) { + var location = GmUtility.locationFromLatLng(gmapContext.location); + location.radius = gmapContext.radius; + location.name = gmapContext.locationName; + return location; + } else { + if (params.radius) { + gmapContext.radius = params.radius; } - break; - case "subscribe": - if (params == undefined) { - return null; - } else { - var event = params.event; - var callback = params.callback; - if (!event || ! callback) { - console.error("LocationPicker: Invalid arguments for method \"subscribe\"") - return null; - } - google.maps.event.addListener(gmapContext.map, event, callback); - } - break; - case "map": - if (params == undefined) { - var locationObj = GmUtility.locationFromLatLng(gmapContext.location); - locationObj.formattedAddress = gmapContext.locationName; - locationObj.addressComponents = gmapContext.addressComponents; - return { - map: gmapContext.map, - marker: gmapContext.marker, - location: locationObj - } - } else { + GmUtility.setPosition(gmapContext, new google.maps.LatLng(params.latitude, params.longitude), function(gmapContext) { + updateInputValues(gmapContext.settings.inputBinding, gmapContext); + }); + } + break; + + case "subscribe": + if (params == undefined) { + return null; + } else { + var event = params.event; + var callback = params.callback; + if (!event || !callback) { + console.error('LocationPicker: Invalid arguments for method "subscribe"'); return null; } - case "autosize": - autosize(gmapContext); - return this; + google.maps.event.addListener(gmapContext.map, event, callback); + } + break; + + case "map": + if (params == undefined) { + var locationObj = GmUtility.locationFromLatLng(gmapContext.location); + locationObj.formattedAddress = gmapContext.locationName; + locationObj.addressComponents = gmapContext.addressComponents; + return { + map: gmapContext.map, + marker: gmapContext.marker, + location: locationObj + }; + } else { + return null; + } + + case "autosize": + autosize(gmapContext); + return this; } return null; } return this.each(function() { var $target = $(this); - if (isPluginApplied(this)){ - updateMap(getContextForElement(this), $(this), options); - return; - } - var settings = $.extend({}, $.fn.locationpicker.defaults, options ); + if (isPluginApplied(this)) return; + var settings = $.extend({}, $.fn.locationpicker.defaults, options); var gmapContext = new GMapContext(this, { zoom: settings.zoom, center: new google.maps.LatLng(settings.location.latitude, settings.location.longitude), @@ -304,13 +261,13 @@ }); $target.data("locationpicker", gmapContext); google.maps.event.addListener(gmapContext.marker, "dragend", function(event) { - GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context){ + GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context) { var currentLocation = GmUtility.locationFromLatLng(gmapContext.location); - context.settings.onchanged.apply(gmapContext.domContainer, [currentLocation, context.radius, true]); + context.settings.onchanged.apply(gmapContext.domContainer, [ currentLocation, context.radius, true ]); updateInputValues(gmapContext.settings.inputBinding, gmapContext); }); }); - GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context){ + GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context) { updateInputValues(settings.inputBinding, gmapContext); setupInputListenersInput(settings.inputBinding, gmapContext); context.settings.oninitialized($target); @@ -318,7 +275,10 @@ }); }; $.fn.locationpicker.defaults = { - location: {latitude: 40.7324319, longitude: -73.82480777777776}, + location: { + latitude: 40.7324319, + longitude: -73.82480799999996 + }, locationName: "", radius: 500, zoom: 15, @@ -330,11 +290,10 @@ locationNameInput: null }, enableAutocomplete: false, - enableAutocompleteBlur: false, enableReverseGeocode: true, draggable: true, onchanged: function(currentLocation, radius, isMarkerDropped) {}, onlocationnotfound: function(locationName) {}, - oninitialized: function (component) {} - } -}( jQuery )); + oninitialized: function(component) {} + }; +})(jQuery); From f1b867f7eb0ad1d77d6b2282c2f1fae2fe3084a2 Mon Sep 17 00:00:00 2001 From: Mohamed Dardouri Date: Sun, 3 May 2015 14:58:56 +0100 Subject: [PATCH 5/5] Update locationpicker.jquery.min.js --- dist/locationpicker.jquery.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/locationpicker.jquery.min.js b/dist/locationpicker.jquery.min.js index 423965f..9001471 100644 --- a/dist/locationpicker.jquery.min.js +++ b/dist/locationpicker.jquery.min.js @@ -1,4 +1,4 @@ -/*! jquery-locationpicker - v0.1.12 - 2015-01-05 */ +/*! jquery-locationpicker - v0.1.13 - 2015-05-03 */ !function(a){function b(a,b){var c=new google.maps.Map(a,b),d=new google.maps.Marker({position:new google.maps.LatLng(54.19335,-3.92695),map:c,title:"Drag Me",draggable:b.draggable});return{map:c,marker:d,circle:null,location:d.position,radius:b.radius,locationName:b.locationName,addressComponents:{formatted_address:null,addressLine1:null,addressLine2:null,streetName:null,streetNumber:null,city:null,district:null,state:null,stateOrProvince:null},settings:b.settings,domContainer:a,geodecoder:new google.maps.Geocoder}}function d(a){return void 0!=e(a)}function e(b){return a(b).data("locationpicker")}function f(a,b){if(a){var d=c.locationFromLatLng(b.location);a.latitudeInput&&a.latitudeInput.val(d.latitude).trigger("change",!0),a.longitudeInput&&a.longitudeInput.val(d.longitude).trigger("change",!0),a.radiusInput&&a.radiusInput.val(b.radius).trigger("change",!0),a.locationNameInput&&a.locationNameInput.val(b.locationName).trigger("change",!0)}}function g(b,d){if(b){if(b.radiusInput&&b.radiusInput.on("change",function(b,e){e||(d.radius=a(this).val(),c.setPosition(d,d.location,function(a){a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1])}))}),b.locationNameInput&&d.settings.enableAutocomplete){var e=!1;d.autocomplete=new google.maps.places.Autocomplete(b.locationNameInput.get(0)),google.maps.event.addListener(d.autocomplete,"place_changed",function(){e=!1;var a=d.autocomplete.getPlace();return a.geometry?(c.setPosition(d,a.geometry.location,function(a){f(b,a),a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1])}),void 0):(d.settings.onlocationnotfound(a.name),void 0)}),d.settings.enableAutocompleteBlur&&(b.locationNameInput.on("change",function(a,b){b||(e=!0)}),b.locationNameInput.on("blur",function(g,h){h||setTimeout(function(){var g=a(b.locationNameInput).val();g.length>5&&e&&(e=!1,d.geodecoder.geocode({address:g},function(a,e){e==google.maps.GeocoderStatus.OK&&a&&a.length&&c.setPosition(d,a[0].geometry.location,function(a){f(b,a),a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1])})}))},1e3)}))}b.latitudeInput&&b.latitudeInput.on("change",function(e,g){g||c.setPosition(d,new google.maps.LatLng(a(this).val(),d.location.lng()),function(a){a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1]),f(b,d)})}),b.longitudeInput&&b.longitudeInput.on("change",function(e,g){g||c.setPosition(d,new google.maps.LatLng(d.location.lat(),a(this).val()),function(a){a.settings.onchanged.apply(d.domContainer,[c.locationFromLatLng(a.location),a.radius,!1]),f(b,d)})})}}function h(a){google.maps.event.trigger(a.map,"resize"),setTimeout(function(){a.map.setCenter(a.marker.position)},300)}function i(b,d,e){var f=a.extend({},a.fn.locationpicker.defaults,e),h=f.location.latitude,i=f.location.longitude,j=f.radius,k=b.settings.location.latitude,l=b.settings.location.longitude,m=b.settings.radius;(h!=k||i!=l||j!=m)&&(b.settings.location.latitude=h,b.settings.location.longitude=i,b.radius=j,c.setPosition(b,new google.maps.LatLng(b.settings.location.latitude,b.settings.location.longitude),function(a){g(b.settings.inputBinding,b),a.settings.oninitialized(d)}))}var c={drawCircle:function(b,c,d,e){return null!=b.circle&&b.circle.setMap(null),d>0?(d*=1,e=a.extend({strokeColor:"#0000FF",strokeOpacity:.35,strokeWeight:2,fillColor:"#0000FF",fillOpacity:.2},e),e.map=b.map,e.radius=d,e.center=c,b.circle=new google.maps.Circle(e),b.circle):null},setPosition:function(a,b,d){a.location=b,a.marker.setPosition(b),a.map.panTo(b),this.drawCircle(a,b,a.radius,{}),a.settings.enableReverseGeocode?a.geodecoder.geocode({latLng:a.location},function(b,e){e==google.maps.GeocoderStatus.OK&&b.length>0&&(a.locationName=b[0].formatted_address,a.addressComponents=c.address_component_from_google_geocode(b[0].address_components)),d&&d.call(this,a)}):d&&d.call(this,a)},locationFromLatLng:function(a){return{latitude:a.lat(),longitude:a.lng()}},address_component_from_google_geocode:function(a){for(var b={},c=a.length-1;c>=0;c--){var d=a[c];d.types.indexOf("postal_code")>=0?b.postalCode=d.short_name:d.types.indexOf("street_number")>=0?b.streetNumber=d.short_name:d.types.indexOf("route")>=0?b.streetName=d.short_name:d.types.indexOf("locality")>=0?b.city=d.short_name:d.types.indexOf("sublocality")>=0?b.district=d.short_name:d.types.indexOf("administrative_area_level_1")>=0?b.stateOrProvince=d.short_name:d.types.indexOf("country")>=0&&(b.country=d.short_name)}return b.addressLine1=[b.streetNumber,b.streetName].join(" ").trim(),b.addressLine2="",b}};a.fn.locationpicker=function(j,k){if("string"==typeof j){var l=this.get(0);if(!d(l))return;var m=e(l);switch(j){case"location":if(void 0==k){var n=c.locationFromLatLng(m.location);return n.radius=m.radius,n.name=m.locationName,n}k.radius&&(m.radius=k.radius),c.setPosition(m,new google.maps.LatLng(k.latitude,k.longitude),function(a){f(a.settings.inputBinding,a)});break;case"subscribe":if(void 0==k)return null;var o=k.event,p=k.callback;if(!o||!p)return console.error('LocationPicker: Invalid arguments for method "subscribe"'),null;google.maps.event.addListener(m.map,o,p);break;case"map":if(void 0==k){var q=c.locationFromLatLng(m.location);return q.formattedAddress=m.locationName,q.addressComponents=m.addressComponents,{map:m.map,marker:m.marker,location:q}}return null;case"autosize":return h(m),this}return null}return this.each(function(){var h=a(this);if(d(this))return i(e(this),a(this),j),void 0;var k=a.extend({},a.fn.locationpicker.defaults,j),l=new b(this,{zoom:k.zoom,center:new google.maps.LatLng(k.location.latitude,k.location.longitude),mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:!1,disableDoubleClickZoom:!1,scrollwheel:k.scrollwheel,streetViewControl:!1,radius:k.radius,locationName:k.locationName,settings:k,draggable:k.draggable});h.data("locationpicker",l),google.maps.event.addListener(l.marker,"dragend",function(){c.setPosition(l,l.marker.position,function(a){var b=c.locationFromLatLng(l.location);a.settings.onchanged.apply(l.domContainer,[b,a.radius,!0]),f(l.settings.inputBinding,l)})}),c.setPosition(l,new google.maps.LatLng(k.location.latitude,k.location.longitude),function(a){f(k.inputBinding,l),g(k.inputBinding,l),a.settings.oninitialized(h)})})},a.fn.locationpicker.defaults={location:{latitude:40.7324319,longitude:-73.82480777777776},locationName:"",radius:500,zoom:15,scrollwheel:!0,inputBinding:{latitudeInput:null,longitudeInput:null,radiusInput:null,locationNameInput:null},enableAutocomplete:!1,enableAutocompleteBlur:!1,enableReverseGeocode:!0,draggable:!0,onchanged:function(){},onlocationnotfound:function(){},oninitialized:function(){}}}(jQuery); //# sourceMappingURL=locationpicker.jquery.min.map