Skip to content

Commit 6f66594

Browse files
committed
Merge pull request #66 from EmanueleCoppola/master
Added custom icon functionality, modified examples and updated version.
2 parents 45c82c4 + 8a41cfd commit 6f66594

12 files changed

+424
-296
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The plug-in requires [jQuery](http://jquery.com/) and the [Google Maps API](http
1515
* Add jQuery and Google Maps API to the `<head>` of your HTML file:
1616
```
1717
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
18+
// be careful to include the parameter "libraries=places"
1819
<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=places'></script>
1920
<script src="js/locationpicker.jquery.js"></script>
2021
```
@@ -39,4 +40,6 @@ Documentation along with examples available [here](http://logicify.github.io/jqu
3940

4041
Credits
4142
-------
42-
Dmitry Berezovsky, Logicify (<http://logicify.com/>)
43+
Dmitry Berezovsky, Logicify (<http://logicify.com/>)
44+
Emanuele Coppola, Libre sc (<http://libreidee.com/>)
45+

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-locationpicker",
3-
"version": "0.1.12",
3+
"version": "0.1.13",
44
"homepage": "https://github.com/Logicify/jquery-locationpicker-plugin",
55
"authors": [
66
"Dmitry Berezovsky <[email protected]>"

dist/locationpicker.jquery.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
/*! jquery-locationpicker - v0.1.12 - 2015-01-05 */
1+
/*! jquery-locationpicker - v0.1.13 - 2016-03-11 */
22
(function($) {
33
function GMapContext(domElement, options) {
44
var _map = new google.maps.Map(domElement, options);
55
var _marker = new google.maps.Marker({
66
position: new google.maps.LatLng(54.19335, -3.92695),
77
map: _map,
88
title: "Drag Me",
9-
draggable: options.draggable
9+
draggable: options.draggable,
10+
icon: options.markerIcon !== undefined ? options.markerIcon : undefined
1011
});
1112
return {
1213
map: _map,
@@ -143,8 +144,10 @@
143144
});
144145
}
145146
if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) {
147+
var blur = false;
146148
gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0));
147149
google.maps.event.addListener(gmapContext.autocomplete, "place_changed", function() {
150+
blur = false;
148151
var place = gmapContext.autocomplete.getPlace();
149152
if (!place.geometry) {
150153
gmapContext.settings.onlocationnotfound(place.name);
@@ -155,6 +158,35 @@
155158
context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]);
156159
});
157160
});
161+
if (gmapContext.settings.enableAutocompleteBlur) {
162+
inputBinding.locationNameInput.on("change", function(e) {
163+
if (!e.originalEvent) {
164+
return;
165+
}
166+
blur = true;
167+
});
168+
inputBinding.locationNameInput.on("blur", function(e) {
169+
if (!e.originalEvent) {
170+
return;
171+
}
172+
setTimeout(function() {
173+
var address = $(inputBinding.locationNameInput).val();
174+
if (address.length > 5 && blur) {
175+
blur = false;
176+
gmapContext.geodecoder.geocode({
177+
address: address
178+
}, function(results, status) {
179+
if (status == google.maps.GeocoderStatus.OK && results && results.length) {
180+
GmUtility.setPosition(gmapContext, results[0].geometry.location, function(context) {
181+
updateInputValues(inputBinding, context);
182+
context.settings.onchanged.apply(gmapContext.domContainer, [ GmUtility.locationFromLatLng(context.location), context.radius, false ]);
183+
});
184+
}
185+
});
186+
}
187+
}, 1e3);
188+
});
189+
}
158190
}
159191
if (inputBinding.latitudeInput) {
160192
inputBinding.latitudeInput.on("change", function(e) {
@@ -184,6 +216,17 @@
184216
gmapContext.map.setCenter(gmapContext.marker.position);
185217
}, 300);
186218
}
219+
function updateMap(gmapContext, $target, options) {
220+
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;
221+
if (latNew == latOld && lngNew == lngOld && radiusNew == radiusOld) return;
222+
gmapContext.settings.location.latitude = latNew;
223+
gmapContext.settings.location.longitude = lngNew;
224+
gmapContext.radius = radiusNew;
225+
GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.settings.location.latitude, gmapContext.settings.location.longitude), function(context) {
226+
setupInputListenersInput(gmapContext.settings.inputBinding, gmapContext);
227+
context.settings.oninitialized($target);
228+
});
229+
}
187230
$.fn.locationpicker = function(options, params) {
188231
if (typeof options == "string") {
189232
var _targetDomElement = this.get(0);
@@ -242,7 +285,10 @@
242285
}
243286
return this.each(function() {
244287
var $target = $(this);
245-
if (isPluginApplied(this)) return;
288+
if (isPluginApplied(this)) {
289+
updateMap(getContextForElement(this), $(this), options);
290+
return;
291+
}
246292
var settings = $.extend({}, $.fn.locationpicker.defaults, options);
247293
var gmapContext = new GMapContext(this, {
248294
zoom: settings.zoom,
@@ -255,7 +301,8 @@
255301
radius: settings.radius,
256302
locationName: settings.locationName,
257303
settings: settings,
258-
draggable: settings.draggable
304+
draggable: settings.draggable,
305+
markerIcon: settings.markerIcon
259306
});
260307
$target.data("locationpicker", gmapContext);
261308
google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
@@ -275,7 +322,7 @@
275322
$.fn.locationpicker.defaults = {
276323
location: {
277324
latitude: 40.7324319,
278-
longitude: -73.82480799999996
325+
longitude: -73.82480777777776
279326
},
280327
locationName: "",
281328
radius: 500,
@@ -288,10 +335,12 @@
288335
locationNameInput: null
289336
},
290337
enableAutocomplete: false,
338+
enableAutocompleteBlur: false,
291339
enableReverseGeocode: true,
292340
draggable: true,
293341
onchanged: function(currentLocation, radius, isMarkerDropped) {},
294342
onlocationnotfound: function(locationName) {},
295-
oninitialized: function(component) {}
343+
oninitialized: function(component) {},
344+
markerIcon: undefined
296345
};
297346
})(jQuery);

dist/locationpicker.jquery.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)