Skip to content
Snippets Groups Projects
Commit 43a9db6d authored by placinta's avatar placinta Committed by podarok
Browse files

Issue #2157629 by Placinta: Gmap + Location Additional Address Field, Option to Ignore when Mapping

parent a8ea2eb3
No related branches found
No related tags found
No related merge requests found
/**
* Documents the JS hooks.
*/
/**
* Allows to alter the address parts of a location address before being geo-coded.
*
* @param object event
* @param object params
* Data to handle:
* - addressParts: An object containing all the address parts
* that are present on the location widget form, which includes:
* name, street, additional, city, province, postal-code, country.
* - separator: The string used to concatenate the address parts.
*/
$(document).on('location_gmap_find_address.address_parts_alter', function(event, params) {
// Remove the name from the address parts object, so it is not
// used in geo-coding process.
if (typeof params.addressParts !== 'undefined' &&
typeof params.addressParts.name !== 'undefined'
) {
delete params.addressParts.name;
}
params.separator = ', ';
});
......@@ -4,19 +4,51 @@
$("button.location-gmap-find-address-button").click(function (e) {
e.preventDefault();
var address_parts = [];
var params = {
addressParts: {},
separator: ', '
};
$("fieldset#" + $(this).val() + " .form-item input[type=text]," +
"fieldset#" + $(this).val() + " .form-item select > option:selected").each(function () {
if (!$(this).hasClass('gmap-control') && $(this).val() !== '') {
if ($(this).is('option')) {
address_parts.push($(this).text());
} else {
address_parts.push($(this).val());
}
"fieldset#" + $(this).val() + " .form-item select > option:selected").each(function () {
if (!$(this).hasClass('gmap-control') && $(this).val() !== '') {
// Get the html id of the element.
var isOption = $(this).is('option');
var id;
if (isOption) {
id = $(this).parent().attr('id');
}
});
else {
id = $(this).attr('id');
}
var id_parts = id.split('-');
// The last part of the input id, contains the type
// of the location field. It can be: name, street,
// additional, city, province, postal-code, country.
var locationFieldType = id_parts[id_parts.length - 1];
// Assign the value of the input to the parts
// object.
if (isOption) {
params.addressParts[locationFieldType] = $(this).text();
} else {
params.addressParts[locationFieldType] = $(this).val();
}
}
});
// Trigger location_gmap_find_address.address_parts_alter.
// Allow altering the address parts by custom code.
var location_field_separator = ', ';
$(document).trigger('location_gmap_find_address.address_parts_alter', [params]);
var address_parts_array = [];
for (var part in params.addressParts) {
if (params.addressParts.hasOwnProperty(part)) {
address_parts_array.push(params.addressParts[part]);
}
}
var address_string = address_parts.join(', ');
var address_string = address_parts_array.join(location_field_separator);
var gmap_id = $("fieldset#" + $(this).val() + " .gmap-map").attr('id');
var geocoder;
if (google.maps.version !== 'undefined') { // assume Google Maps API v3 as API v2 did not have this variable
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment