Skip to content

Commit

Permalink
Merge pull request #88 from Logicify/development
Browse files Browse the repository at this point in the history
Merged code for upcoming release 1.14
  • Loading branch information
corvis authored Sep 20, 2016
2 parents 6f66594 + 8bd8280 commit d717c60
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 57 deletions.
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.13",
"version": "0.1.14",
"homepage": "https://github.com/Logicify/jquery-locationpicker-plugin",
"authors": [
"Dmitry Berezovsky <[email protected]>"
Expand Down
86 changes: 66 additions & 20 deletions dist/locationpicker.jquery.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*! jquery-locationpicker - v0.1.13 - 2016-03-11 */
/*! jquery-locationpicker - v0.1.14 - 2016-09-20 */
(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,
visible: options.markerVisible,
draggable: options.markerDraggable,
icon: options.markerIcon !== undefined ? options.markerIcon : undefined
});
return {
Expand Down Expand Up @@ -60,17 +61,7 @@
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.locationName = results[0].formatted_address;
gMapContext.addressComponents = GmUtility.address_component_from_google_geocode(results[0].address_components);
}
if (callback) {
callback.call(this, gMapContext);
}
});
this.updateLocationName(gMapContext, callback);
} else {
if (callback) {
callback.call(this, gMapContext);
Expand All @@ -83,6 +74,29 @@
longitude: lnlg.lng()
};
},
addressByFormat: function(addresses, format) {
var result = null;
for (var i = addresses.length - 1; i >= 0; i--) {
if (addresses[i].types.indexOf(format) >= 0) {
result = addresses[i];
}
}
return result || addresses[0];
},
updateLocationName: function(gmapContext, callback) {
gmapContext.geodecoder.geocode({
latLng: gmapContext.marker.position
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
var address = GmUtility.addressByFormat(results, gmapContext.settings.addressFormat);
gmapContext.locationName = address.formatted_address;
gmapContext.addressComponents = GmUtility.address_component_from_google_geocode(address.address_components);
}
if (callback) {
callback.call(this, gmapContext);
}
});
},
address_component_from_google_geocode: function(address_components) {
var result = {};
for (var i = address_components.length - 1; i >= 0; i--) {
Expand Down Expand Up @@ -116,7 +130,7 @@
}
function updateInputValues(inputBinding, gmapContext) {
if (!inputBinding) return;
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
var currentLocation = GmUtility.locationFromLatLng(gmapContext.marker.position);
if (inputBinding.latitudeInput) {
inputBinding.latitudeInput.val(currentLocation.latitude).change();
}
Expand Down Expand Up @@ -145,7 +159,7 @@
}
if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) {
var blur = false;
gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0));
gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0), gmapContext.settings.autocompleteOptions);
google.maps.event.addListener(gmapContext.autocomplete, "place_changed", function() {
blur = false;
var place = gmapContext.autocomplete.getPlace();
Expand Down Expand Up @@ -195,6 +209,7 @@
}
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(gmapContext.settings.inputBinding, gmapContext);
});
});
}
Expand All @@ -205,6 +220,7 @@
}
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(gmapContext.settings.inputBinding, gmapContext);
});
});
}
Expand Down Expand Up @@ -293,24 +309,48 @@
var gmapContext = new GMapContext(this, {
zoom: settings.zoom,
center: new google.maps.LatLng(settings.location.latitude, settings.location.longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeId: settings.mapTypeId,
mapTypeControl: false,
styles: settings.styles,
disableDoubleClickZoom: false,
scrollwheel: settings.scrollwheel,
streetViewControl: false,
radius: settings.radius,
locationName: settings.locationName,
settings: settings,
autocompleteOptions: settings.autocompleteOptions,
addressFormat: settings.addressFormat,
draggable: settings.draggable,
markerIcon: settings.markerIcon
markerIcon: settings.markerIcon,
markerDraggable: settings.markerDraggable,
markerVisible: settings.markerVisible
});
$target.data("locationpicker", gmapContext);
google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
function displayMarkerWithSelectedArea() {
GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context) {
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
context.settings.onchanged.apply(gmapContext.domContainer, [ currentLocation, context.radius, true ]);
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
context.settings.onchanged.apply(gmapContext.domContainer, [ currentLocation, context.radius, true ]);
});
}
if (settings.markerInCenter) {
gmapContext.map.addListener("bounds_changed", function() {
if (!gmapContext.marker.dragging) {
gmapContext.marker.setPosition(gmapContext.map.center);
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
}
});
gmapContext.map.addListener("idle", function() {
if (!gmapContext.marker.dragging) {
displayMarkerWithSelectedArea();
}
});
}
google.maps.event.addListener(gmapContext.marker, "drag", function(event) {
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
});
google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
displayMarkerWithSelectedArea();
});
GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context) {
updateInputValues(settings.inputBinding, gmapContext);
Expand All @@ -327,6 +367,8 @@
locationName: "",
radius: 500,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [],
scrollwheel: true,
inputBinding: {
latitudeInput: null,
Expand All @@ -336,11 +378,15 @@
},
enableAutocomplete: false,
enableAutocompleteBlur: false,
autocompleteOptions: null,
addressFormat: "postal_code",
enableReverseGeocode: true,
draggable: true,
onchanged: function(currentLocation, radius, isMarkerDropped) {},
onlocationnotfound: function(locationName) {},
oninitialized: function(component) {},
markerIcon: undefined
markerIcon: undefined,
markerDraggable: true,
markerVisible: true
};
})(jQuery);
Loading

0 comments on commit d717c60

Please sign in to comment.