From dd6b9aed814125d19a70470afd038ed65dcb4e02 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 13 Aug 2018 12:42:30 +0200 Subject: [PATCH] Refactored the layer configuration of the GIS maps to fix some bugs --- .../godmode/gis_maps/configure_gis_map.php | 962 +++++++++--------- pandora_console/include/functions_gis.php | 79 +- pandora_console/include/styles/pandora.css | 17 + 3 files changed, 484 insertions(+), 574 deletions(-) diff --git a/pandora_console/godmode/gis_maps/configure_gis_map.php b/pandora_console/godmode/gis_maps/configure_gis_map.php index f145eba687..dab75690a2 100644 --- a/pandora_console/godmode/gis_maps/configure_gis_map.php +++ b/pandora_console/godmode/gis_maps/configure_gis_map.php @@ -38,6 +38,25 @@ $sec2 = safe_url_extraclean ($sec2); $sec = get_parameter_get ('sec'); $sec = safe_url_extraclean ($sec); +// Layers +$layer_ids = get_parameter("layer_ids", array()); +$layers = get_parameter("layers", array()); +$layer_list = array(); + +foreach ($layer_ids as $layer_id) { + if (empty($layers[$layer_id]) || empty($layers[$layer_id]["name"])) continue; + $trimmed_name = trim($layers[$layer_id]["name"]); + if (empty($trimmed_name)) continue; + + $layer_list[] = array( + "id" => (strpos($layer_id, "new_") === false) ? (int) $layer_id : null, + "layer_name" => $trimmed_name, + "layer_visible" => ((int) $layers[$layer_id]["visible"] === 1), + "layer_group" => (int) $layers[$layer_id]["agents_from_group"], + "layer_agent_list" => $layers[$layer_id]["agents"] + ); +} + $next_action = 'new_map'; switch ($action) { @@ -63,14 +82,7 @@ switch ($action) { unset($map_connection_list_temp[$index]); } } - $layer_list = explode(",",get_parameter('layer_list')); - foreach ($layer_list as $index => $value) { - $cleanValue = trim($value); - if ($cleanValue == '') { - unset($layer_list[$index]); - } - } - + $map_connection_default = get_parameter('map_connection_default'); $map_connection_list = array(); @@ -82,13 +94,6 @@ switch ($action) { $map_connection_list[] = array('id_conection' => $idMapConnection, 'default' => $default); } - $arrayLayers = array(); - foreach ($layer_list as $layerID) { - $layer = get_parameter('layer_values_' . $layerID); - $layer = json_decode(io_safe_output ($layer), true); - array_unshift ($arrayLayers, $layer); - } - $invalidFields = gis_validate_map_data($map_name, $map_zoom_level, $map_initial_longitude, $map_initial_latitude, $map_initial_altitude, $map_default_longitude, $map_default_latitude, $map_default_altitude, @@ -98,7 +103,7 @@ switch ($action) { $idMap = gis_save_map($map_name, $map_initial_longitude, $map_initial_latitude, $map_initial_altitude, $map_zoom_level, $map_background, $map_default_longitude, $map_default_latitude, $map_default_altitude, - $map_group_id, $map_connection_list, $arrayLayers); + $map_group_id, $map_connection_list, $layer_list); $mapCreatedOk = true; $next_action = 'update_saved'; } @@ -106,7 +111,6 @@ switch ($action) { $next_action = 'save_new'; $mapCreatedOk = false; } - $layer_list = $arrayLayers; ui_print_result_message ($mapCreatedOk, __('Map successfully created'), __('Map could not be created')); @@ -124,8 +128,8 @@ switch ($action) { $map_default_latitude = ''; $map_default_altitude = ''; $map_group_id = ''; - $map_connection_list = Array(); - $layer_list = Array(); + $map_connection_list = array(); + $layer_list = array(); $map_levels_zoom = 0; break; case 'edit_map': @@ -152,13 +156,6 @@ switch ($action) { unset($map_connection_list_temp[$index]); } } - $layer_list = explode(",", get_parameter('layer_list')); - foreach ($layer_list as $index => $value) { - $cleanValue = trim($value); - if ($cleanValue == '') { - unset($layer_list[$index]); - } - } $map_connection_default = get_parameter('map_connection_default'); @@ -171,26 +168,17 @@ switch ($action) { $map_connection_list[] = array('id_conection' => $idMapConnection, 'default' => $default); } - $arrayLayers = array(); - foreach ($layer_list as $layerID) { - $layer = get_parameter('layer_values_' . $layerID); - $layer = json_decode(io_safe_output ($layer), true); - array_unshift ($arrayLayers, $layer); - } - - - $invalidFields = gis_validate_map_data($map_name, $map_zoom_level, $map_initial_longitude, $map_initial_latitude, $map_initial_altitude, $map_default_longitude, $map_default_latitude, $map_default_altitude, $map_connection_list, $map_levels_zoom); - + if (empty($invalidFields) && get_parameter('map_connection_list') != "") { //TODO gis_update_map($idMap, $map_name, $map_initial_longitude, $map_initial_latitude, $map_initial_altitude, $map_zoom_level, $map_background, $map_default_longitude, $map_default_latitude, $map_default_altitude, - $map_group_id, $map_connection_list, $arrayLayers); + $map_group_id, $map_connection_list, $layer_list); $mapCreatedOk = true; } else { @@ -222,16 +210,11 @@ if ($idMap) { ui_print_page_header (__('GIS Maps builder'), "images/gm_gis.png", false, "configure_gis_map", true, $buttons); - -ui_require_javascript_file('openlayers.pandora'); -//Global vars for javascript and scripts. ?> + + '; - - +echo '
'; //Load the data in edit or reload in update. switch ($action) { @@ -301,22 +339,7 @@ switch ($action) { $map_connection_list = $mapData['connections']; $map_levels_zoom = gis_get_num_zoom_levels_connection_default($map_connection_list); - //$map_levels_zoom = get_parameter('map_levels_zoom'); - - $layer_list = array(); - foreach ($mapData['layers'] as $layer) { - $layerAgentList = array(); - foreach($layer['layer_agent_list'] as $layerAgent) { - $layerAgentList[] = $layerAgent['nombre']; - } - $layer_list[] = array( - 'id' => $layer['id_tmap_layer'], - 'layer_name' => $layer['layer_name'], - 'layer_group' => $layer['layer_group'], - 'layer_visible' => $layer['layer_visible'], - 'layer_agent_list' => $layerAgentList - ); - } + $layer_list = !empty($mapData['layers']) ? $mapData['layers'] : array(); break; } @@ -393,16 +416,17 @@ echo "

" . __('Layers') . ui_print_help_tip (__('Each layer can show agents f $table->width = '100%'; $table->class = 'databox filters'; +$table->valign = array(); +$table->valign[0] = 'top'; +$table->valign[1] = 'top'; $table->data = array (); $table->data[0][0] = "

" .__('List of layers') . ui_print_help_tip (__('It is possible to edit, delete and reorder the layers.'), true) . "

"; $table->data[0][1] = '
' . html_print_button(__('New layer'), 'new_layer', false, 'newLayer();', 'class="sub add"', true) . '
'; -$table->data[1][0] = '' . - gis_add_layer_list($layer_list) . - '
'; -$table->data[1][1] = '
- +$table->data[1][0] = '
'; +$table->data[1][1] = '