Skip to content

Commit 3ef159b

Browse files
author
Dmitry Berezovsky
committed
Added new method which allows to get Google Maps widget context. Put dom element to the onchange callback context
1 parent f793c50 commit 3ef159b

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

locationpicker.jquery.js

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,18 @@
112112
if (inputBinding.locationNameInput) {
113113
inputBinding.locationNameInput.val(gmapContext.locationName);
114114
}
115-
}
116-
115+
}
116+
117117
function setupInputListenersInput(inputBinding, gmapContext) {
118118
if (inputBinding) {
119119
if (inputBinding.radiusInput){
120-
inputBinding.radiusInput.on("change", function() {
121-
gmapContext.radius = $(this).val();
122-
GmUtility.setPosition(gmapContext, gmapContext.location, function(context){
123-
context.settings.onchanged(GmUtility.locationFromLatLng(context.location), context.radius, false);
124-
});
125-
});
120+
inputBinding.radiusInput.on("change", function() {
121+
gmapContext.radius = $(this).val();
122+
GmUtility.setPosition(gmapContext, gmapContext.location, function(context){
123+
context.settings.onchanged.apply(gmapContext.domContainer,
124+
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
125+
});
126+
});
126127
}
127128
if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) {
128129
gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0));
@@ -132,25 +133,28 @@
132133
gmapContext.settings.onlocationnotfound(place.name);
133134
return;
134135
}
135-
GmUtility.setPosition(gmapContext, place.geometry.location, function(context) {
136+
GmUtility.setPosition(gmapContext, place.geometry.location, function(context) {
136137
updateInputValues(inputBinding, context);
137-
context.settings.onchanged(GmUtility.locationFromLatLng(context.location), context.radius, false);
138+
context.settings.onchanged.apply(gmapContext.domContainer,
139+
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
138140
});
139141
});
140142
}
141143
if (inputBinding.latitudeInput) {
142-
inputBinding.latitudeInput.on("change", function() {
143-
GmUtility.setPosition(gmapContext, new google.maps.LatLng($(this).val(), gmapContext.location.lng()), function(context){
144-
context.settings.onchanged(GmUtility.locationFromLatLng(context.location), context.radius, false);
145-
});
146-
});
144+
inputBinding.latitudeInput.on("change", function() {
145+
GmUtility.setPosition(gmapContext, new google.maps.LatLng($(this).val(), gmapContext.location.lng()), function(context){
146+
context.settings.onchanged.apply(gmapContext.domContainer,
147+
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
148+
});
149+
});
147150
}
148151
if (inputBinding.longitudeInput) {
149-
inputBinding.longitudeInput.on("change", function() {
150-
GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.location.lat(), $(this).val()), function(context){
151-
context.settings.onchanged(GmUtility.locationFromLatLng(context.location), context.radius, false);
152-
});
153-
});
152+
inputBinding.longitudeInput.on("change", function() {
153+
GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.location.lat(), $(this).val()), function(context){
154+
context.settings.onchanged.apply(gmapContext.domContainer,
155+
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
156+
});
157+
});
154158
}
155159
}
156160
}
@@ -192,7 +196,7 @@
192196
* - event: string, name of the event
193197
* - callback: function, callback function to be invoked
194198
*/
195-
if (options == undefined) { // Getter is not available
199+
if (params == undefined) { // Getter is not available
196200
return null;
197201
} else {
198202
var event = params.event;
@@ -203,8 +207,23 @@
203207
}
204208
google.maps.event.addListener(gmapContext.map, event, callback);
205209
}
206-
207210
break;
211+
case "map":
212+
/**
213+
* Returns object which allows access actual google widget and marker paced on it.
214+
* Structure: {
215+
* map: Instance of the google map widget
216+
* marker: marker placed on map
217+
* }
218+
*/
219+
if (params == undefined) { // Getter is not available
220+
return {
221+
map: gmapContext.map,
222+
marker: gmapContext.marker
223+
}
224+
} else {
225+
return null;
226+
}
208227
}
209228
return null;
210229
}
@@ -233,7 +252,7 @@
233252
google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
234253
GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context){
235254
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
236-
context.settings.onchanged(currentLocation, context.radius, true);
255+
context.settings.onchanged.apply(gmapContext.domContainer, [currentLocation, context.radius, true]);
237256
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
238257
});
239258
});
@@ -265,4 +284,4 @@
265284

266285
}
267286

268-
}( jQuery ));
287+
}( jQuery ));

locationpicker.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"map",
1010
"radius"
1111
],
12-
"version": "0.1.8",
12+
"version": "0.1.9",
1313
"author": {
1414
"name": "Dmitry Berezovsky",
1515
"url": "http://logicify.com/"

0 commit comments

Comments
 (0)