Skip to content

Commit

Permalink
Merge pull request #66 from EmanueleCoppola/master
Browse files Browse the repository at this point in the history
Added custom icon functionality, modified examples and updated version.
  • Loading branch information
corvis committed Mar 11, 2016
2 parents 45c82c4 + 8a41cfd commit 6f66594
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 296 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The plug-in requires [jQuery](http://jquery.com/) and the [Google Maps API](http
* Add jQuery and Google Maps API to the `<head>` of your HTML file:
```
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
// be careful to include the parameter "libraries=places"
<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=places'></script>
<script src="js/locationpicker.jquery.js"></script>
```
Expand All @@ -39,4 +40,6 @@ Documentation along with examples available [here](http://logicify.github.io/jqu

Credits
-------
Dmitry Berezovsky, Logicify (<http://logicify.com/>)
Dmitry Berezovsky, Logicify (<http://logicify.com/>)
Emanuele Coppola, Libre sc (<http://libreidee.com/>)

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-locationpicker",
"version": "0.1.12",
"version": "0.1.13",
"homepage": "https://github.com/Logicify/jquery-locationpicker-plugin",
"authors": [
"Dmitry Berezovsky <[email protected]>"
Expand Down
61 changes: 55 additions & 6 deletions dist/locationpicker.jquery.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*! jquery-locationpicker - v0.1.12 - 2015-01-05 */
/*! jquery-locationpicker - v0.1.13 - 2016-03-11 */
(function($) {
function GMapContext(domElement, options) {
var _map = new google.maps.Map(domElement, options);
var _marker = new google.maps.Marker({
position: new google.maps.LatLng(54.19335, -3.92695),
map: _map,
title: "Drag Me",
draggable: options.draggable
draggable: options.draggable,
icon: options.markerIcon !== undefined ? options.markerIcon : undefined
});
return {
map: _map,
Expand Down Expand Up @@ -143,8 +144,10 @@
});
}
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;
var place = gmapContext.autocomplete.getPlace();
if (!place.geometry) {
gmapContext.settings.onlocationnotfound(place.name);
Expand All @@ -155,6 +158,35 @@
context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]);
});
});
if (gmapContext.settings.enableAutocompleteBlur) {
inputBinding.locationNameInput.on("change", function(e) {
if (!e.originalEvent) {
return;
}
blur = true;
});
inputBinding.locationNameInput.on("blur", function(e) {
if (!e.originalEvent) {
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 ]);
});
}
});
}
}, 1e3);
});
}
}
if (inputBinding.latitudeInput) {
inputBinding.latitudeInput.on("change", function(e) {
Expand Down Expand Up @@ -184,6 +216,17 @@
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") {
var _targetDomElement = this.get(0);
Expand Down Expand Up @@ -242,7 +285,10 @@
}
return this.each(function() {
var $target = $(this);
if (isPluginApplied(this)) return;
if (isPluginApplied(this)) {
updateMap(getContextForElement(this), $(this), options);
return;
}
var settings = $.extend({}, $.fn.locationpicker.defaults, options);
var gmapContext = new GMapContext(this, {
zoom: settings.zoom,
Expand All @@ -255,7 +301,8 @@
radius: settings.radius,
locationName: settings.locationName,
settings: settings,
draggable: settings.draggable
draggable: settings.draggable,
markerIcon: settings.markerIcon
});
$target.data("locationpicker", gmapContext);
google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
Expand All @@ -275,7 +322,7 @@
$.fn.locationpicker.defaults = {
location: {
latitude: 40.7324319,
longitude: -73.82480799999996
longitude: -73.82480777777776
},
locationName: "",
radius: 500,
Expand All @@ -288,10 +335,12 @@
locationNameInput: null
},
enableAutocomplete: false,
enableAutocompleteBlur: false,
enableReverseGeocode: true,
draggable: true,
onchanged: function(currentLocation, radius, isMarkerDropped) {},
onlocationnotfound: function(locationName) {},
oninitialized: function(component) {}
oninitialized: function(component) {},
markerIcon: undefined
};
})(jQuery);
6 changes: 3 additions & 3 deletions dist/locationpicker.jquery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6f66594

Please sign in to comment.