Reworked Geolocalization extra field map for show users location - Refs BT#11371

remotes/angel/1.11.x
José Loguercio 8 years ago
parent 866068dc9a
commit e5e5c25cb4
  1. 8
      plugin/google_maps/lang/english.php
  2. 8
      plugin/google_maps/lang/french.php
  3. 8
      plugin/google_maps/lang/spanish.php
  4. 19
      plugin/google_maps/src/map_coordinates.php
  5. 138
      plugin/google_maps/view/map_coordinates.tpl

@ -2,8 +2,12 @@
$strings['plugin_title'] = "Google Maps";
$strings['plugin_comment'] = "Enable the functionality to show google maps";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones, siga el siguiente link para ver el mapa : <a href='". api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php'>" . api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php</a>";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo o los campos extra de usuario separados por una coma (,) del cual quiere obtener las localizaciones, puede obtener hasta 5 campos de geolocalización (el resto serán ignorados) los cuales se marcarán con los siguientes iconos respectivamente:
<br><br>
<img src='//maps.google.com/mapfiles/ms/icons/red-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/green-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/blue-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/yellow-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/purple-dot.png'>
<br><br>
siga el siguiente link para ver el mapa : <a href='". api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php'>" . api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php</a>";
$strings['enable_api'] = "Enable API";
$strings['api_key'] = "Api Key";
$strings['extra_field_name'] = "Extra field name";
$strings['UsersCoordinatesMap'] = "Users Coordinates Map";
$strings['UsersCoordinatesMap'] = "Users location Map";

@ -2,8 +2,12 @@
$strings['plugin_title'] = "Google Maps";
$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones, siga el siguiente link para ver el mapa : <a href='". api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php'>" . api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php</a>";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo o los campos extra de usuario separados por una coma (,) del cual quiere obtener las localizaciones, puede obtener hasta 5 campos de geolocalización (el resto serán ignorados) los cuales se marcarán con los siguientes iconos respectivamente:
<br><br>
<img src='//maps.google.com/mapfiles/ms/icons/red-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/green-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/blue-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/yellow-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/purple-dot.png'>
<br><br>
siga el siguiente link para ver el mapa : <a href='". api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php'>" . api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php</a>";
$strings['enable_api'] = "Enable API";
$strings['api_key'] = "Api Key";
$strings['extra_field_name'] = "Nom de champ supplémentaire";
$strings['UsersCoordinatesMap'] = "Carte des coordonnées des utilisateurs";
$strings['UsersCoordinatesMap'] = "Carte des emplacement des utilisateurs";

@ -2,8 +2,12 @@
$strings['plugin_title'] = "Google Maps";
$strings['plugin_comment'] = "Enable the functionality to show google maps";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones, siga el siguiente link para ver el mapa : <a href='". api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php'>" . api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php</a>";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo o los campos extra de usuario separados por una coma (,) del cual quiere obtener las localizaciones, puede obtener hasta 5 campos de geolocalización (el resto serán ignorados) los cuales se marcarán con los siguientes iconos respectivamente:
<br><br>
<img src='//maps.google.com/mapfiles/ms/icons/red-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/green-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/blue-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/yellow-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/purple-dot.png'>
<br><br>
siga el siguiente link para ver el mapa : <a href='". api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php'>" . api_get_path(WEB_PLUGIN_PATH) . "google_maps/src/map_coordinates.php</a>";
$strings['enable_api'] = "Activar API";
$strings['api_key'] = "Api Key";
$strings['extra_field_name'] = "Nombre del campo extra";
$strings['UsersCoordinatesMap'] = "Mapa de Coordenadas de Usuarios";
$strings['UsersCoordinatesMap'] = "Mapa de localización de Usuarios";

@ -37,15 +37,28 @@ foreach ($extraFieldName as $field) {
$extraFieldValues = [];
foreach ($extraFieldNames as $fieldName) {
$extraFieldRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldValues');
$extraFieldValues[] = $extraFieldRepo->findBy(['field' => $fieldName->getId()]);
foreach ($extraFieldNames as $index => $fieldName) {
if ($fieldName) {
$extraFieldRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldValues');
$extraFieldValues[] = $extraFieldRepo->findBy(['field' => $fieldName->getId()]);
}
}
$templateName = $plugin->get_lang('UsersCoordinatesMap');
$tpl = new Template($templateName);
$formattedExtraFieldValues = [];
foreach ($extraFieldValues as $index => $extra) {
foreach ($extra as $yandex => $field) {
$thisUserExtraField = api_get_user_info($field->getItemId());
$formattedExtraFieldValues[$index][$yandex]['address'] = $field->getValue();
$formattedExtraFieldValues[$index][$yandex]['user_complete_name'] = $thisUserExtraField['complete_name'];
}
}
$tpl->assign('extra_field_values_formatted', $formattedExtraFieldValues);
$tpl->assign('extra_field_values', $extraFieldValues);
$content = $tpl->fetch('google_maps/view/map_coordinates.tpl');

@ -6,64 +6,8 @@
initMap();
});
function addMaker(lat, lng, map, bounds, userInfo, index) {
if (index > 5) {
return;
}
var location = new google.maps.LatLng(lat, lng);
var infoWindow = new google.maps.InfoWindow();
var geocoder = geocoder = new google.maps.Geocoder();
var marker = new google.maps.Marker({
map: map,
position: location,
label: userInfo.complete_name
});
switch (index) {
case '1':
marker.setIcon('//maps.google.com/mapfiles/ms/icons/red-dot.png');
break;
case '2':
marker.setIcon('//maps.google.com/mapfiles/ms/icons/green-dot.png');
break;
case '3':
marker.setIcon('//maps.google.com/mapfiles/ms/icons/blue-dot.png');
break;
case '4':
marker.setIcon('//maps.google.com/mapfiles/ms/icons/yellow-dot.png');
break;
case '5':
marker.setIcon('//maps.google.com/mapfiles/ms/icons/purple-dot.png');
break;
}
var address = "";
geocoder.geocode({ 'latLng': location }, function (results) {
if (results) {
address = results[1].formatted_address;
} else {
address = '{{ 'Unknown' | get_lang }}';
}
var infoWinContent = "<b>" + userInfo.complete_name + "</b> - " + address;
marker.addListener('click', function() {
infoWindow.setContent(infoWinContent);
infoWindow.open(map, marker);
});
});
bounds.extend(marker.position);
map.fitBounds(bounds);
}
function initMap() {
var center = new google.maps.LatLng(-3.480523, 7.866211);
var bounds = new google.maps.LatLngBounds();
@ -79,25 +23,83 @@
mapTypeId: google.maps.MapTypeId.ROADMAP
});
{% for extra in extra_field_values %}
var extraFields = {{ extra_field_values_formatted|json_encode }};
var index = '{{ loop.index }}';
for (var i = 0; i < extraFields.length; i++) {
{% for field in extra %}
var index = i + 1;
var latLng = '{{ field.value }}';
latLng = latLng.split(',');
for (var y = 0; y < extraFields[i].length; y++) {
var lat = latLng[0];
var lng = latLng[1];
var address = extraFields[i][y]['address'];
var userCompleteName = extraFields[i][y]['user_complete_name'];
{% set userInfo = field.itemId | user_info %}
addMaker(address, map, bounds, userCompleteName, index);
}
}
}
addMaker(lat, lng, map, bounds, {{ userInfo|json_encode }}, index);
function addMaker(address, map, bounds, userCompleteName, index) {
{% endfor %}
if (index > 5) {
return;
}
var infoWindow = new google.maps.InfoWindow();
{% endfor %}
var geocoder = geocoder = new google.maps.Geocoder();
var formattedAddress = '';
geocoder.geocode({ 'address': address }, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results) {
formattedAddress = results[0].formatted_address;
} else {
formattedAddress = '{{ 'Unknown' | get_lang }}';
}
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
label: userCompleteName
});
switch (index) {
case 1:
marker.setIcon('//maps.google.com/mapfiles/ms/icons/red-dot.png');
break;
case 2:
marker.setIcon('//maps.google.com/mapfiles/ms/icons/green-dot.png');
break;
case 3:
marker.setIcon('//maps.google.com/mapfiles/ms/icons/blue-dot.png');
break;
case 4:
marker.setIcon('//maps.google.com/mapfiles/ms/icons/yellow-dot.png');
break;
case 5:
marker.setIcon('//maps.google.com/mapfiles/ms/icons/purple-dot.png');
break;
}
var infoWinContent = "<b>" + userCompleteName + "</b> - " + formattedAddress;
marker.addListener('click', function() {
infoWindow.setContent(infoWinContent);
infoWindow.open(map, marker);
});
bounds.extend(marker.position);
map.fitBounds(bounds);
} else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
setTimeout(function() {
geoCode(address, map, bounds, userCompleteName, index);
}, 350);
}
});
}
</script>
Loading…
Cancel
Save